Skip to content

Conversation

@methane
Copy link
Member

@methane methane commented Feb 19, 2019

set.add(0) and set.add.__get__(0) now raise TypeError with same error message.

https://bugs.python.org/issue36026

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a 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?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

@methane methane Mar 26, 2019

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'.

Copy link
Member

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'

Copy link
Member

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).

Copy link
Member Author

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'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

methane added 2 commits March 26, 2019 22:10
set.add(0) and set.add.__get__(0) now raise TypeError
with same error message.
@methane methane merged commit 62f9588 into python:master Apr 1, 2019
@methane methane deleted the descr-errormsg branch April 1, 2019 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants