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

mypy always fails with Python 3.10 match statement #11829

Closed
wrobell opened this issue Dec 23, 2021 · 23 comments
Closed

mypy always fails with Python 3.10 match statement #11829

wrobell opened this issue Dec 23, 2021 · 23 comments
Labels
bug mypy got something wrong

Comments

@wrobell
Copy link

wrobell commented Dec 23, 2021

Please consider:

a = 1
match a:  # type: ignore
    case 0:
        print('is zero')
    case 1:
        print('is one')

then

$ mypy t5.py
t5.py:2: error: Match statement is not supported
Found 1 error in 1 file (errors prevented further checking)

I would expect Mypy to ignore the whole match block.

Or is there an option I am missing, which I can pass to Mypy?

Mypy 0.930, Python 3.10.1.

@wrobell wrobell added the bug mypy got something wrong label Dec 23, 2021
@srittau
Copy link
Contributor

srittau commented Dec 23, 2021

The match statement is not yet supported in mypy. See #10191.

@wrobell
Copy link
Author

wrobell commented Dec 23, 2021

@srittau That's OK. I am just asking Mypy to ignore match block, but it still raises the error.

It seems it could be trivial to make it to respect "type: ignore"?

mypy/mypy/fastparse.py

Lines 1289 to 1293 in 9e34f6a

def visit_Match(self, n: Any) -> Node:
self.fail("Match statement is not supported",
line=n.lineno, column=n.col_offset, blocker=True)
# Just return some valid node
return PassStmt()

Artturin added a commit to nix-community/nixos-gen-config that referenced this issue Jan 2, 2022
its not supported in mypy yet :/ and ignore doesn't work yet
python/mypy#11829
This reverts commit d86a269.
@srittau
Copy link
Contributor

srittau commented Jan 3, 2022

That indeed seems like a regression. At least in mypy 0.910, the match statement could be ignored.

@jarek-webellian
Copy link

@srittau downgraded to mypy 0.910, the error is still the same

$ mypy -V && mypy t5.py
mypy 0.910
t5.py:2: error: Match statement is not supported  [syntax]
Found 1 error in 1 file (errors prevented further checking)

@MPalarya
Copy link

MPalarya commented Jan 9, 2022

@srittau is there a way to properly ignore the match section as a temporary solution?
OP's attempt does not seem to work on either 0.910 and 0.931 versions

@srittau
Copy link
Contributor

srittau commented Jan 9, 2022

I'm not sure. I thought it had worked for me with 0.910, but when I downgraded, it failed too.

@intgr
Copy link
Contributor

intgr commented Jan 18, 2022

Looks like proper match support is pretty close to merging (#10191), so I guess it makes sense to just wait it out?

@JelleZijlstra
Copy link
Member

It has been merged

@lenoqt
Copy link

lenoqt commented Jan 19, 2022

When this is going to be available on pypi? I am still having issues with my build using the latest version.

@JelleZijlstra
Copy link
Member

There are no concrete plans for the next release yet.

lenoqt added a commit to lenoqt/Trading that referenced this issue Jan 19, 2022
lenoqt added a commit to lenoqt/Trading that referenced this issue Jan 19, 2022
lenoqt added a commit to lenoqt/Trading that referenced this issue Jan 19, 2022
@JukkaL
Copy link
Collaborator

JukkaL commented Jan 19, 2022

I'm hoping that we will have a feature release sometime in February.

@JukkaL
Copy link
Collaborator

JukkaL commented Jan 19, 2022

This issue can be used to track progress on the next feature release which will support the match statement:

@schlopp96
Copy link

schlopp96 commented Jan 20, 2022

When this is going to be available on pypi? I am still having issues with my build using the latest version.

As have I unfortunately...

I've tried adding # type: ignore to various parts of code blocks just in case perhaps there was some sort of bug causing said phrase to function incorrectly or in different positions, but no dice.

Are there any sort of temporary fixes in the meantime, or do I just need to ignore the red squiggles in my IDE for now, lol?

@lenoqt
Copy link

lenoqt commented Jan 21, 2022

When this is going to be available on pypi? I am still having issues with my build using the latest version.

As have I unfortunately...

I've tried adding # type: ignore to various parts of code blocks just in case perhaps there was some sort of bug causing said phrase to function incorrectly or in different positions, but no dice.

Are there any sort of temporary fixes in the meantime, or do I just need to ignore the red squiggles in my IDE for now, lol?

I had to disable mypy until this gets released.

@gdalmau
Copy link

gdalmau commented Jan 21, 2022

As have I unfortunately...

I've tried adding # type: ignore to various parts of code blocks just in case perhaps there was some sort of bug causing said phrase to function incorrectly or in different positions, but no dice.

Are there any sort of temporary fixes in the meantime, or do I just need to ignore the red squiggles in my IDE for now, lol?

While there is no release you can install mypy on the commit that includes this initial support for match statements:

pip install git+git://github.com/python/mypy.git@9b3147701f054bf8ef42bd96e33153b05976a5e1

The commit above is the first commit after 9b63751 where the CI succeeds.

@jeremytwfortune
Copy link

I can absolutely appreciate that mypy needs time to support newer features. I'm confused on the choice here, though, to return an error. What is the reasoning behind classifying the result this way?

@intgr
Copy link
Contributor

intgr commented Feb 2, 2022

I'm relying on mypy to type-check my code. If I'm using language features that mypy does not support, I think it's good to receive a warning in places where I cannot rely on it.

The fact that you couldn't suppress the warning was bad, but probably an honest mistake.

@jeremytwfortune
Copy link

Certainly agree with the warning. It would be awkward to just have mypy be silent when it can't process some syntax at all. If the fact that it raises an error was in error, that's certainly my misunderstanding of the issue here. Thanks! 👍

@SerGeRybakov
Copy link

As have I unfortunately...
I've tried adding # type: ignore to various parts of code blocks just in case perhaps there was some sort of bug causing said phrase to function incorrectly or in different positions, but no dice.
Are there any sort of temporary fixes in the meantime, or do I just need to ignore the red squiggles in my IDE for now, lol?

While there is no release you can install mypy on the commit that includes this initial support for match statements:

pip install git+git://github.com/python/mypy.git@9b3147701f054bf8ef42bd96e33153b05976a5e1

The commit above is the first commit after 9b63751 where the CI succeeds.

It's good to have an option to install from git branch to local. But it doesn't solve pre-commit hooks problems.
Waiting for a soonest release!

@aomayden
Copy link

Any updates on this? I'm using mypy 1.3.0 and this is still throwing the error
error: Pattern matching is only supported in Python 3.10 and greater [syntax]

@hauntsaninja
Copy link
Collaborator

That probably means you're not running mypy with Python 3.10 or newer (or you're not actually running mypy 1.3). Try python3.10 -m mypy

@aomayden
Copy link

Yes, you're right. I hadn't updated my .mypy.ini from a previous project to state python_version=3.10. Thank you!

@larroy
Copy link

larroy commented Nov 4, 2023

I still have this in mypy 1.6.1 for mac.
error: Pattern matching is only supported in Python 3.10 and greater

Python 3.10.13
mypy 1.6.1

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

No branches or pull requests