Skip to content
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

list's in-place add doesn't return NotImplemented when appropriate #66967

Closed
ethanfurman opened this issue Oct 31, 2014 · 3 comments
Closed

list's in-place add doesn't return NotImplemented when appropriate #66967

ethanfurman opened this issue Oct 31, 2014 · 3 comments
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@ethanfurman
Copy link
Member

BPO 22778
Nosy @rhettinger, @ethanfurman

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/rhettinger'
closed_at = <Date 2014-10-31.22:20:20.183>
created_at = <Date 2014-10-31.22:07:49.806>
labels = ['type-bug', 'invalid']
title = "list's in-place add doesn't return NotImplemented when appropriate"
updated_at = <Date 2014-10-31.22:43:33.995>
user = 'https://github.com/ethanfurman'

bugs.python.org fields:

activity = <Date 2014-10-31.22:43:33.995>
actor = 'ethan.furman'
assignee = 'rhettinger'
closed = True
closed_date = <Date 2014-10-31.22:20:20.183>
closer = 'rhettinger'
components = []
creation = <Date 2014-10-31.22:07:49.806>
creator = 'ethan.furman'
dependencies = []
files = []
hgrepos = []
issue_num = 22778
keywords = []
message_count = 3.0
messages = ['230396', '230401', '230408']
nosy_count = 2.0
nosy_names = ['rhettinger', 'ethan.furman']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue22778'
versions = ['Python 3.5']

@ethanfurman
Copy link
Member Author

--> s = []
--> s += 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable

For comparison, when NotImplemented is appropriately returned the message looks like this:

--> s -= 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -=: 'list' and 'int'

Which is certainly more helpful than "<blank> object is not iterable"

@ethanfurman ethanfurman added the type-bug An unexpected behavior, bug, or error label Oct 31, 2014
@rhettinger
Copy link
Contributor

Please don't replicate existing issues.

Also, this behavior for lists is long-standing, tested, and designed by Guido. More than a little code relies on this behavior.

@rhettinger rhettinger self-assigned this Oct 31, 2014
@ethanfurman
Copy link
Member Author

My understanding was that if a different patch will be needed, it is not the same issue. Is that not correct?

Here's the test:

    def test_iadd(self):
        ...
        self.assertRaises(TypeError, u.__iadd__, None)

It would still pass, as returning NotImplemented will still result in a TypeError, just with a friendlier message.

If any code is depending on this, it is depending on the error message text, which is explicitly not guaranteed

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants