@@ -1627,6 +1627,10 @@ def _check_in_slots(self, node: nodes.AssignAttr) -> None:
1627
1627
# Properties circumvent the slots mechanism,
1628
1628
# so we should not emit a warning for them.
1629
1629
return
1630
+ if node .attrname != "__class__" and utils .is_class_attr (
1631
+ node .attrname , klass
1632
+ ):
1633
+ return
1630
1634
if node .attrname in klass .locals :
1631
1635
for local_name in klass .locals .get (node .attrname ):
1632
1636
statement = local_name .statement (future = True )
@@ -1642,7 +1646,12 @@ def _check_in_slots(self, node: nodes.AssignAttr) -> None:
1642
1646
slots , node .parent .value
1643
1647
):
1644
1648
return
1645
- self .add_message ("assigning-non-slot" , args = (node .attrname ,), node = node )
1649
+ self .add_message (
1650
+ "assigning-non-slot" ,
1651
+ args = (node .attrname ,),
1652
+ node = node ,
1653
+ confidence = INFERENCE ,
1654
+ )
1646
1655
1647
1656
@only_required_for_messages (
1648
1657
"protected-access" , "no-classmethod-decorator" , "no-staticmethod-decorator"
@@ -1777,7 +1786,7 @@ def _check_protected_attribute_access(
1777
1786
if (
1778
1787
self ._is_classmethod (node .frame (future = True ))
1779
1788
and self ._is_inferred_instance (node .expr , klass )
1780
- and self ._is_class_attribute (attrname , klass )
1789
+ and self ._is_class_or_instance_attribute (attrname , klass )
1781
1790
):
1782
1791
return
1783
1792
@@ -1824,19 +1833,16 @@ def _is_inferred_instance(expr, klass: nodes.ClassDef) -> bool:
1824
1833
return inferred ._proxied is klass
1825
1834
1826
1835
@staticmethod
1827
- def _is_class_attribute (name : str , klass : nodes .ClassDef ) -> bool :
1836
+ def _is_class_or_instance_attribute (name : str , klass : nodes .ClassDef ) -> bool :
1828
1837
"""Check if the given attribute *name* is a class or instance member of the
1829
1838
given *klass*.
1830
1839
1831
1840
Returns ``True`` if the name is a property in the given klass,
1832
1841
``False`` otherwise.
1833
1842
"""
1834
1843
1835
- try :
1836
- klass .getattr (name )
1844
+ if utils .is_class_attr (name , klass ):
1837
1845
return True
1838
- except astroid .NotFoundError :
1839
- pass
1840
1846
1841
1847
try :
1842
1848
klass .instance_attr (name )
0 commit comments