Category : mypy

I’m making a class that implements the MutableSequence contract and am having trouble type-hinting the getters & setters which take either a slice or a SupportsIndex instance as the index argument. In my application I have a _normalise_index function which turns negative relative indices and slices into positive ones by subtracting from len – e.g. ..

Read more

I have a python class that looks as following: import numpy as np from typing import Union, Sequence, Literal class TestClass(): def test(self, a: np.ndarray, b: np.ndarray): return a.reshape(b, order = ‘F’) Evaluating this module with mypy returns the error No overload variant of "reshape" of "_ArrayOrScalarCommon" matches argument types "ndarray", "str" According to the ..

Read more

I have a class that looks as following: import numpy as np from typing import Union, Sequence class TestClass(): def __init__(self, a: Union[Sequence[float], np.ndarray]): self.a = a @property def a(self) -> np.ndarray: return self._a @a.setter def a(self, a: Union[Sequence[float], np.ndarray]): self._a = np.array(a) Using mypy to evaluate this returns the error Incompatible types in assignment ..

Read more

I’m currently working on an API wrapper that will support asynchronous as well. So I decided to create an asynchronous Client by inheriting from an asynchronous regular Client. # Test import requests import aiohttp class Client: def request(self, url: str) -> requests.Response: … class AsyncClient(Client): def request(self, url: str) -> aiohttp.ClientResponse: … Then, the mypy ..

Read more