Questions tagged [pyright]

Pyright is a static type checker for Python, developed by Microsoft and implemented in TypeScript. It supports PEP 484, PEP 526, PEP 544 and has smart type inference.

Pyright is a static type checker for Python, developed by Microsoft and implemented in TypeScript. It supports PEP 484, PEP 526, PEP 544 and has smart type inference. It supports the Language Server Protocol and is available in a Visual Studio Code plugin.

154 questions
1
vote
1 answer

Configure Pyright to use Ruff as a linter

I use Zed editor with Pyright and it works like a charm. However I want to use Ruff linter with Pyright but I don't find any documentation about how to achieve this for Zed editor. Do I have to specify linter directly in pyrightconfig.json and if so…
1
vote
0 answers

When MyPy is enabled in VsCode does it go through pyright, or is it a seperate thing on its own?

I'm actually trying to use pyright+mypy in Neovim and so I'm inspecting what is going on in VsCode. I know there is a vscode setting python.linting.mypyEnabled and I'm trying to find out what exactly happens when that is so. Vscode also takes a mypy…
1
vote
1 answer

Why doesn't a read-only Mapping work as a type hint for a Dict attribute in Python?

Why does a read-only Mapping not work as a type hint for a Dict attribute? I know dict is mutable, which makes the field invariant, but could you explain what can go wrong with passing it to a read-only Mapping type? Consider the following…
Lajos
  • 2,549
  • 6
  • 31
  • 38
1
vote
0 answers

How to get pyright to use the current conda environment automatically?

I would like pyright installed by Mason to use the current conds environment, that is the one used when opening neovim. If I put a pyrightconfig.json shown below in root dir of my project, this will work { "venv": "some name", "venvPath":…
H.Li
  • 171
  • 2
  • 12
1
vote
0 answers

Pandas TimeStamp type is not recognized by pyright

I have a segment of code that looks at a pandas' DataFrame column that's a Series of Timestamps and requests the date for the Timestamp. When I run pyright over this code it returns an error saying that it Cannot access the member "date" for type…
1
vote
1 answer

List of single type cannot be assigned to list of union type

I wrote a python code like below class A: pass class B: pass class C: pass from typing import TypeVar, Union, Type, Optional, List test = TypeVar("test", bound=A) def wow(w: Optional[List[Union[Type["test"], Type[C]]]]): …
Planete
  • 45
  • 4
1
vote
1 answer

Python Analysis: Type Checking Mode in VS CODE

I changed the settings "Python Analysis: Type Checking Mode" to strict mode enter image description here And I get an error while checking for an instance of str, def is_name(name: str) -> bool: if isinstance(name, str): return…
1
vote
1 answer

mason lsp pyright seems to be download but dosen't work on vim

I have a problem on my nvim LSP. according to mason plugin the pyright is downloaded and I on other IDE the lsp works great. when i open python file with neovim it didn't recognized import and basic functions. someone can handle this…
Dump Eldor
  • 92
  • 1
  • 11
1
vote
0 answers

How to type hint results of specific function calls with generic return signature

I believe it is easier to ask this question using a concrete example: import matplotlib.pyplot as plt _, ax = plt.subplots() # Pyright: Cannot access member "plot" for type "ndarray[Any, dtype[Any]]"   # Member "plot" is unknown ax.plot([1, 2, 3],…
zap
  • 568
  • 2
  • 13
1
vote
1 answer

How do I use a match statement to pattern match the class of multiple values in python?

I have a union type, and I can create a value for it like so: import random class X: s: str = 'ab' MyType = int | X def get_value() -> MyType: if random.random() > 0.5: return 3 return X() a = get_value() And I can use a…
Zantier
  • 833
  • 1
  • 8
  • 18
1
vote
0 answers

Why pyright config with mason in nvim shows that package is not accessed

The pyright did not run well: Although it completes properly, it cannot find the package location: This is my config for pyright --config python language server lspconfig["pyright"].setup({ capabilities = capabilities, on_attach = on_attach, …
1
vote
0 answers

Why are generic arguments described by `T@function_name` by pyright?

Given the following block of code: import typing as tp T = tp.TypeVar("T") def dummy(item: T) -> T: return item reveal_type(dummy) When run onto it, pyright prints: ❯ pyright type_arobase.py < some output trimmed…
1
vote
2 answers

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

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…
run_the_race
  • 1,344
  • 2
  • 36
  • 62
1
vote
0 answers

Python typing. Function that narrows return type according to input list of types TypeVar(bound=Union[A,B], covariant=True)

Today I've been reading into the Liskov's Substitution Principle and reading various docs/blogs on covariance/contravariance after experiencing the following problem. I want a function which narrows the returned type according to the provided list…
Zachy
  • 88
  • 5
1
vote
0 answers

How to add built-in function (gettext) to pyright?

I have a python project with gettext. And I use gettext.install for adding _ to built-ins, so it works correctly. But my pyright always shows error: _ is not defined. How can I let pyright know this function? My pyrightconfig.json: { "venvPath":…
vilaugra
  • 11
  • 1