New submission from Eric V. Smith <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue44655>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com