@@ -1627,6 +1627,10 @@ def _check_in_slots(self, node: nodes.AssignAttr) -> None:
16271627 # Properties circumvent the slots mechanism,
16281628 # so we should not emit a warning for them.
16291629 return
1630+ if node .attrname != "__class__" and utils .is_class_attr (
1631+ node .attrname , klass
1632+ ):
1633+ return
16301634 if node .attrname in klass .locals :
16311635 for local_name in klass .locals .get (node .attrname ):
16321636 statement = local_name .statement (future = True )
@@ -1642,7 +1646,12 @@ def _check_in_slots(self, node: nodes.AssignAttr) -> None:
16421646 slots , node .parent .value
16431647 ):
16441648 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+ )
16461655
16471656 @only_required_for_messages (
16481657 "protected-access" , "no-classmethod-decorator" , "no-staticmethod-decorator"
@@ -1777,7 +1786,7 @@ def _check_protected_attribute_access(
17771786 if (
17781787 self ._is_classmethod (node .frame (future = True ))
17791788 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 )
17811790 ):
17821791 return
17831792
@@ -1824,19 +1833,16 @@ def _is_inferred_instance(expr, klass: nodes.ClassDef) -> bool:
18241833 return inferred ._proxied is klass
18251834
18261835 @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 :
18281837 """Check if the given attribute *name* is a class or instance member of the
18291838 given *klass*.
18301839
18311840 Returns ``True`` if the name is a property in the given klass,
18321841 ``False`` otherwise.
18331842 """
18341843
1835- try :
1836- klass .getattr (name )
1844+ if utils .is_class_attr (name , klass ):
18371845 return True
1838- except astroid .NotFoundError :
1839- pass
18401846
18411847 try :
18421848 klass .instance_attr (name )
0 commit comments