[New-bugs-announce] [issue15223] datetime instances lack __module__ attribute

Chris Jerdonek report at bugs.python.org
Fri Jun 29 18:05:27 CEST 2012

New submission from Chris Jerdonek <chris.jerdonek at gmail.com>:

Instances of datetime.datetime don't seem to have the '__module__' attribute even though the datetime class itself does.

This seems to contradict Section 3.2 of the Python documentation about the standard type hierarchy (in the subsection called "Class instances"): http://docs.python.org/dev/reference/datamodel.html#the-standard-type-hierarchy

"A class instance has a namespace implemented as a dictionary which is the first place in which attribute references are searched. When an attribute is not found there, and the instance’s class has an attribute by that name, the search continues with the class attributes."

Instances of other classes defined in the standard library do have the attribute.

The session below illustrates the issue:

Python 3.3.0a4 (v3.3.0a4:7c51388a3aa7, May 30 2012, 16:58:42) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> datetime.__module__
>>> d = datetime(2000, 1, 1)
>>> d.__class__ 
<class 'datetime.datetime'>
>>> d.__module__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'datetime.datetime' object has no attribute '__module__'

components: Library (Lib)
messages: 164332
nosy: cjerdonek
priority: normal
severity: normal
status: open
title: datetime instances lack __module__ attribute
type: behavior
versions: Python 3.3

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list