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

Expected type in class pattern; found "Any" for ignored missing import in match/case #14477

Closed
ds-cbo opened this issue Jan 20, 2023 · 1 comment · Fixed by #14479
Closed
Labels
bug mypy got something wrong topic-match-statement Python 3.10's match statement

Comments

@ds-cbo
Copy link
Contributor

ds-cbo commented Jan 20, 2023

To Reproduce

from somewhere import Foo

match None:
    case Foo():
        ...

https://mypy-play.net/?mypy=latest&python=3.11&flags=ignore-missing-imports&gist=03694364e4e855575f23ba9c625e804e

Expected Behavior

no error

Actual Behavior

$ mypy --ignore-missing-imports test.py
test.py:4: error: Expected type in class pattern; found "Any"  [misc]
Found 1 error in 1 file (checked 1 source file)

Your Environment

mypy 0.991 without config files on python 3.10 and 3.11

@ds-cbo ds-cbo added the bug mypy got something wrong label Jan 20, 2023
@AlexWaygood AlexWaygood added the topic-match-statement Python 3.10's match statement label Jan 20, 2023
@tinkerware
Copy link

This can be an occasional stumbling block that's quite difficult to find a way out of without the right error message. In my case, I ran into two internal libraries, A and B, where A had imports from B. A also had the ignore_missing_imports = true setting to deal with some legacy 3rd-party libraries.

Code that looks like following fails in this set-up with the error in this issue:

from B import Foo, Bar

def do_stuff(value: Foo | Bar) → None:
  match value:
    case Foo(a=a):
      ...
    case Bar(b=b):
      ...

No error is given if library B adds the py.typed marker. At the very least, a more descriptive error with a fix suggestion seems useful. Using ignore_missing_imports = false does give the user a hint with the skipping analyzing ... error.

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-match-statement Python 3.10's match statement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants