hadialqattan / pycln

A formatter for finding and removing unused import statements.

Home Page:https://hadialqattan.github.io/pycln

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Match statement syntax not supported

sondrelg opened this issue · comments

Hi,

Thanks for creating this project. It's been super helpful 👏

Ran into an issue with match statement syntax on the last version (1.2.5), running the project as a pre-commit hook. Looks like match statement support was added a while ago, so not sure if I'm just tired or there's an actual bug in the hook 🙃

Reproducible example

Python code

# match.py
match 1:
    case 1:
        print('nice')
    case _:
        print('what')

Pre-commit config

# pre-commit-config.yaml
repos:
  - repo: https://github.com/hadialqattan/pycln
    rev: v1.2.5
    hooks:
      - id: pycln

Output

  match.py:1:7 SyntaxError: invalid syntax 'match 1:' ⛔

Hi @sondrelg, I checked that out myself, and I found that there was no problem in Pycln regarding the MatchAs statement support, so I tried to get the same error that you've encountered by running Pycln using a Python version < 3.10 (I tried 3.8), luckily, I've encountered the same error, therefore, I believe your problem was that you were running Pycln using a Python version < 3.10.

BTW, Pycln uses Python's ast module to parse the code, so if you use for example Python3.8, which does not support the MatchAs syntax, with a 3.10 syntax, Pycln wouldn't be able to deal with it.

Thanks for being around!

Have a good day!

Actually, I came to the idea of showing Python version when using --version flag, so instead of outputting only Pycln version:

$ pycln --version
pycln, version 1.2.5

we can also show Python version, for example:

$ pycln --version
pycln v1.2.5, python v3.8

Do you have any thoughts about this idea?

+ please let me know if I'm right/wrong so I can fix/close this issue. (initially, I'll mark it as invalid).

Thanks for the quick response. You're probably right, while my venv is 3.10.2, I'm guessing my pre-commit venv(s) are not. I'll reset and try again when I get a chance in a few hours. Closing in the meantime and will update when I can 👍

Yep after running pre-commit clean and recreating the pre-commit environment things work well 👍 Thanks again!