ruff icon indicating copy to clipboard operation
ruff copied to clipboard

False Positive F811 Redfinition on class member if global variable with same name is unused.

Open Daraan opened this issue 1 year ago • 3 comments

Version: 0.7.1

In the following code snippet the class member is marked as redefinition

https://play.ruff.rs/ce10f9c6-0895-4146-932c-89c3aea05159

from queue import Empty

class Types:
    INVALID = 0
    UINT = 1
    HEX = 2
    Empty = 3  # <-- reported as redefinition

# q = Empty() <- this disables the error, if uncommented

Daraan avatar Oct 25 '24 16:10 Daraan

Pyflakes flags this, so I'm inclined to say it's working as expected.

charliermarsh avatar Oct 28 '24 01:10 charliermarsh

Looking at this more closely, it does seem consistent with how we handle redefinitions in function bodies.

https://play.ruff.rs/39ccfb6f-b0d6-4674-9fa1-6982797166fc

MichaReiser avatar Oct 28 '24 07:10 MichaReiser

Thank you for looking at it. True, it is a redefinition I guess a warning is then helpfull.

I am then only confused about the variable usage of it that disables the error: https://play.ruff.rs/47aeefef-757c-47ec-afb0-7952478d0aeb

q = Empty() # <- this disables the error, if uncommented

Daraan avatar Oct 28 '24 08:10 Daraan

The reason that the usage disables the warning is that F811 only warns about symbols that get redefined but are never used. Adding q = Empty() adds a use to Empty: It's still redefined, but no longer unused.

MichaReiser avatar Oct 30 '24 07:10 MichaReiser