[New-bugs-announce] [issue35166] BUILD_MAP_UNPACK doesn't function as expected for dict subclasses

Dan Snider report at bugs.python.org
Mon Nov 5 01:23:01 EST 2018


New submission from Dan Snider <mr.assume.away at gmail.com>:

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

----------
components: Interpreter Core
messages: 329280
nosy: bup
priority: normal
severity: normal
status: open
title: BUILD_MAP_UNPACK doesn't function as expected for dict subclasses
type: behavior
versions: Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35166>
_______________________________________


More information about the New-bugs-announce mailing list