Skip to content
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

Enum member annotations mask subclass in type annotation resolution #47

Open
PikalaxALT opened this issue Jan 13, 2021 · 5 comments
Open
Assignees

Comments

@PikalaxALT
Copy link

The way enum stubs are defined causes their values to appear to PyCharm as their annotated type rather than as instances of their class. This causes PyCharm to warn that, for example, the per= argument to commands.MaxConcurrency.__init__ is an int rather than the expected BucketType.

image

@bryanforbes bryanforbes self-assigned this Jan 13, 2021
@bryanforbes
Copy link
Owner

This seems like a PyCharm issue as the stubs are using the standard enum.Enum class as the base class for all of the enums in discord. I'd be interested to see what PyCharm does with the following code:

from enum import Enum

class MyEnum(Enum):
    One = 1
    Two = 2

def my_function(arg: MyEnum) -> None:
    pass

my_function(MyEnum.One)

@Gobot1234
Copy link

AFAIK PyCharm takes the annotated value to be the correct one ignoring the fact it's in an Enum, that code therefore runs fine.

@bryanforbes
Copy link
Owner

AFAIK PyCharm takes the annotated value to be the correct one ignoring the fact it's in an Enum, that code therefore runs fine.

Then I'm not sure why PyCharm would have an issue with BucketType since it's done exactly the same way.

@Gobot1234
Copy link

I've tried doing this in stubs before, the only way to get it to work is to type hint members as instances of the enum.

@bryanforbes
Copy link
Owner

My whole point is that this works fine in mypy and, (as far as I can tell) according to PEP-484, should work in all type checkers, so this would appear to be a bug in PyCharm. If you can show me other type checkers that also flag this as an error, I'd be more prone to work around this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants