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

Add a py.typed file to flake8 #1560

Closed
AlexWaygood opened this issue Feb 11, 2022 · 13 comments
Closed

Add a py.typed file to flake8 #1560

AlexWaygood opened this issue Feb 11, 2022 · 13 comments

Comments

@AlexWaygood
Copy link

describe the request

Hi! I'm a (relatively new) maintainer of flake8-pyi, a flake8 plugin for linting .pyi stub files. Slightly embarrasingly, for a plugin that's so focussed on improving the Python-typing ecosystem, our codebase is not yet fully typed, and I'm trying to improve on that.

One issue is that our imports from flake8 require # type: ignore[import] comments in order for mypy to be happy with them. However, it looks like flake8 is already fully typed, meaning all that flake8 needs in order to meet the standard outlined in PEP 561 is to add a py.typed file to the repo. If flake8 adds the py.typed file, we can remove the # type: ignore comments from our imports, and mypy will have a much greater ability to understand what's going on in our code.

Would you be receptive to the idea of adding a py.typed file to flake8? I'd be happy to submit a PR, if so.

@asottile
Copy link
Member

flake8's only public interface is being phased out and replaced -- it doesn't intend to expose any other part of its api so I'd rather hold off on adding a py.typed file

@asottile
Copy link
Member

for example, both of these imports reach into implementation details that are not part of flake8's interface (your plugin will be broken): https://github.com/PyCQA/flake8-pyi/blob/02b101b67bb45812b2a4d5697aca1c36d4eb1551/pyi.py#L21-L22

@AlexWaygood
Copy link
Author

Makes sense — thanks for the quick response, and all the work you do to maintain the project!

@JelleZijlstra
Copy link

@asottile would you be interested in having flake8 natively support linting pyi files? That way, the flake8-pyi plugin wouldn't need to reach into flake8 internals.

@asottile
Copy link
Member

flake8 really only supports python files, pyi is a bit of a different beast. that said -- the incompatibilities aren't with flake8 but with other plugins

@AlexWaygood
Copy link
Author

the incompatibilities aren't with flake8 but with other plugins

Yes, it's only really the pyflakes checks that cause us difficulties over at flake8-pyi. Would it be worth opening an issue over at pyflakes, do you think?

@asottile
Copy link
Member

there appear to be a few already: https://github.com/PyCQA/pyflakes/issues?q=is%3Aissue+pyi+is%3Aclosed

@sigmavirus24
Copy link
Member

What's the actual goal of flake8-pyi?

@JelleZijlstra
Copy link

@sigmavirus24 it provides linting for stub files, including a number of checks that only make sense in stubs (for example, it warns if a function body is anything other than ...). I guess the goal is to make it so when we review code at https://github.com/python/typeshed, there's fewer things we have to check manually :)

@sigmavirus24
Copy link
Member

Maybe it's controversial but should that just be pyilint? Or some better band that does this in a lightweight way? This reminds me of folks trying to hack in linting of cython or restructured text or other jupyter notebooks.

I guess I'm wondering what's necessary about it being a plugin or what you see as the benefits to you developing it as a plugin and having to reach into things to make it sort of work for a brief period of time

@JelleZijlstra
Copy link

It took me a while there to realize you were not suggesting to use pylint :)

A completely standalone tool would also be an option, but by building on flake8 we get the benefits of leaning on flake8 for things like error reporting, # noqa support, etc. Also, pyi files mostly are Python, and there are other flake8 checks that can be useful on them (line length, redefined names, undefined names).

@sigmavirus24
Copy link
Member

It took me a while there to realize you were not suggesting to use pylint :)

Sorry, it was meant as a tongue in cheek joke

@sigmavirus24
Copy link
Member

A completely standalone tool would also be an option, but by building on flake8 we get the benefits of leaning on flake8 for things like error reporting, # noqa support, etc. Also, pyi files mostly are Python, and there are other flake8 checks that can be useful on them (line length, redefined names, undefined names

So, pycodestyle and pyflakes independently do most of what you want from Flake8. I think most of what you'd want our of Flake8 is the noqa support and maybe config handling with CLI parsing on top?

I don't know you're getting enough from being a flake8 plugin. Part of me still wants to generalize a bunch of the fundamentals of Flake8 that people want into a library for others but never had enough reason to do so. Given how much of it I wrote, I also wouldn't object to it being forked/copied personally if someone wanted to

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

4 participants