[New-bugs-announce] [issue44655] Confusing error with __slots__

Eric V. Smith report at bugs.python.org
Fri Jul 16 15:14:32 EDT 2021


New submission from Eric V. Smith <eric at trueblade.com>:

This is related to issue 44649. This is the simplest non-dataclasses case I could come up with.

Given:

class Example:
    __slots__ = ('a', 'b')
    def __init__(self, a):
        self.a = a

obj = Example(42)
print(obj.b)

I get this in 3.10 and main:

Traceback (most recent call last):
  File "C:\home\eric\local\python\cpython\testdc.py", line 7, in <module>
    print(obj.b)
          ^^^^^
AttributeError: b. Did you mean: 'b'?


The error message is confusing.

3.8 gives:

Traceback (most recent call last):
  File "testdc.py", line 7, in <module>
    print(obj.b)
AttributeError: b

I don't have 3.9 around to test with.

Maybe don't print the "Did you mean" part if the suggestion is the same as the requested attribute?

The fact that the instance variable isn't initialized is the actual error in issue 44649, and I'll fix it there.

----------
components: Interpreter Core
messages: 397652
nosy: eric.smith, pablogsal
priority: normal
severity: normal
status: open
title: Confusing error with __slots__
type: behavior
versions: Python 3.10, Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44655>
_______________________________________


More information about the New-bugs-announce mailing list