[issue16268] dir(closure) claims that a closure has no __dir__, only to work later after manually invoking __dir__ from its type

Christopher the Magnificent report at bugs.python.org
Wed Oct 17 21:05:10 CEST 2012


New submission from Christopher the Magnificent:

This is really short, you should spot the inconsistency in the result of the same function call fairly easily.

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 01:25:11) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class Thing:
...     def method(self):
...             print(__class__)
... 
>>> x = Thing.method.__closure__[0]
>>> dir(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object does not provide __dir__
>>> type(x).__dir__(x)
['__gt__', '__eq__', '__setattr__', '__doc__', '__sizeof__', '__str__', '__init__', '__repr__', 'cell_contents', '__dir__', '__ge__', '__class__', '__new__', '__ne__', '__subclasshook__', '__hash__', '__lt__', '__reduce__', '__le__', '__getattribute__', '__format__', '__reduce_ex__', '__delattr__']
>>> dir(x)
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'cell_contents']
>>>

----------
components: Interpreter Core
messages: 173197
nosy: christopherthemagnificent
priority: normal
severity: normal
status: open
title: dir(closure) claims that a closure has no __dir__, only to work later after manually invoking __dir__ from its type
type: behavior
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16268>
_______________________________________


More information about the Python-bugs-list mailing list