python / cpython

The Python programming language
https://www.python.org/
Other
60.06k stars 29.09k forks source link

Incorrect hexadecimal to decimal conversion in enum example #118443

Closed array93 closed 2 weeks ago

array93 commented 3 weeks ago

Documentation

Section describing __new__(cls, *args, **kwds) says:

results in the call int('1a', 16) and a value of 17 for the member.

While class int(x, base=10) suggests the value would be 26 since 1A hex is 26 decimal.

Also wouldn't the enum in the example need to inherit from int to get its __new__ implementation? I'm confused about the mixed-in.

array93 commented 3 weeks ago

also the example itself does not implement __new__ which would make the value a tuple?

eendebakpt commented 3 weeks ago

@array93 Thanks for reporting, you are right the documentation was not correct. The issue was recently fixed in https://github.com/python/cpython/pull/118311. That change will take some time though before it ends up in the official documentation.

hugovk commented 2 weeks ago

Thanks both, let's mark this as a duplicate of https://github.com/python/cpython/issues/118310.