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

Can anyone tell me what the following [Pyright reportGeneralTypeIssues] error means, because when I run the program it runs normally

Can anyone tell me what the following [Pyright reportGeneralTypeIssues] error means, because when I run the program it runs normally... import pandas as pd obj = pd.Series([4, 7, -5, 3]) obj.index = ['Bob', 'Steve', 'Jeff', 'Ryan'] [Pyright…
n30vIM
  • 1
  • 2
0
votes
1 answer

pyright not autocompleting dlib for python

Specs: Mac M1 Pro Dlib installed with conda (also tried pip3 and it gave the same results) Vscode and coc.nvim using pyright (both using the same language server) python 3.9.12 import dlib dlib.get_frontal_face_detector() Currently, when I run…
0
votes
0 answers

When type hinting python functions, why are `*args` and `**kwargs` trearted differently?

I'm learning my way around type hints in modern python, specifically how to express the type of functions and their parameters. If I have a function f and I know nothing about it, I can write its type as Callable (or equivalently, Callable[...,…
0
votes
1 answer

How to install pyright on ubuntu 20.04?

I want to install pyright on my ubuntu. To do this, I first installed npm (the most recent version): npm install -g npm@latest But when I install a pyright, I get these errors: /home/user/.npm-global/bin/pyright-langserver ->…
Iv Iv
  • 13
  • 4
0
votes
0 answers

Overloaded functions with overlapping typehints in signature results in error for mypy, but not pyright

Take the following example of code: from typing import Literal, overload, Tuple SpecificStrings = Literal['bacon', 'eggs'] @overload def my_func(foo: SpecificStrings) -> float: ... @overload def my_func(foo: str) -> bool: ... def…
sytech
  • 29,298
  • 3
  • 45
  • 86
0
votes
0 answers

Pyright to provide "key" suggestions for custom class implementing typing.Mapping

When writing a simple python program like the following, pyright can detect that I have the keys 1, 2, 3 in my map, as well as 10, 11 which were added afterwards using the [ ] notation. Can I achieve the same sort of inference for a custom type,…
bergercookie
  • 2,542
  • 1
  • 30
  • 38
0
votes
0 answers

Why is a Python generic type alias invalid for this type-checking function?

I have a Python function used as a runtime check that ensures an object is an instance of at least one class in a tuple. It works and my type-checker (pyright) correctly infers the return type from the arguments: from typing import Union, Type,…
Sean Mackesey
  • 10,701
  • 11
  • 40
  • 66
0
votes
0 answers

VScode does not find module norm in scipy stats

The scipy.stats have a module called norm but VScode does not seem to find it. . I am aware of this very similar question, but I am no able to solve my problem based on the answer givin there. Scipy is installed in a Conda environment. Using…
Havsula
  • 43
  • 1
  • 9
0
votes
1 answer

How to convert between 2 type aliases in python?

I am trying to do the following in python: import typing TypeA = str TypeB = typing.Union[typing.List[str], typing.List[int], int, str] TypeC = typing.Dict[str, TypeB] def funcA(arg1: TypeC): var1: typing.List[TypeA] = arg1["random_key"] #…
In78
  • 440
  • 4
  • 17
0
votes
0 answers

Why can't Pyright resolve this module properly?

I'm using a library that is installed in /opt/confd/src/confd/pyapi/. My $PYTHONPATH is set to /opt/confd/src/confd/pyapi. The output of python -c 'import sys; print(sys.path)' is ['', '/opt/confd/src/confd/pyapi', '/usr/lib/python39.zip',…
nullromo
  • 2,165
  • 2
  • 18
  • 39
0
votes
2 answers

How to avoid type checker warnings due to default values set in __init__?

In my app there are many cases of classes that essentially behave like this: class A: def __init__(self) -> None: self.subject = None def set_subject(self, subject: SpecificClass) -> None: self.subject = subject def…
0
votes
0 answers

Typing an optional named argument in overriden method in derived class

At runtime, the following code is perfectly valid: class Base(): @abstractmethod def get(self, arg: str, **kwargs: Any): pass class Derived(Base): def get(self, arg: str, optional_arg: bool = False, **kwargs: Any): …
stav
  • 1,497
  • 2
  • 15
  • 40
0
votes
0 answers

How to run code type-checked python code using Pyright?

I have installed Pyright for type-checking my Python code, but I am not sure how to run it. For example, this is the code I have def add(x: int, y: int): return x + y print(add(10, 20)) When I try to run it with python, python typed.py, it…
John Winston
  • 1,260
  • 15
  • 30
0
votes
1 answer

pyright: Using TypeVar in homogeneous List with min/max

I try to understand how to use TypeVar with pyright. I've built the following small function: import random from typing import List, Sequence, TypeVar T = TypeVar("T", int, str, float) TypedList = List[T] def merge(a: TypedList, b: TypedList) ->…
Yam Mesicka
  • 6,243
  • 7
  • 45
  • 64
0
votes
1 answer

Filter method is behaving unexpectedly

I'm trying to introduce type hints into an existing codebase, but I'm running into an issue when I attempt to type my query. from sqlalchemy.orm.query import Query class DbContext: def __init__(self, db_host, db_port, db_name, db_user,…
Mister Epic
  • 16,295
  • 13
  • 76
  • 147
1 2 3
10
11