8000 Use EnumMeta instead of Enum to mark enum classes by elazarg · Pull Request #4319 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Use EnumMeta instead of Enum to mark enum classes #4319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 10, 2018
Prev Previous commit
Next Next commit
use dummy constructor and explain why
  • Loading branch information
elazarg committed Apr 8, 2018
commit a1d61e7cd7d63fde298fd8d82cc4ef84318d5bed
5 changes: 5 additions & 0 deletions test-data/unit/check-enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Medal(metaclass=EnumMeta):
gold = 1
silver = "hello"
bronze = None
# Without __init__ the definition fails at runtime, but we want to verify that mypy
# uses `enum.EnumMeta` and not `enum.Enum` as the definition of what is enum.
def __init__(self, *args): pass
reveal_type(Medal.bronze) # E: Revealed type is '__main__.Medal'
m = Medal.gold
m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Medal")
Expand All @@ -27,6 +30,8 @@ class Medal(Achievement):
gold = 1
silver = "hello"
bronze = None
# See comment in testEnumFromEnumMetaBasics
def __init__(self, *args): pass
reveal_type(Medal.bronze) # E: Revealed type is '__main__.Medal'
m = Medal.gold
m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Medal")
Expand Down
0