Skip to content

How to pre-define symbols? #1149

Answered by erictraut
frozax asked this question in Q&A
Apr 11, 2021 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

While Python allows code to "insert" symbols into the namespace of another module, this practice is very fragile, and I would highly discourage library authors from using it. It potentially overwrites symbols of the same name in other modules, and it makes code difficult to follow (both for static code tools and for humans). Symbols should be imported explicitly to avoid namespace collisions.

If you are the consumer of a library that implements this dangerous and ill-advised behavior, you have a few options:

  1. Although the symbol is already implicitly "inserted" into your module's namespace, use a proper explicit import statement to import the symbol again. Pylance and other tools (and rea…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@frozax
Comment options

@erictraut
Comment options

Answer selected by frozax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants