mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-17627 PY-17733 Resolve class attributes defined in @classmethods
The logic is similar to that for instance attributes. Top-level class attributes and methods defined in the class body get the precedence, followed by class attributes defined with assignments in @classmethods unless the latter would resolve to the same assignments as in cls.attr = cls.attr + 1 finally, we scan through all other class methods resolving the name to the first definition inside one of them. So far, I intentionally didn't expose such attributes in findClassAttribute() or getClassAttributes() because users of these methods assume that this API considers only attributes defined immediately in the class body. Adding extra definitions from class methods might break these usages. I had to update the inspection about typing.Final, because it relied on the fact that resolve() on assignment targets on class objects can lead only to those top-level class attributes, where type hints are normally located, but now it can lead to assignments to a qualified attribute inside a containing class method. GitOrigin-RevId: 0ca5bdaa4efca127ac187e822a49df6795e1028a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c0c2bd301b
commit
cef42660a3
@@ -0,0 +1,8 @@
|
||||
class C:
|
||||
@classmethod
|
||||
def first(cls):
|
||||
cls.attr = 1
|
||||
|
||||
@classmethod
|
||||
def second(cls):
|
||||
print(cls.attr)
|
||||
@@ -0,0 +1,8 @@
|
||||
class C:
|
||||
@classmethod
|
||||
def first(cls):
|
||||
cls.attr = 1
|
||||
|
||||
@classmethod
|
||||
def second(cls):
|
||||
print(cls.at<caret>)
|
||||
Reference in New Issue
Block a user