[issue16894] Function attribute access doesn't invoke methods in dict subclasses

2021-01-01 Thread David Beazley


Change by David Beazley :


--
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16894] Function attribute access doesn't invoke methods in dict subclasses

2020-03-06 Thread Brett Cannon


Change by Brett Cannon :


--
nosy:  -brett.cannon

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16894] Function attribute access doesn't invoke methods in dict subclasses

2013-01-14 Thread Meador Inge

Changes by Meador Inge mead...@gmail.com:


--
nosy: +meador.inge

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16894
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16894] Function attribute access doesn't invoke methods in dict subclasses

2013-01-10 Thread Daniel Urban

Changes by Daniel Urban urban.dani...@gmail.com:


--
nosy: +daniel.urban

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16894
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16894] Function attribute access doesn't invoke methods in dict subclasses

2013-01-09 Thread Eric Snow

Eric Snow added the comment:

Looks like a case where the concrete dict API is ignoring subtype 
implementations.

In your example the attribute access will be handled by a LOAD_ATTR which calls 
PyObject_GetAttr() (Python/ceval.c:2369).  That ends up calling 
PyFunction_Type.tp_getattro (inherited from PyBaseObject_Type).

That ends up just being PyObject_GenericGetAttr() (Objects/object.c:1061).  The 
dict gets pulled from foo using PyFunction_Type.-tp_dictoffset and then 
PyDict_GetItem() gets called on it.

Unfortunately, PyDict_GetItem() is hard-coded to the dict implementation.  At 
this point your __getitem__() has been entirely circumvented!

FYI, this is a pain point for myself right now so it's been on my mind 
(COrderedDict and kwargs).  This came up in 2011.  See issue 10977.

--
nosy: +eric.snow

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16894
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16894] Function attribute access doesn't invoke methods in dict subclasses

2013-01-08 Thread David Beazley

New submission from David Beazley:

Suppose you subclass a dictionary:

class mdict(dict):
def __getitem__(self, index):
print('Getting:', index)
return super().__getitem__(index)

Now, suppose you define a function and perform these steps that reassign the 
function's attribute dictionary:

 def foo():
... pass
... 
 foo.__dict__ = mdict()
 foo.x = 23
 foo.x  # Observe: No output from overridden __getitem__
23
 type(foo.__dict__)
class '__main__.mdict'
 foo.__dict__
{'x': 23}
 

Carefully observe that access to foo.x does not invoke the overridden 
__getitem__() method in mdict.  Instead, it just directly accesses the default 
__getitem__() on dict. 

Admittedly, this is a really obscure corner case.  However, if the __dict__ 
attribute of a function can be legally reassigned, it might be nice for 
inheritance to work ;-).

--
components: Interpreter Core
messages: 179364
nosy: dabeaz
priority: normal
severity: normal
status: open
title: Function attribute access doesn't invoke methods in dict subclasses
type: behavior
versions: Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16894
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16894] Function attribute access doesn't invoke methods in dict subclasses

2013-01-08 Thread Alex Gaynor

Changes by Alex Gaynor alex.gay...@gmail.com:


--
nosy: +alex

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16894
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16894] Function attribute access doesn't invoke methods in dict subclasses

2013-01-08 Thread Brett Cannon

Changes by Brett Cannon br...@python.org:


--
nosy: +brett.cannon

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16894
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com