pyright

Pyright with multiple venv (monorepo)

Pyright with multiple venv (monorepo) Question: Got an issue with pyright on a monorepo: it didn’t recognize classes/functions imported from nearby projects/libraries (get a reportMissingImports). For instance, with this repo structure: . ├── library |   └── src |    └── __init__.py ├── project1 |   └── src |   └── main.py ├── project2 … └── pyproject.toml This …

Total answers: 1

Achieving single-responsibility principle with python abstract classes

Achieving single-responsibility principle with python abstract classes Question: I want to separate the DB models from the actual classes. But i need two static functions for fetching data from the DB regardless of the subclass type. the implementation for both functions are the same across all DB models. pyright showing an error that cls inside …

Total answers: 1

Pyright highlighting perfectly working astropy code as if it were incorrect

Pyright highlighting perfectly working astropy code as if it were incorrect Question: I was building a simulator for planets’ orbits, and pyright is really helpful for highlighting mistakes automatically, but for some reason it doesn’t understand perfectly working operations with astropy’s units and keeps highlighting it as if they were incorrect. How can I make …

Total answers: 1

Weird scikit-learn Python intellisense error message

Weird scikit-learn Python intellisense error message Question: Lately I was doing some ML stuff with Python using scikit-learn package. I wanted to use make_blobs() function so I began writing code for example: X, y = make_blobs(n_samples=m, centers=2, n_features=2, center_box=(80, 100)) and of course this is fine. However while coding next lines my Intellisense within Visual …

Total answers: 2

Pyright can't see Poetry dependencies

Pyright can't see Poetry dependencies Question: In a poetry project the local dependencies are installed in the ~/.cache/pypoetry/virtualenvs/ folder. Pyright in nvim is complaining that import package lines can’t be resolved. What should I include into pyproject.toml? Or how to show pyright the path to the dependencies? Thanks My pyrightconfig.json looks like this: { "venvPath": …

Total answers: 2

"at" sign (@) in Python type hints (suggested by Pylance / Pyright)

"at" sign (@) in Python type hints (suggested by Pylance / Pyright) Question: The July 2022 release of the Python extension for Visual Studio Code introduced "Inlay Type Hints", which automatically suggests return types of functions that don’t have an explicit annotation. To enable it, you can set "python.analysis.inlayHints.functionReturnTypes": true to your IDE user settings …

Total answers: 1

Python, provide type hints for a mixin that a property exists

Python, provide type hints for a mixin that a property exists Question: For example this mixin: from lib import stringlib class NiceNameMixin: @property def nice_first_name(self): return stringlib.clean_name(self.first_name) @property def nice_last_name(self): return stringlib.clean_name(self.last_name) warns me: Cannot access member "first_name" for type "NiceNameMixin" Member "first_name" is unknown. What is the correct was of telling the type checker …

Total answers: 2

Ignoring a specific undefined variable with pyright

Ignoring a specific undefined variable with pyright Question: When writing custom SaltStack modules/states using VScode and linting with pyright, I get the following error all over the place: "__salt__" is not defined It’s not a killer, because I can put the following on the end of every line that references it: # pyright: ignore[reportUndefinedVariable] But …

Total answers: 2

How do you ignore specific Pyright type checks by project, file, line?

How do you ignore specific Pyright type checks by project, file, line? Question: I cannot quite find clear documentation on how to ignore one or more specific Pyright checks: Using a config file at the root of your project. At the top of a file, function, or method. Each ligne as a trailing comment. Thanks …

Total answers: 1

How to declare a Protocol with a field which supports both a simple type and property?

How to declare a Protocol with a field which supports both a simple type and property? Question: (Related, but not duplicated: How to annotate attribute that can be implemented as property?) I want to create a Protocol, in which a field can be implemented by both a simple type and property. For example: class P(Protocol): …

Total answers: 2