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
0
votes
0 answers

Python typevar signature for function that extracts objects of a specific type from a nested dictionary

I have some data organized into the following structure: T = TypeVar("T") my_data: Dict[type[T], Dict[str, List[T]]] = dict() Thus, given a type T, this dictionary will return another dictionary that is keyed by a string identifier, mapping to a…
Vranvs
  • 1,411
  • 4
  • 17
  • 38
0
votes
1 answer

Pyright highlighting perfectly working astropy code as if it were incorrect

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…
0
votes
0 answers

Why pyright doesn't allow str.join of a non-literal set?

The following code produces the error message: Operator "|" not supported for types "set[str]" and "set[str]" ......   Operator "|" not supported for types "set[str]" and "set[str]" when expected type is "Iterable[LiteralString]" def…
Yam Mesicka
  • 6,243
  • 7
  • 45
  • 64
0
votes
0 answers

pyright linter error with overloads -- perhaps missing some cases?

I write some code with overloads (pared down to illustrate the problem): from __future__ import annotations from typing import overload class Unit: @overload def __mul__(self, other: Unit) -> Unit: ... @overload def…
DanielSank
  • 3,303
  • 3
  • 24
  • 42
0
votes
3 answers

Pyright can't see Poetry dependencies

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…
0
votes
0 answers

Resolve "Return type, "list[Unknown]", is partially unknown" type-checking diagnostic in Pylance?

am using a custom JSONEncoder to write a data structure containing sets: class EnhancedJSONEncoder(json.JSONEncoder): def default(self, o: Any): if isinstance(o, set): return list(o) return super().default(o) This…
0
votes
0 answers

False error from pyright whe using dictionaries

I'm using nvim with pyright and I get this error, but it is not incorrect, does anybody knows how to fix it?
0
votes
1 answer

How to fix lsp-pyright type hint errors; "int" is incompatible with "float"?

Using this python example snippet below, I'm getting the error at the bottom from typing import List def foo(x:List[float]): pass i=[3] foo(i) . [Pyright] Argument of type "list[int]" cannot be assigned to parameter "x" of type "List[float]"…
jjk
  • 592
  • 1
  • 6
  • 23
0
votes
1 answer

Is there a way to disable coc-pyright type annotations in vim?

I use Vim 9.0.105 and python3.9.5 and I'm on WSL2 with Ubuntu20.04 Like I say in the Title, I have an issue with coc-pyright which when I write variables coc-pyright automatically "write" the type annotation. Here is a little example The problem is…
Cbr
  • 3
  • 1
0
votes
2 answers

Ignoring a specific undefined variable with pyright

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…
Xaraxia
  • 199
  • 9
0
votes
2 answers

Pyright shows an error when converting column(int) to int

I can not assign a variable without adding # type:ignore || Used for pyright (Autocomplete) or it giving me an error. Error: [Pyright reportGeneralTypeIssues] [E] Argument of type "Column" cannot be assigned to parameter "id" of type "int" in…
MiguelCiulog
  • 13
  • 2
  • 5
0
votes
1 answer

Cannot access member for type tuple[Any, ...] using Pandas DataFrame itertuples (Pyright-langserver with Neovim 0.7)

I'm using the pyright-langserver with Neovim v0.7.0. It functions well, except I don't know how to correctly annotate the types in the following situation. import pandas as pd df = pd.DataFrame({'num_legs': [4, 2], 'num_wings': [0,…
Nick Reid
  • 91
  • 3
0
votes
2 answers

pyright giving out errors on self.rect when a class inherits from pygame.sprite.Sprite

I have a simple Entity class which inherits from pygame.sprite.Sprite like so: import pygame class Entity(pygame.sprite.Sprite): def __init__( self, pos: tuple[int, int], size: tuple[int, int], color: str, …
donut321
  • 23
  • 3
0
votes
1 answer

How do I set up a container so my emacs-lsp can run a Python IDE with pyright using the python and modules in the container?

I am trying to update old python code using a TensorFlow v1 container (I will eventually port it to either TensorFlow v2 or PyTorch). I have an emacs Python environment already set up and used locally based on LSP, pyright, flycheck, pyvenv and…
0
votes
0 answers

Circular dependency causing type to not be equal to itself?

I have a circular dependency caused by type-hinting analogous to this minimal example: a.py: from comparison import are_equal class A: def __eq__(self, other): if not isinstance(other, A): return NotImplemented …
cymin
  • 83
  • 8