[issue32845] Mac: Local modules can shadow builtins (e.g. a local `math.py` can shadow `math`)

Ned Deily report at bugs.python.org
Wed Feb 14 20:08:51 EST 2018


Ned Deily <nad at python.org> added the comment:

This had me confused for a while.  But eric.smith's comment is the clue to what's going on here:

> This is the expected behavior, fortunately or not. "math" is not builtin in the sense that is used in that paragraph.

The difference in behavior that you are seeing seems to be due to the fact that the Debian/Ubuntu uses a non-standard build to build-in the standard lib "math" module, whereas the Mac version you are using undoubtedly does not.  You can see this behavior yourself if you build your own version of python (either 2.7 or 3.x) on your Ubuntu system.  You should now see the same behavior you see on the Mac.  For example:

# on a current Debian system
$ /usr/bin/python2.7 -c 'import sys,math;print(sys.modules["math"])'
<module 'math' (built-in)>

# on a current Mac system using the python.org 2.7.14
$ /usr/local/bin/python2.7 -c 'import sys,math;print(sys.modules["math"])'
<module 'math' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/math.so'>

So, I don't think this is an issue at all.  Please reopen if you think there is actually a problem here.

----------
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

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


More information about the Python-bugs-list mailing list