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

Pyflyby should understand structural pattern matching (PyInf#11543) #276

Open
dshivashankar1994 opened this issue Dec 2, 2023 · 0 comments

Comments

@dshivashankar1994
Copy link
Collaborator

Currently pyflyby does not understand structural pattern matching. In the following example, pyflyby erroneously suggests an unneeded import:

from typing_extensions import assert_never

my_var: int | str = 5

match my_var:
    case str():
        print("we have a str")
    case int():
        print("we have an int")
    case json:  # try to assert that my_var is never a json object
        assert_never(json)
~ tidy-imports pattern_match.py
[PYFLYBY] /u/zeng/repos/scratch/pattern_match.py: added 'import json'
--- /u/zeng/repos/scratch/pattern_match.py      2023-11-29 12:32:59.404921000 +0000
+++ /tmp/tmps3uv669v    2023-11-29 12:33:06.071715619 +0000
@@ -1,4 +1,5 @@
-from typing_extensions import assert_never
+import json
+from   typing_extensions        import assert_never
 
 my_var: int | str = 5
 

Replace /u/zeng/repos/scratch/pattern_match.py? [y/N] 

case json: is a catch-all that will match any value and assign the name json to it, though that does not detract from this being a pyflyby bug.

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

1 participant