Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:
I'm glad that you fixed the bug in your code, but this is not a bug in Python. It isn't "a parsing issue", the code is parsed fine. What you did was no different from: def func(): print(x) x = 1 except that the binding operation was an import, not an assignment. You get exactly the same error here: def func(): print(math) import math That's the way the language is defined. Imports and assignments are both binding operations and are treated the same by the interpreter. It's not an accident or a mistake or a parsing issue or a bug, it is the way the language is supposed to work. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45294> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com