-
Hello, my code will register some variables in the builtin namespace so that they can be used anywhere just like names such as dict/list/len. My question is, how should I make Pylance recognize these additional names in the built-in namespace? I can't find relevant documentation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 you to do it doesn't make it a good idea. |
Beta Was this translation helpful? Give feedback.
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…