pylint icon indicating copy to clipboard operation
pylint copied to clipboard

Strange Emit of E0601 where something about shadowing a global would be clearer

Open Gloweye opened this issue 7 years ago • 1 comments

Steps to reproduce

Consider this code:

class Thing:
    def __init__(self, thing_type: type):
        self._type = thing_type
        self._value = None

    @property
    def type(self):
        return self._type

    @property
    def value(self):
        return self._value

    @value.setter
    def value(self, value):
        self._value = self._type(value)

Current behavior

This emits: E0601: Using variable 'type' before assignment (used-before-assignment) Because type is used as annotation before it is created as a property on the class.

Expected behavior

I would expect a warning about shadowing a global instead, since type is a builtin name.

I would not expect E0601 because at that point, the name is defined.

pylint --version output

main.py 2.1.1 astroid 2.0.4 Python 3.6.7 |Anaconda, Inc.| (default, Oct 28 2018, 19:44:12) [MSC v.1915 64 bit (AMD64)]

Background

Came up as an issue because of https://stackoverflow.com/questions/53598374/pylint-giving-not-callable-error-for-object-property-that-is-callable/ . This might give more background information.

Code can of course be fixed by removing the property named type. However, the warnings aren't anywhere near that.

Gloweye avatar Dec 05 '18 09:12 Gloweye

Thanks for the report, this makes sense!

PCManticore avatar Dec 11 '18 13:12 PCManticore