-
-
Notifications
You must be signed in to change notification settings - Fork 491
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
Make lazy_import more friendly to pyflakes and other static checkers #30647
Comments
This comment has been minimized.
This comment has been minimized.
comment:2
|
comment:3
Note that the patchbot "pyflakes plugin" knows about lazy imports. BUT only with a basic syntax, one-liners. |
comment:4
Ah, OK, found it at https://github.com/sagemath/sage-patchbot/blob/master/sage_patchbot/plugins.py#L283 |
comment:5
Replying to @tobiasdiez:
Thanks for the pointer! Given that lazy imports are so widely used in sage, we probably don't want to use this workaround unless really necessary. It would add a lot of clutter to lots of files |
comment:6
A simple solution would be to make
Of course, we could as well just use
|
comment:7
Expanding on this, we could introduce a method
|
comment:8
I think this will not be sufficient for the static typing analysis. You would need to provide the information that Maybe one could declare it as |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
Commit: |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:13
Here's something that seems to work. |
Author: Matthias Koeppe |
comment:14
Replying to @tobiasdiez:
In the current version, I suppose one could just use a typed assignment |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
comment:18
I was hoping for a syntax such as |
Dependencies: #30616 |
comment:20
Could you please document the |
comment:21
Replying to @mkoeppe:
What do you mean with typed assignment?
static type checkers can check if
|
comment:23
Another option would be to introduce (global) booleans that indicate whether a given library is available. E.g.
Yet another solution would be the following pattern:
suggested in python/mypy#1297 (comment). |
comment:24
Replying to @jhpalmieri:
This has now happened in #30587. |
comment:25
Replying to @mkoeppe:
This was previously discussed in #22752 |
comment:26
Another solution is to provide type stub files ( |
pyflakes
does not know aboutlazy_import
and may therefore emit distracting warnings - as noted in #30616 comment:8We introduce a new method
PythonModule.lazy_import
, which enables the following new idiom for creating lazy imports that are visible to static checkers:See also:
LazyImport
implementation based onlazy_object_proxy
Depends on #30616
CC: @dcoudert @tobiasdiez @fchapoton @jhpalmieri @tscrim
Component: refactoring
Author: Matthias Koeppe
Branch/Commit: u/mkoeppe/make_lazy_import_more_friendly_to_pyflakes_and_other_static_checkers @
9b19c7a
Issue created by migration from https://trac.sagemath.org/ticket/30647
The text was updated successfully, but these errors were encountered: