diff --git a/ChangeLog b/ChangeLog index 52007414b8..d6b71e6c28 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,9 @@ Release date: TBA .. Put new features here and also in 'doc/whatsnew/2.14.rst' +* Update ``invalid-slots-object`` message to show bad object rather than its inferred value. + + Closes #6101 * Added new checker ``typevar-name-mismatch``: TypeVar must be assigned to a variable with the same name as its name argument. diff --git a/doc/whatsnew/2.14.rst b/doc/whatsnew/2.14.rst index dfe548f4bd..ce3c1cedfe 100644 --- a/doc/whatsnew/2.14.rst +++ b/doc/whatsnew/2.14.rst @@ -60,6 +60,10 @@ Extensions Other Changes ============= +* Update ``invalid-slots-object`` message to show bad object rather than its inferred value. + + Closes #6101 + * Removed the broken ``generate-man`` option. Closes #5283 diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py index b9c11d1132..cc6a109582 100644 --- a/pylint/checkers/classes/class_checker.py +++ b/pylint/checkers/classes/class_checker.py @@ -1429,12 +1429,18 @@ def _check_slots_elt(self, elt, node): inferred.value, str ): self.add_message( - "invalid-slots-object", args=inferred.as_string(), node=elt + "invalid-slots-object", + args=elt.as_string(), + node=elt, + confidence=INFERENCE, ) continue if not inferred.value: self.add_message( - "invalid-slots-object", args=inferred.as_string(), node=elt + "invalid-slots-object", + args=elt.as_string(), + node=elt, + confidence=INFERENCE, ) # Check if we have a conflict with a class variable. diff --git a/tests/functional/s/slots_checks.py b/tests/functional/s/slots_checks.py index 79912b65c4..0eec9182ac 100644 --- a/tests/functional/s/slots_checks.py +++ b/tests/functional/s/slots_checks.py @@ -57,6 +57,12 @@ class SeventhBad(object): # [single-string-used-for-slots] class EighthBad(object): # [single-string-used-for-slots] __slots__ = deque.__name__ +class NinthBad(object): + __slots__ = [str] # [invalid-slots-object] + +class TenthBad(object): + __slots__ = [1 + 2 + 3] # [invalid-slots-object] + class PotentiallyGood(object): __slots__ = func() diff --git a/tests/functional/s/slots_checks.txt b/tests/functional/s/slots_checks.txt index 17b3195522..49b3149124 100644 --- a/tests/functional/s/slots_checks.txt +++ b/tests/functional/s/slots_checks.txt @@ -1,11 +1,13 @@ invalid-slots:36:0:36:9:Bad:Invalid __slots__ object:UNDEFINED invalid-slots:39:0:39:15:SecondBad:Invalid __slots__ object:UNDEFINED -invalid-slots-object:43:22:43:23:ThirdBad:Invalid object '2' in __slots__, must contain only non empty strings:UNDEFINED +invalid-slots-object:43:22:43:23:ThirdBad:Invalid object '2' in __slots__, must contain only non empty strings:INFERENCE invalid-slots:45:0:45:15:FourthBad:Invalid __slots__ object:UNDEFINED -invalid-slots-object:49:27:49:29:FifthBad:"Invalid object ""''"" in __slots__, must contain only non empty strings":UNDEFINED +invalid-slots-object:49:27:49:29:FifthBad:"Invalid object ""''"" in __slots__, must contain only non empty strings":INFERENCE single-string-used-for-slots:51:0:51:14:SixthBad:Class __slots__ should be a non-string iterable:UNDEFINED single-string-used-for-slots:54:0:54:16:SeventhBad:Class __slots__ should be a non-string iterable:UNDEFINED single-string-used-for-slots:57:0:57:15:EighthBad:Class __slots__ should be a non-string iterable:UNDEFINED -class-variable-slots-conflict:85:17:85:24:ValueInSlotConflict:Value 'first' in slots conflicts with class variable:UNDEFINED -class-variable-slots-conflict:85:45:85:53:ValueInSlotConflict:Value 'fourth' in slots conflicts with class variable:UNDEFINED -class-variable-slots-conflict:85:36:85:43:ValueInSlotConflict:Value 'third' in slots conflicts with class variable:UNDEFINED +invalid-slots-object:61:17:61:20:NinthBad:Invalid object 'str' in __slots__, must contain only non empty strings:INFERENCE +invalid-slots-object:64:17:64:26:TenthBad:Invalid object '1 + 2 + 3' in __slots__, must contain only non empty strings:INFERENCE +class-variable-slots-conflict:91:17:91:24:ValueInSlotConflict:Value 'first' in slots conflicts with class variable:UNDEFINED +class-variable-slots-conflict:91:45:91:53:ValueInSlotConflict:Value 'fourth' in slots conflicts with class variable:UNDEFINED +class-variable-slots-conflict:91:36:91:43:ValueInSlotConflict:Value 'third' in slots conflicts with class variable:UNDEFINED