Skip to content

Commit 6cbec9b

Browse files
Mark _T and _E type vars as covariant
1 parent 7103664 commit 6cbec9b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

poltergeist/result.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any, Callable, Generic, NoReturn, TypeVar, final, overload
22

3-
_T = TypeVar("_T")
4-
_E = TypeVar("_E", bound=BaseException)
3+
_T = TypeVar("_T", covariant=True)
4+
_E = TypeVar("_E", bound=BaseException, covariant=True)
55
_D = TypeVar("_D")
66

77

tests/mypy/test_result.yml

+17
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
err: Result[str, Exception] = Err(123) # E: Argument 1 to "Err" has incompatible type "int"; expected "Exception" [arg-type]
66
other: Result[str, int] # E: Type argument "int" of "Result" must be a subtype of "BaseException" [type-var]
77
8+
- case: result_generic_covariant
9+
main: |
10+
from abc import ABC, abstractmethod
11+
from typing import Any, Generic, TypeVar
12+
from poltergeist import Err, Result
13+
14+
FooT = TypeVar("FooT", bound=Result[Any, Exception])
15+
16+
class Foo(Generic[FooT], ABC):
17+
@abstractmethod
18+
def run(self) -> FooT:
19+
...
20+
21+
class Bar(Foo[Result[Any, ValueError]]):
22+
def run(self) -> Result[Any, ValueError]:
23+
return Err(ValueError(""))
24+
825
- case: result_err
926
main: |
1027
from poltergeist import Result

0 commit comments

Comments
 (0)