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

method self type appears to be unknown (Flag, Python 3.11) #15109

Open
belm0 opened this issue Apr 24, 2023 · 0 comments
Open

method self type appears to be unknown (Flag, Python 3.11) #15109

belm0 opened this issue Apr 24, 2023 · 0 comments
Labels
bug mypy got something wrong topic-enum topic-self-types Types for self

Comments

@belm0
Copy link

belm0 commented Apr 24, 2023

In a method of a class derived from Flag, the type of self appears to be unknown.

To Reproduce

import enum

class Foo(enum.Flag):
    A = 1
    B = 2

    def names(self):
        return [v.name for v in list(self.__class__) if self & v]

Expected Behavior

no errors

Actual Behavior

$ mypy --check-untyped-defs flag.py
flag.py:8: error: "object" has no attribute "name"  [attr-defined]
flag.py:8: error: Unsupported operand types for & ("Foo" and "object")  [operator]

Though I can resolve the error by annotating self with typing_extensions.Self, I'm not sure that should be necessary.

Your Environment

  • Mypy version used: 1.2.0
  • Python version used: 3.11.0
@belm0 belm0 added the bug mypy got something wrong label Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-enum topic-self-types Types for self
Projects
None yet
Development

No branches or pull requests

2 participants