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
BUILD_MAP_UNPACK doesn't function as expected for dict subclasses #79347
Comments
>>> class Dict(dict):
def keys(self): assert 0
def update(*args, **kwds): assert 0
def __getitem__(self, key): assert 0
def __iter__(self): assert 0
>>> {**Dict(a=1)}
{'a': 1} The opcode uses PyDict_Update, which calls the internal dict_merge function which contains the following line:
Translated to Python, that should be equal to
Both that and the line in C evaluate to false for me (while a dict subclass that doesn't override __iter__ evaluates to true), so I The BUILD_MAP_UNPACK_WITH_CALL, CALL_FUNCTION_EX, and CALL_FUNCTION_KW opcodes are affected as well. |
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in keys
AssertionError This works as expected to me. |
You say it doesn't work as expected, but you don't say what you expect or why. (Don't make me guess what you mean -- explicit is better than implicit.) When I try your subclass in 3.6, I get an unexpected TypeError: py> class Dict(dict):
... def keys(self): assert 0
... def update(*args, **kwds): assert 0
... def __getitem__(self, key): assert 0
... def __iter__(self): assert 0
...
py> {**Dict(a=1)}
{'a': 1}
py> Dict(a=1).keys()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in keys
TypeError |
How weird... after restarting the interpreter, I can't reproduce that TypeError. I get the AssertionError Serhiy showed. |
BUILD_MAP_UNPACK and BUILD_MAP_UNPACK_WITH_CALL have been removed. |
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: