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