Comments (3)
Pyright (the type checker that underlies pylance) is working as intended here. These symbols are not referenced anywhere in the file. You appear to have enabled the reportUnusedImport
diagnostic error, which is off by default. When you enable this check, pyright will report an error if your file includes an imported symbol that is not used anywhere within the module and is not re-exported to other modules. In your case, I suspect you intend for these symbols to be re-exported to other modules. By default, symbols imported into a module are assumed to be private (internal) to that module. If you intend to re-export them to other modules, you need to use one of the techniques documented here. You can either include them in an __all__
or use a redundant form of import (for example, from x import y as y
). This convention was established in PEP 484 for stub files, but the typing community has since adopted it for ".py" files as well.
If you don't want pyright to generate an error for unreferenced imports, you can choose to disable the reportUnusedImport
in your project or on a per-file basis using a # pyright: reportUnusedImport=false
at the top of the file.
from pylance-release.
@erictraut, thank you very much for your answer. Yes, you are right: they are not referenced in the file.
However, this file __init__.py
means that this is a package, which later will be used by other modules. In my case, I am writing
from spark_framework import *
from other parts of the code, and due to this import of functions that is surrounded by red rectangle on my screenshot, they are imported fine.
However, it looks like Pylance doesn't recognize it to be in the __init__.py
and doesn't get the real intention.
from pylance-release.
However, this file
__init__.py
means that this is a package, which later will be used by other modules.
As Eric mentioned above, if you want to re-export these symbols from this module (and you want a static type checker to understand that that is your intention) you'll either need to include them in an __all__
or use a redundant import form (from x import y as y
).
I've copied that part of his response here:
By default, symbols imported into a module are assumed to be private (internal) to that module. If you intend to re-export them to other modules, you need to use one of the techniques documented here. You can either include them in an
__all__
or use a redundant form of import (for example,from x import y as y
). This convention was established in PEP 484 for stub files, but the typing community has since adopted it for ".py" files as well.
from pylance-release.
Related Issues (20)
- Consecutive comment lines are not foldable in Python but are in (at least some) other languages HOT 1
- Pylance makes type hints in Python unusable for me HOT 14
- `"python.analysis.autoImportCompletions": false` not working. HOT 1
- Syntax highlighting issue for a valid conditional logic when type hints provided HOT 3
- PyLance crashes when setting node option '--no-deprecation' HOT 24
- My VSCode keep freezing because of Pylance HOT 1
- pylance bug HOT 1
- F2 renaming not working across all python files HOT 2
- Better string completions HOT 1
- import side by side in standalone file didn't work HOT 1
- Problema com desempenho HOT 1
- wtegt HOT 1
- wtegt HOT 1
- wtegt HOT 1
- "Not a known attribute" error HOT 12
- pylance crashing all the time HOT 1
- Pylance Performance Issue HOT 1
- pylance crash: Allocation failed - JavaScript heap out of memory HOT 16
- report HOT 2
- issue HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pylance-release.