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

max function reports type errors in incorrect order #86729

Closed
nkobald mannequin opened this issue Dec 4, 2020 · 4 comments
Closed

max function reports type errors in incorrect order #86729

nkobald mannequin opened this issue Dec 4, 2020 · 4 comments
Labels
3.8 only security fixes pending The issue will be closed if no feedback is provided type-bug An unexpected behavior, bug, or error

Comments

@nkobald
Copy link
Mannequin

nkobald mannequin commented Dec 4, 2020

BPO 42563
Nosy @ericvsmith, @serhiy-storchaka

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 = None
closed_at = None
created_at = <Date 2020-12-04.00:57:36.757>
labels = ['type-bug', '3.8']
title = 'max function reports type errors in incorrect order'
updated_at = <Date 2020-12-04.16:18:21.358>
user = 'https://bugs.python.org/nkobald'

bugs.python.org fields:

activity = <Date 2020-12-04.16:18:21.358>
actor = 'eric.smith'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = []
creation = <Date 2020-12-04.00:57:36.757>
creator = 'nkobald'
dependencies = []
files = []
hgrepos = []
issue_num = 42563
keywords = []
message_count = 3.0
messages = ['382463', '382469', '382501']
nosy_count = 3.0
nosy_names = ['eric.smith', 'serhiy.storchaka', 'nkobald']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue42563'
versions = ['Python 3.8']

@nkobald
Copy link
Mannequin Author

nkobald mannequin commented Dec 4, 2020

I'm not _sure_ this is a bug, but I thought the behaviour was a bit odd. If you run max with a str and an int in different orders, you get this behaviour:

>>> max(123, 'hello')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '>' not supported between instances of 'str' and 'int'
>>> max(123, 'hello')

>>> max('hello', 123)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '>' not supported between instances of 'int' and 'str'

Note that order of the error message: 'int' and 'str' is the inverse of the order the str and int really are.

Did a search for max and didn't find this.

@nkobald nkobald mannequin added 3.8 only security fixes type-bug An unexpected behavior, bug, or error labels Dec 4, 2020
@serhiy-storchaka
Copy link
Member

This is because the code of the main() function is roughly equivalent to

    result = next(iter)
    for item in iter:
        if item > result:
            result = item

It can be changed to use "result < item" instead of "item > result", but it can has subtle differences in behavior. I am not sure what is better.

If we change it, it can only be in 3.10, because of the risk of affecting user code.

@serhiy-storchaka serhiy-storchaka added 3.10 only security fixes and removed 3.8 only security fixes labels Dec 4, 2020
@ericvsmith
Copy link
Member

I don't think making a change would be worth the risk.

@ericvsmith ericvsmith added 3.8 only security fixes and removed 3.10 only security fixes labels Dec 4, 2020
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@iritkatriel iritkatriel added the pending The issue will be closed if no feedback is provided label Nov 23, 2023
@iritkatriel
Copy link
Member

From the discussion I think we're not going to change this. Marking as pending and will close soon if there will be no objections.

@iritkatriel iritkatriel closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.8 only security fixes pending The issue will be closed if no feedback is provided type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants