Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a builtins parameter #2103

Closed
Neyri opened this issue Nov 23, 2021 · 7 comments
Closed

Add a builtins parameter #2103

Neyri opened this issue Nov 23, 2021 · 7 comments
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version typestub Issue relating to our bundled type stubs

Comments

@Neyri
Copy link

Neyri commented Nov 23, 2021

Hello,
I am working on databricks notebooks and I use VScode to edit the content of the notebooks.
I make extensive use of builtin databricks functions such as dbutils or spark. However I find Pylance raises an UndefinedVariable on those functions as they are not locally declared.
I would like to be able to specify some builtins functions that pylance won't raise an undefined error on. I imagine this would be similar to flake8's approach on the subject, see here

Even better : I would like to be able to specify a databricks profile where all databricks' builtin functions will be already defined (and autocompletion compatible). But not sure that fits in the philosophy of the package.

@erictraut
Copy link
Contributor

Pylance doesn't hard-code the definition of "builtins". Rather, it uses the type information from the builtins.pyi stub file from typeshed. You can download your own copy of the typeshed stdlib stubs and use the python.analysis.typeshedPaths setting to point to their path. You can then modify your local copy of builtins.pyi file and add additional symbols.

@bschnurr bschnurr added enhancement New feature or request typestub Issue relating to our bundled type stubs labels Nov 23, 2021
@github-actions github-actions bot removed the triage label Nov 23, 2021
@erictraut
Copy link
Contributor

We've received this request from a number of users, so I've implemented a less-cumbersome way to extend the builtins namespace. For details, refer to this documentation. This new capability will be included in next week's release of pylance.

@erictraut erictraut added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Feb 3, 2022
@debonte
Copy link
Contributor

debonte commented Feb 10, 2022

This issue has been fixed in version 2022.2.1, which we've just released. You can find the changelog here: CHANGELOG.md

@debonte debonte closed this as completed Feb 10, 2022
@bthorsted
Copy link

bthorsted commented Jun 28, 2022

So, I have a question about using the __builtins__.pyi file. In the example from databricks, the builtins are not functions, but actually entire modules with submodules, classes and functions. How would I go about 'mocking' that structure with the __builtins__.pyi file?

@erictraut
Copy link
Contributor

You should be able to import those other modules in __builtins__.pyi. To make these modules appear as "re-exported", you'll need to use a redundant form of import.

import foo as foo

@bthorsted
Copy link

You should be able to import those other modules in builtins.pyi.

So if the modules are not actually available outside of the databricks runtime, I would need to write a mock up module with the necessary submodules and classes and then import them into the __builtins__.pyi, is that correct?

@erictraut
Copy link
Contributor

Yes, that's correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version typestub Issue relating to our bundled type stubs
Projects
None yet
Development

No branches or pull requests

5 participants