trio has a parameter defaulted to
None
and trio-stubs doesn't have that parameter hinted asOptional
In this context, would the problem be in trio, or in trio-stubs?
defaults
would lose its typing when used in inherited class? This only applies to an attribute with the name defaults
.
=None
and the stubs have : trio.abc.Clock = ...
. seems like it would be good to have some tool or another able to find this discrepancy.
mypy.nodes.TypeInfo
:]
) stubtest.
error: package.f is inconsistent, runtime argument "p" has a default value of type None, which is incompatible with stub argument type builtins.int
Stub: at line 1
def (p: builtins.int =)
Runtime: at line 1 in file /Users/shantanu/tmp/lol/package/__init__.py
def (p=None)
from typing import Union
def foo(X: Union[int, str]) -> bool:
if isinstance(X, str):
reveal_type(X) # str
def g(y: int) -> bool:
reveal_type(X) # Union[int, str]
return len(X) > y # <<<<< error: Argument 1 to "len" has incompatible type "Union[int, str]"; expected "Sized"
return g(10)
reveal_type(X) # int
return bool(X)
Any
. I'm currently running into a snag where I don't know how to deal with a NewType
that I defined - what I'm trying to do results in a mypy error. Please find below a minimal reproduction of the problem. Does anyone have any advice or am I forced to leave it as Any
?# test.py
from dataclasses import dataclass
from typing import NewType
A = NewType("A", str)
@dataclass
class Test:
a: A
# stubgen'd test.pyi
from typing import Any
A: Any
class Test:
a: A
def __init__(self, a: Any) -> None: ...
# trying to remove 'Any' as much as possible
from typing import Type
A: Type[str]
class Test:
a: A # mypy error: "test.A" is not valid as a type
def __init__(self, a: A) -> None: ... # mypy error: "test.A" is not valid as a type