Skip to content

Commit

Permalink
Adopt PEP 563 postponed annotation evaluation (rustedpy#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
wbolster committed Dec 21, 2021
1 parent cc72072 commit 4867794
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/result/result.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import Callable, Generic, TypeVar, Union, Any, cast, overload, NoReturn
from __future__ import annotations

from typing import Any, Callable, Generic, NoReturn, TypeVar, Union, cast, overload

T = TypeVar("T", covariant=True) # Success type
E = TypeVar("E", covariant=True) # Error type
Expand Down Expand Up @@ -99,7 +101,7 @@ def unwrap_or_else(self, op: Callable[[E], T]) -> T:
"""
return self._value

def map(self, op: Callable[[T], U]) -> 'Result[U, E]':
def map(self, op: Callable[[T], U]) -> Result[U, E]:
"""
The contained result is `Ok`, so return `Ok` with original value mapped to
a new value using the passed in function.
Expand All @@ -124,7 +126,7 @@ def map_or_else(
"""
return op(self._value)

def map_err(self, op: Callable[[E], F]) -> 'Result[T, F]':
def map_err(self, op: Callable[[E], F]) -> Result[T, F]:
"""
The contained result is `Ok`, so return `Ok` with the original value
"""
Expand Down Expand Up @@ -216,7 +218,7 @@ def unwrap_or_else(self, op: Callable[[E], T]) -> T:
"""
return op(self._value)

def map(self, op: Callable[[T], U]) -> 'Result[U, E]':
def map(self, op: Callable[[T], U]) -> Result[U, E]:
"""
Return `Err` with the same value
"""
Expand All @@ -238,7 +240,7 @@ def map_or_else(
"""
return default_op()

def map_err(self, op: Callable[[E], F]) -> 'Result[T, F]':
def map_err(self, op: Callable[[E], F]) -> Result[T, F]:
"""
The contained result is `Err`, so return `Err` with original error mapped to
a new value using the passed in function.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_pattern_matching.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from result import Err, Ok, Result


Expand Down
2 changes: 2 additions & 0 deletions tests/test_result.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from result import Err, Ok, OkErr, Result, UnwrapError
Expand Down

0 comments on commit 4867794

Please sign in to comment.