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
Python 3.9 regression: Literal dict with > 65535 items are one item shorter #85703
Comments
Consider this reproducer.py: import sys
LEN = int(sys.argv[1])
with open('big_dict.py', 'w') as f:
print('INTS = {', file=f)
for i in range(LEN):
print(f' {i}: None,', file=f)
print('}', file=f)
import big_dict
assert len(big_dict.INTS) == LEN, len(big_dict.INTS) And run it with any number > 65535: $ python3.9 reproducer.py 65536
Traceback (most recent call last):
File "/tmp/reproducer.py", line 12, in <module>
assert len(big_dict.INTS) == LEN, len(big_dict.INTS)
AssertionError: 65535 This has not happened on python 3.8. This also happens with PYTHONOLDPARSER=1. |
Also reproduces with today's git. |
It appears that the 65535 key is missing regardless of the LEN value. |
Bisect says 8a4cd70 is the first bad commit. Considering that 0xFFFF appears a few times in that patch, that seems plausible ;) |
I think what's happening is that in 'compiler_dict' (Python/compile.c), it's checking whether 'elements' has reached a maximum (0xFFFF). However, it's not doing this after incrementing; instead, it's checking before incrementing and resetting 'elements' to 0 when it should be resetting to 1. The 65535th element isn't counted. |
How did you discover this issue? I'd like to clean up the code for creating dictionary literals and it might be helpful to know where such huge dictionary literals exist. |
@hroncok said on Twitter it was reported at Storyyeller/enjarify#17 |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: