[New-bugs-announce] [issue36762] Teach "import *" to warn when overwriting globals or builtins

Raymond Hettinger report at bugs.python.org
Tue Apr 30 18:31:42 EDT 2019


New submission from Raymond Hettinger <raymond.hettinger at gmail.com>:

One reason we usually suggest that people don't use star imports is that it is too easy to shadow a builtin or overwrite an existing global.  Momma Gump always used to say, "import star is like a box of chocolates, you never know what you've going to get".

>>> from os import *
Warning (from warnings module):
  File "__main__", line 1
ImportWarning: The 'open' variable in the 'os' module shadows a variable in the 'builtins' module

>>> alpha = 2.0
>>> beta = 3.0
>>> gamma = 4.5
>>> delta = 5.5
>>> from math import *
>>> from os import *
Warning (from warnings module):
  File "__main__", line 8
ImportWarning: The 'gamma' variable in the 'math' overwrites an existing variable in the globals.

----------
components: Interpreter Core
messages: 341166
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Teach "import *" to warn when overwriting globals or builtins
type: behavior
versions: Python 3.8

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


More information about the New-bugs-announce mailing list