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

Interpreting type comment is missing, producing different result from flake8 #10501

Closed
cielavenir opened this issue Mar 21, 2024 · 3 comments
Closed
Labels
question Asking for support or clarification

Comments

@cielavenir
Copy link

Version

$ ruff --version
ruff 0.3.3
$ python3 -m flake8 --version
3.9.2 (flake8_logger: 0.0.0, mccabe: 0.6.1, pycodestyle: 2.7.0, pyflakes: 2.3.1, teamcity-messages: 1.21) CPython 3.9.2 on Linux

Code with import:

import collections


class ToyClass(object):
    dic = None  # type: collections.defaultdict

Result:

$ python3 -m flake8 typecomment1.py 
$ ruff check typecomment1.py 
typecomment1.py:1:8: F401 [*] `collections` imported but unused
Found 1 error.
[*] 1 fixable with the `--fix` option.

Code without import:

class ToyClass(object):
    dic = None  # type: collections.defaultdict

Result:

$ python3 -m flake8 typecomment2.py
typecomment.py:2:17: F821 undefined name 'collections'
$ ruff check typecomment2.py 
All checks passed!

This means that Ruff does not interpret type comment while flake8 does.

I searched for "type comment".


Found by a collegue of mine @braineo .

@AlexWaygood
Copy link
Member

Thanks for the report!

The latest version of flake8 also does not understand type comments; flake8 3.9.2 is several years old now. It dropped support so that it could improve performance, and because there's no reason to use type comments unless you support very old Python versions that have been end-of-life for a long time. The relevant change here is in one of the builtin flake8 plugins, pyflakes:

Since great tools such as https://github.com/ilevkivskyi/com2ann exist that can help people auto-upgrade their legacy type comments to type annotations, I'm therefore sceptical that ruff should add support for type comments.

@MichaReiser MichaReiser added the question Asking for support or clarification label Mar 21, 2024
@AlexWaygood
Copy link
Member

It looks like this issue is actually a duplicate of #1619, so I'll close in favour of that one 👍

@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Mar 21, 2024
@felixvd
Copy link

felixvd commented Mar 22, 2024

That's a fair point. Thanks for your prompt and detailed response @AlexWaygood

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

4 participants