PyCharm inspection for assignment to undefined attributes

I know PyCharm detects unresolved references when reading undefined attributes, but I'd like to catch cases where I'm assigning to attributes that don't exist (typos). Is there a setting or inspection I can enable for this? I've looked in Settings > Editor > Inspections but haven't found.

class CC:
    def __init__(self):
        self.x = 1
c = CC()
c.a = c.b

PyCharm can warn that c.b might not exists but it has no warning for c.a 
I am interested in an IDE warning (not interesed in modifying class to prevent assignmnet at runtime).

 

0
正式评论

Hi there

 

Thank you for reaching out, 

It seems this is a known (rather old) bug raised here:

https://youtrack.jetbrains.com/issue/PY-49035/Warn-about-attaching-new-attributes-to-an-instance-outside-its-class-methods

Please feel free to follow / upvote the above case.

Kind regards

 

请先登录再写评论。