Skip to content

Commit

Permalink
Mark _T and _E type vars as covariant
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandermalyga committed Apr 21, 2024
1 parent 7103664 commit 6cbec9b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions poltergeist/result.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Callable, Generic, NoReturn, TypeVar, final, overload

_T = TypeVar("_T")
_E = TypeVar("_E", bound=BaseException)
_T = TypeVar("_T", covariant=True)
_E = TypeVar("_E", bound=BaseException, covariant=True)
_D = TypeVar("_D")


Expand Down
17 changes: 17 additions & 0 deletions tests/mypy/test_result.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@
err: Result[str, Exception] = Err(123) # E: Argument 1 to "Err" has incompatible type "int"; expected "Exception" [arg-type]
other: Result[str, int] # E: Type argument "int" of "Result" must be a subtype of "BaseException" [type-var]
- case: result_generic_covariant
main: |
from abc import ABC, abstractmethod
from typing import Any, Generic, TypeVar
from poltergeist import Err, Result
FooT = TypeVar("FooT", bound=Result[Any, Exception])
class Foo(Generic[FooT], ABC):
@abstractmethod
def run(self) -> FooT:
...
class Bar(Foo[Result[Any, ValueError]]):
def run(self) -> Result[Any, ValueError]:
return Err(ValueError(""))
- case: result_err
main: |
from poltergeist import Result
Expand Down

0 comments on commit 6cbec9b

Please sign in to comment.