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

Should TCH run on pyi files? #3357

Closed
MarcoGorelli opened this issue Mar 6, 2023 · 8 comments · Fixed by #3362
Closed

Should TCH run on pyi files? #3357

MarcoGorelli opened this issue Mar 6, 2023 · 8 comments · Fixed by #3362
Assignees

Comments

@MarcoGorelli
Copy link

Hi,

See here: pandas-dev/pandas#51794

The TCH code is reporting lots of errors in typing stub files (.pyi) - is this right? They're only used by the type checker anyway, perhaps TCH shouldn't run for this file type?

@charliermarsh
Copy link
Member

My initial reaction is that you’re right. Let me see what the originating plug-in does (though we may want to change it anyway even if they run on pyi files).

@MarcoGorelli
Copy link
Author

I didn't think flake8 ran on cython files to begin with (or at least, wasn't meant to)

@charliermarsh
Copy link
Member

Sorry, I might be misunderstanding - we’re talking about pyi stub files here, not Cython files, right?

@MarcoGorelli
Copy link
Author

sorry I'm mixing up things (in pandas I think .pyi files are only used to provide annotations for cython files), but the link makes it look like flake8 is only supposed to run on Python files

running it on a directory doesn't pick up the stub files, but indeed, passing them explicitly, the original plugin would flag them

(.311venv) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev$ flake8 pandas/_libs --select=TC001
(.311venv) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev$ flake8 pandas/_libs/lib.pyi --select=TC001
pandas/_libs/lib.pyi:16:1: TC001 Move application import 'pandas._typing.DtypeObj' into a type-checking block
pandas/_libs/lib.pyi:16:1: TC001 Move application import 'pandas._typing.npt' into a type-checking block
pandas/_libs/lib.pyi:16:1: TC001 Move application import 'pandas._typing.ArrayLike' into a type-checking block

@charliermarsh
Copy link
Member

Ahh ok, got it. Well, I think it makes sense to exclude these rules from the TCH checks, I don't see a benefit in enforcing those rules on stub files.

@charliermarsh
Copy link
Member

I can fix this today.

@twoertwein
Copy link

using if TYPE_CHECKING in pyi files probably also violates flake8-pyi's Y002

@charliermarsh
Copy link
Member

Oh lol yeah, that sounds bad then!

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

Successfully merging a pull request may close this issue.

3 participants