Skip to content

Type hint for additional names in builtin namespace #5292

Answered by erictraut
prim asked this question in Q&A
Discussion options

You must be logged in to vote

I highly recommend that you do not dynamically modify the builtin namespace — or any other module's global namespace, for that matter. It leads to very fragile code and the potential for namespace collisions. Python has an import mechanism for good reason.

That said, there are legitimate reasons for needing to specify non-standard symbols within the builtins namespace. This is an issue for alternate Python distributions that are tailored for specific environments (such as embedded). Pyright, the type checker upon which pylance is built, has support for this case. You can read about it here.

Once again, I strongly recommend against the behavior you're suggesting. Just because Python allows…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@prim
Comment options

Answer selected by prim
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