You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enum field 'name' conflics with instance attribute 'name' #4654
Hm, is the stub file a *.pyi file? If not it may be picking up the file as a regular Python module. Otherwise it shouldn't be complaining about Ellipsis.
I think this does deserve some discussion, and I think considering the trickery of Enum, we might need to modify the stubs and mypy to handle Enum attributes differently from Enum inheriting types themselves. Let me think about this some more.
Shouldn't the enum attributes be considered implicitly ClassVar[MyEnum]? The base class defines an instance variable, whereas the class defines a class/static variable. It indeed will be special casing.
Activity
emmatyping commentedon Feb 28, 2018
Hm, is the stub file a
*.pyifile? If not it may be picking up the file as a regular Python module. Otherwise it shouldn't be complaining aboutEllipsis.fried commentedon Feb 28, 2018
This is a stub, the problem is the stub for Enum says 'name: str' so we are conflicting with that
emmatyping commentedon Feb 28, 2018
Ah, the source of the issue is https://github.com/python/typeshed/blob/master/stdlib/3.4/enum.pyi#L30 this is a typeshed bug.It is, in fact not a bug in typeshed.
fried commentedon Feb 28, 2018
I guess i'm not sure what the fix is, Enum instances do have a .name and .value.
emmatyping commentedon Feb 28, 2018
I think this does deserve some discussion, and I think considering the trickery of Enum, we might need to modify the stubs and mypy to handle Enum attributes differently from Enum inheriting types themselves. Let me think about this some more.
gvanrossum commentedon Mar 1, 2018
Yeah, this is tricky. We may have to special-case this in mypy. However maybe @elazarg has an idea, he seems to understand the Enum stuff best.
elazarg commentedon Mar 1, 2018
Shouldn't the enum attributes be considered implicitly
ClassVar[MyEnum]? The base class defines an instance variable, whereas the class defines a class/static variable. It indeed will be special casing.ambv commentedon Mar 1, 2018
We looked at this and there's another related issue here. mypy's special handling of Enum already treats
namespecially. Consider:Mypy correctly finds that
fouris a missing attribute but thinksnamedoes exist. Better yet, if you ask it to reveal its type...This is not a typeshed problem since the revealed type goes against what typeshed defines for
name. It's of course fine for valid members:gvanrossum commentedon Mar 2, 2018
I suspect this code is a little lax: https://github.com/python/mypy/blob/master/mypy/checkmember.py#L440