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
6
votes
1 answer

Pyright is not finding imports from libraries in a virtualenv

pyright reports both missing imports (could not be resolved) and general type errors (unknown import symbol). These libraries all exist -- I can run the code in ipython without errors. I'm using poetry to manage my virtual environment. My venv is…
meangrape
  • 317
  • 2
  • 11
6
votes
1 answer

how to tell a python type checker that an optional definitely exists?

I'm used to typescript, in which one can use a ! to tell the type-checker to assume a value won't be null. Is there something analogous when using type annotations in python? A (contrived) example: When executing the expression m.maybe_num + 3 in…
brahn
  • 12,096
  • 11
  • 39
  • 49
6
votes
1 answer

Neovim built-in LSP shows No code actions available for Python files

When I open a python file, diagnostics seem to be working fine. Then I navigate to a line with a diagnostic error, press the shortcut to invoke code actions ('ca' in my case) and I get a message 'No code actions available'. I have tried…
5
votes
1 answer

Usage of nested protocol (member of protocol is also a protocol)

Consider a Python protocol attribute which is also annotated with a protocol. I found in that case, both mypy and Pyright report an error even when my custom datatype follows the nested protocol. For example in the code below Outer follows the…
orematasaburo
  • 1,207
  • 10
  • 20
5
votes
1 answer

Typing decorators that can be used with or without arguments

I have a decorator that can be called either without or with arguments (all strings): @decorator def fct0(a: int, b: int) -> int: return a * b @decorator("foo", "bar") # any number of arguments def fct1(a: int, b: int) -> int: return a *…
rogdham
  • 193
  • 8
5
votes
2 answers

Using modern typing features on older versions of Python

So, I was writing an event emitter class using Python. Code currently looks like this: from typing import Callable, Generic, ParamSpec P = ParamSpec('P') class Event(Generic[P]): def __init__(self): ... def addHandler(self, action :…
ISD
  • 984
  • 1
  • 6
  • 21
5
votes
1 answer

Python typing: do stubs take precedence over library sources?

I'm splitting my code into multiple packages, which are installable via PyPI. Then these packages are used in a child package, where I want type information from "library" packages to be fully used. In order to have complete type checking, I'd like…
Boschie
  • 467
  • 3
  • 13
5
votes
0 answers

How to use coc-pyright with python environment in container?

I want to use python environment in docker container, alongside editing source files on the host machine. I know VSCode provides devcontainer feature, but I want to use VIM and coc-pyright. How to do that?
tamuhey
  • 2,904
  • 3
  • 21
  • 50
4
votes
1 answer

More elegant way to switch tqdm progress bars without LSP Pyright error

I'm creating a custom Python CLI module using docx2pdf. The docx2pdf module is using tqdm to display progress bars while the .docx files are being converted to .pdf. In my module I'm using the CLI log parameter to enable/disable console logging…
4
votes
2 answers

Weird scikit-learn Python intellisense error message

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…
4
votes
1 answer

Neovim LSP: pyright server does not dynamically regognize changes in sub folders

I setup Neovim LSP using the nvim-lspconfig and the lsp-installer where I also installed the pyright server. Without any further configuration it worked out of the box. However when I have a class in a subfolder and add a new method, pyright does…
goTAN
  • 587
  • 1
  • 7
  • 15
4
votes
1 answer

Overriding type hint for an attribute of a class from 3rd party library

I have a 3rd-party web-framework which has type hints in some of its code. I can not control the code of the said framework Suppose I have following piece from framework import web ... class UserPosts(web.WebView): async def get(self): …
S.S.J
  • 353
  • 1
  • 7
4
votes
0 answers

Fix Pyright error: Operator "in" not supported for types "Literal['Dispatch__'] and "_T@filter"

I have a line of code that keeps getting flagged by Pyright and I'm not sure how I would rewrite this line of code: dispatch_vars = list(filter(lambda x: "Dispatch__" in x, df.columns)) And Pyright says: [Pyright] Operator "in" not supported for…
dylanjm
  • 2,011
  • 9
  • 21
4
votes
1 answer

How to show and ignore Pyright error codes

I am using pyright type checker and need to suppress warnings where e.g. numpy type stubs are insufficient to infer correct types. This can be accomplished with #type: ignore comment. However, I'd like any other issue to still be highlighted on the…
Boschie
  • 467
  • 3
  • 13
4
votes
0 answers

Neovim LSP: language servers not found

I'm trying to set up neovim's new LSP. Following the manual I downloaded the plugin lspconfig, the pyright and typescript language servers, and sourced the setups in my init.vim, like so: local nvim_lsp =…
barmanthewise
  • 359
  • 4
  • 10
1
2
3
10 11