Remove conditional behavior of Future.pure

It was not wrapping awaitable values in a new awaitable, which is
incorrect and confusing behavior.
This commit is contained in:
Correl Roush 2019-01-04 11:44:38 -05:00
parent a340cfea68
commit e623ba0571
2 changed files with 4 additions and 18 deletions

View file

@ -17,15 +17,11 @@ class Future(Monad[T]):
self.awaitable = awaitable
@classmethod
def pure(cls, value: Union[T, Awaitable[T]]) -> Future[T]:
if isinstance(value, Awaitable):
return Future(value)
else:
def pure(cls, value: T) -> Future[T]:
async def identity(x: T) -> T:
return x
async def identity(x: T) -> T:
return x
return Future(identity(value))
return Future(identity(value))
def map(self, function: Callable[[T], S]) -> Future[S]:
async def map(f: Callable[[T], S], x: Awaitable[T]) -> S:

View file

@ -28,16 +28,6 @@ async def test_types() -> None:
await sequence
@pytest.mark.asyncio
async def test_pure_accepts_values_or_awaitables() -> None:
async def three() -> int:
return 3
a: Future[int] = Future.pure(3)
b: Future[int] = Future.pure(three())
assert await a == await b
@pytest.mark.asyncio
async def test_functor_identity() -> None:
identity: Callable[[int], int] = lambda x: x