-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
bpo-36026: make descr error message consistent #11930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please provide tests?
Objects/descrobject.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why has this been changed?
There was a difference with classmethod descriptors, but classmethod descriptors were special, they are applied to types, not instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message is for method, not classmethod. But I changed classmethod error message too.
I feel same error message makes sense for classmethod too.
Discuss about actual error message on bpo.
Objects/descrobject.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, this is a really old bug (commit).
>>> desc = set.add
>>> desc(int)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: descriptor 'add' requires a 'set' object but received a 'type'
This should be ...but received a 'int', not 'type'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> desc(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: descriptor 'add' requires a 'set' object but received a 'int'
>>> desc(set)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: descriptor 'add' requires a 'set' object but received a 'type'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not look like a bug to me. If you will change it to produce ...but received a 'int', you will get ... requires a 'set' object but received a 'set' for desc(set), and I have no idea what you will get for descr(1).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, my example was wrong. This is classmethoddesc_call.
>>> desc2 = dict.__dict__['fromkeys']
>>> desc2(int, [])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: descriptor 'fromkeys' requires a subtype of 'dict' but received 'type
'type must be 'int'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set.add(0) and set.add.__get__(0) now raise TypeError with same error message.
set.add(0)andset.add.__get__(0)now raise TypeError with same error message.https://bugs.python.org/issue36026