New submission from Raymond Hettinger <raymond.hettin...@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 <rep...@bugs.python.org> <https://bugs.python.org/issue36762> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com