pylance

Variable is not accessed in Pylance

Variable is not accessed in Pylance Question: For some reason, I am receiving an error on VSCode that says the specific variable is not accessed Pylance and each variable says the same thing, Am I missing something simple? full code below: score = 0 def gen1_questions(): q1 = input("Question 1. What is the rarest M&M …

Total answers: 1

Pylance reports incorrect error for openpyxl

Pylance reports incorrect error for openpyxl Question: I’m using VSCode for python and am getting a typing error with Pylance that appears incorrect and is not reported as an error by mypy –strict. from openpyxl import load_workbook wb = load_workbook("c:/temp/file.xlsx") ws = wb["Sheet1"] x = ws["A1"] Pylance reports "__getitem__" method not defined on type "Chartsheet" …

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

Why does Pydantic evaluate Optional values after or as None?

Why does Pydantic evaluate Optional values after or as None? Question: I have a method which returns an instance of a class depending on a user’s successful authentication. account: Optional[Account] = await Account.authenticate(email, password) return account or account.dict() From my understanding, since None type is Falsey any occurance of account after the or keyword should …

Total answers: 1

typing recursive function with nested type

typing recursive function with nested type Question: background: solving some algorithm problem Problem I’m trying to use a recursive function with nested type in VSCode, and it keep throwing error to me. I reduced it to this from typing import Type NestedStr = list[str | Type["NestedStr"]] def get_first(x: str | NestedStr) -> str: if isinstance(x, …

Total answers: 2

Python annotate type as regex pattern

Python annotate type as regex pattern Question: I have a dictionary annotation class OrderDict(TypedDict): name: str price: float time: str The value of time: will always be formatted like 2022-01-01 00:00:00, or "%Y-%m-%d %H:%M:%S". I’d like a way to express this in the type annotation Something like class OrderDict(TypedDict): name: str price: float time: Pattern["%Y-%m-%d …

Total answers: 2

Phython: missing-function-docstring (pylance)

Phython: missing-function-docstring (pylance) Question: Im getting the message from pylace at my function. What to do? def retangulo(larg, comp): area = larg * comp print(f’A área de um terreno {larg} x {comp} é {area}.’) docstringpylint(missing-function-docstring) I am expecting to understand how to write python the "right way". Asked By: Renan Soares || Source Answers: … …

Total answers: 1

Expressing semantic content of tuple values in type annotations

Expressing semantic content of tuple values in type annotations Question: I’m modeling a financial exchange class Exchange(ABC): @abstractproperty def balances(self) -> Dict[str, Tuple[float, float]]: … The semantic content of .balances return type is a dict that is {asset: (quantity, proportion), …} e.g. {"BTC": (0.0015, .30), "ETH": (0.10, .20), "LTC": (5, .50)} The problem is that …

Total answers: 1

Using VisualStudio+ Python — how to handle "overriding stdlib module" Pylance(reportShadowedImports) warning?

Using VisualStudio+ Python — how to handle "overriding stdlib module" Pylance(reportShadowedImports) warning? Question: When running ipynbs in VS Code, I’ve started noticing Pylance warnings on standard library imports. I am using a conda virtual environment, and I believe the warning is related to that. An example using the glob library reads: "envLibglob.py" is overriding the …

Total answers: 2

Pylance violating the Commutative Law with Union type ordering

Pylance violating the Commutative Law with Union type ordering Question: I have an interface specifying a position member. Because I want it to be agnostic to whether the member is implemented as a @property or a direct attribute, I annotate the type as a Union of the two class Moveable(Protocol): position: property or Tuple[int, int] …

Total answers: 1