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

UP035: doesn't detect errors when it should #10955

Open
morotti opened this issue Apr 15, 2024 · 2 comments
Open

UP035: doesn't detect errors when it should #10955

morotti opened this issue Apr 15, 2024 · 2 comments
Labels
rule Implementing or modifying a lint rule

Comments

@morotti
Copy link

morotti commented Apr 15, 2024

Hello,

I am trying to use ruff to automatically fix issues with collections import that have moved to collections.abc in python 3.10+

I've found that ruff can only detect and fix the import about half the time.

from collections import Iterable

def myfunction(arg):
    if isinstance(arg, Iterable):
        return True
    return False

myfunction("string")
import collections

def myfunction(arg):
    if isinstance(arg, collections.Iterable):
        return True
    return False

myfunction("string")

Try with ruff --select ALL example.py

In the top example, ruff finds the error and can fix it automatically.

example.py:1:1: UP035 [*] Import from `collections.abc` instead: `Iterable`

In the bottom example, ruff doesn't find any error when it should have.
The code fails at runtime.

Traceback (most recent call last):
  File "/home/username/example.py", line 8, in <module>
    myfunction("string")
  File "/home/username/example.py", line 4, in myfunction
    if isinstance(arg, collections.Iterable):
                       ^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'collections' has no attribute 'Iterable'

Running on latest ruff release, 0.3.7, on python 3.11

@charliermarsh
Copy link
Member

That rule flags imports, not usages, and so it doesn't flag attribute accesses on the module, just from collections import ... cases.

@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label May 3, 2024
@jerr0328
Copy link

It looks like the same as #3936 and #7526

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

3 participants