Opened 11 years ago

Closed 10 years ago

#40227 closed defect (invalid)

error in tempfile of python 2.7.5

Reported by: renz@… Owned by: jyrkiwahlstedt
Priority: Normal Milestone:
Component: ports Version: 2.2.0
Keywords: Cc: ned-deily (Ned Deily), petrrr
Port: python27

Description

>>> tempfile.mktemp('.dat')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 356, in mktemp
    dir = gettempdir()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 265, in gettempdir
    tempdir = _get_default_tempdir()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 200, in _get_default_tempdir
    with _io.open(fd, 'wb', closefd=False) as fp:
AttributeError: 'module' object has no attribute 'open'

Change History (9)

comment:1 Changed 11 years ago by mf2k (Frank Schima)

Keywords: tempfile removed
Owner: changed from macports-tickets@… to jwa@…

In the future, please Cc the port maintainers (port info --maintainers python27).

comment:2 Changed 11 years ago by larryv (Lawrence Velázquez)

FWIW, I can’t reproduce this.

% port -v installed python27
The following ports are currently installed:
  python27 @2.7.5_1 (active) platform='darwin 12' archs='x86_64'
% /opt/local/bin/python2.7 -c 'import tempfile; print(tempfile.mktemp(".dat"))'
/var/folders/wb/4r15t9nx5bd4zht628hhnnqm0000gn/T/tmpVr5xzv.dat
%

comment:3 Changed 11 years ago by renz@…

It seems that tempfile.py imports io, but it somehow loads one of my file io.py in my PYTHONPATH. However, this didn't happen in python2.7.2. Do I have to keep out from a construction zone? How would I know?

% python -c 'import tempfile; print tempfile.mktemp(".dat")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io
  File "/Users/renz/code/cpl/io.py", line 217, in <module>
    ...

comment:4 Changed 11 years ago by larryv (Lawrence Velázquez)

Cc: nad@… added

comment:5 Changed 11 years ago by ned-deily (Ned Deily)

The io module has been in the Python standard library since Python 2.6. It looks like you've just been lucky up to now that having your own module named io did not conflict with the one in the standard library. For the record, as part of the fixes for http://bugs.python.org/issue16800 which was released in Python 2.7.4, the tempfile module was changed to use io. Shadowing of module names is a common trap. Probably the best general way to avoid it is by structuring your project as one or more Python packages thereby putting your modules in their own namespace (see http://docs.python.org/2/tutorial/modules.html#packages).

comment:6 Changed 10 years ago by petrrr

Cc: Peter.Danecek@… added

Cc Me!

comment:7 Changed 10 years ago by ryandesign (Ryan Carsten Schmidt)

It sounds like there's nothing we need to do in MacPorts for this issue and could close it as invalid?

comment:8 Changed 10 years ago by ned-deily (Ned Deily)

Yes, this is neither a MacPorts nor a Python issue. Either rename the user module that conflicts with the standard library one or restructure the user program to use its own package namespace.

comment:9 Changed 10 years ago by mf2k (Frank Schima)

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.