-
-
Notifications
You must be signed in to change notification settings - Fork 802
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
Hide deprecated callables from code completion suggestions #2814
Hide deprecated callables from code completion suggestions #2814
Conversation
943cdb9
to
27d3db1
Compare
27d3db1
to
32414d1
Compare
Is this comment related why pylance doesn't work? microsoft/pylance-release#1277 (comment) |
Just tested this and it still does not work for me in VS Code. Seems like pylance does not subset suggestions based on But it's a good point, probably better anyway to declare |
2210942
to
48fd332
Compare
Could you rerun the tests? I think this is a spurious error which already appeared in other PRs and not related to this one. |
I’m not exactly sure if this is what we need, so I leave it open so others can discuss about this PR. Regardless needed, I think it is better to include this as part of the tools/generate schema wrapper, otherwise you’ll need to modify it manually with a new schema. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jakes comment was related to a previous implementation which dynamically fetched the relevant attributes from the module while it was imported. This is no longer relevant in this implementation as |
tools/generate_schema_wrapper.py so far does not touch |
Maybe @ChristopherDavisUCI can think with us a bit here, as he has become quite familiar with the |
Hi @binste, how did you choose the current list for |
Thanks @ChristopherDavisUCI for looking into it! I generated the list with the code I added to tests/test_toplevel.py, i.e.: import altair as alt
[x for x in dir(alt) if not getattr(getattr(alt, x), "_deprecated", False)] |
Thanks! I looked around some more but don't have any alternatives to suggest. I feel like this should be a common issue (wanting to hide a definition from Pylance) but did not find much of anything in my Google searches. (I found lots of examples of people wanting to hide Pylance warning messages.) Is there any issue that we want I asked ChatGPT how to hide these functions, and it said to precede the definitions with the comment @mattijn I'll try to look at #2819 soon, but I don't think I'm going to have anything else to suggest for this PR. |
I tried quickly to create this
|
If I run the script directly from cmd it finds my local altair package in the directory as defined in Now I can run first (using: master...mattijn:altair:generate-init-file): python tools/generate_init_file.py --no-hide-deprecated To initialise the basis python tools/generate_init_file.py --hide-deprecated This creates the But.. the methods/functions that are deprecated are not ignored. For example the import altair as alt
sel_single = getattr(alt, "selection_single")
hasattr(sel_single, '_deprecated')
But calling the function directly, will present the sel_single()
So I was wondering, how can this PR pass CI, while I cannot reproduce it locally. But now I think this test: https://github.com/altair-viz/altair/blob/760bd0fa03546ca61a575cac11204418a5590ae2/tests/test_toplevel.py#L4 is successful because it checks itself, basically dir(alt) == getattr(alt, "__all__") |
Tests currently fail, I'll address this soon. |
I tried this firstly, but in my approach I had to reload the package altair during runtime of the generator, which gave me other problems. Open for alternatives though! |
I opened a PR #2872 to fix the imports in those scripts. After merging this, I think we can update the |
I think I would favour a But after checking I have one concern and one question. After this PR the following items will not appear in the code completion suggestion: __name__
__doc__
__package__
__loader__
__spec__
__path__
__file__
__cached__
__builtins__
__version__
__all__
__dir__
selection_multi
selection_single
list_datasets
load_dataset
datum All good. Except the last one, import altair as alt
getattr(alt.datum, '_deprecated', False)
This import altair as alt
getattr(alt.datum, '__deprecated__', False)
Or modify the And the question that I had is the following, after sorting the list starts with methods that are starting with an upper-case and after this the small-case methods appear in the sorted list. Is this something that we like? I noticed it is the same for the pandas library. |
Addressed your comments, added The attributes which are excluded from [
"__all__",
"__builtins__",
"__cached__",
"__dir__",
"__doc__",
"__file__",
"__loader__",
"__name__",
"__package__",
"__path__",
"__spec__",
"__version__",
"hashlib",
"io",
"itertools",
"json",
"jsonschema",
"list_datasets",
"load_dataset",
"pd",
"pkgutil",
"selection_multi",
"selection_single",
"warnings",
] Regarding the sort order of upper- and lowercase, I don't have a good understanding of what the implications are. Given that both upper- and lowercase objects are relevant for end users ( |
Thanks @binste, I tried to run the |
Closes #2574 (code builds on suggestion of @joelostblom). Concern mentioned [here] is addressed by placing the statements at the end of
__init__.py
so that the module is fully imported.In JupyterLab (and notebook) this works for me:

The deprecated functions themselves are still accessible
Unfortunately, in VS Code the deprecated functions still show up. I didn't find anything online on why Pylance does not respect
__dir__
. Maybe it also has a cache somewhere which I did not manage to clear. But I think it's already great if this is resolved for Jupyter.