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

BUILD_MAP_UNPACK doesn't function as expected for dict subclasses #79347

Closed
mr-nfamous mannequin opened this issue Nov 5, 2018 · 5 comments
Closed

BUILD_MAP_UNPACK doesn't function as expected for dict subclasses #79347

mr-nfamous mannequin opened this issue Nov 5, 2018 · 5 comments
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@mr-nfamous
Copy link
Mannequin

mr-nfamous mannequin commented Nov 5, 2018

BPO 35166
Nosy @stevendaprano, @serhiy-storchaka, @mr-nfamous, @iritkatriel

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 2018-11-05.06:23:01.388>
labels = ['interpreter-core', 'type-bug', '3.7']
title = "BUILD_MAP_UNPACK doesn't function as expected for dict subclasses"
updated_at = <Date 2021-12-30.13:20:40.929>
user = 'https://github.com/mr-nfamous'

bugs.python.org fields:

activity = <Date 2021-12-30.13:20:40.929>
actor = 'iritkatriel'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2018-11-05.06:23:01.388>
creator = 'bup'
dependencies = []
files = []
hgrepos = []
issue_num = 35166
keywords = []
message_count = 5.0
messages = ['329280', '329281', '329282', '329283', '409368']
nosy_count = 4.0
nosy_names = ['steven.daprano', 'serhiy.storchaka', 'bup', 'iritkatriel']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue35166'
versions = ['Python 3.6', 'Python 3.7']

@mr-nfamous
Copy link
Mannequin Author

mr-nfamous mannequin commented Nov 5, 2018

>>> 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:

if (PyDict_Check(b) && (Py_TYPE(b)->tp_iter == (getiterfunc)dict_iter))

Translated to Python, that should be equal to

if type(b).__flags__ & (1<<29) and type.__getattribute__(type(b), '__iter__') is type.__getattribute__(dict, '__iter__')`

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
apparently can't help narrow down the problem any further assuming people agree that this is even is a problem...

The BUILD_MAP_UNPACK_WITH_CALL, CALL_FUNCTION_EX, and CALL_FUNCTION_KW opcodes are affected as well.

@mr-nfamous mr-nfamous mannequin added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Nov 5, 2018
@serhiy-storchaka
Copy link
Member

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in keys
AssertionError

This works as expected to me.

@stevendaprano
Copy link
Member

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

@stevendaprano
Copy link
Member

How weird... after restarting the interpreter, I can't reproduce that TypeError. I get the AssertionError Serhiy showed.

@iritkatriel
Copy link
Member

BUILD_MAP_UNPACK and BUILD_MAP_UNPACK_WITH_CALL have been removed.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@iritkatriel iritkatriel closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants