Skip to content

Commit

Permalink
fix: py39 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
z3z1ma committed Apr 7, 2024
1 parent bcb931e commit b0312db
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/cdf/core/feature_flag/harness.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Harness feature flag provider."""

from __future__ import annotations

import asyncio
import logging
import os
Expand Down
2 changes: 2 additions & 0 deletions src/cdf/core/logger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Logger for CDF"""

from __future__ import annotations

import contextlib
import logging
import typing as t
Expand Down
2 changes: 2 additions & 0 deletions src/cdf/core/specification/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Base specification classes for continuous data framework components"""

from __future__ import annotations

import ast
import importlib
import inspect
Expand Down
28 changes: 21 additions & 7 deletions src/cdf/types/monads.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
U = t.TypeVar("U") # The transformed type of the value inside the Monad
K = t.TypeVar("K") # A known type that is not necessarily the same as T
L = t.TypeVar("L") # A known type that is not necessarily the same as U
E = t.TypeVar("E", bound=BaseException, covariant=True) # The type of the error inside the Result
E = t.TypeVar(
"E", bound=BaseException, covariant=True
) # The type of the error inside the Result
P = t.ParamSpec("P")

TState = t.TypeVar("TState") # The type of the state
Expand Down Expand Up @@ -269,7 +271,9 @@ def to_parts(self) -> t.Tuple[T, E | None]:
pass

@classmethod
def lift(cls, func: t.Callable[[U], K]) -> t.Callable[["U | Result[U, Exception]"], "Result[K, Exception]"]:
def lift(
cls, func: t.Callable[[U], K]
) -> t.Callable[["U | Result[U, Exception]"], "Result[K, Exception]"]:
"""Transforms a function to work with arguments and output wrapped in Result monads.
Args:
Expand Down Expand Up @@ -304,7 +308,9 @@ def filter(self, predicate: t.Callable[[T], bool]) -> "Result[T, E]": ...

def __call__(self, func: t.Callable[[T], "Result[U, E]"]) -> "Result[U, E]": ...

def __rshift__(self, func: t.Callable[[T], "Result[U, E]"]) -> "Result[U, E]": ...
def __rshift__(
self, func: t.Callable[[T], "Result[U, E]"]
) -> "Result[U, E]": ...

def __iter__(self) -> t.Iterator[T]:
"""Allows safely unwrapping the value of the Result using a for construct."""
Expand Down Expand Up @@ -656,7 +662,9 @@ async def _fut():
return cls(_fut)

@classmethod
def lift(cls, func: t.Callable[[U], T]) -> t.Callable[["U | Promise[U]"], "Promise[T]"]:
def lift(
cls, func: t.Callable[[U], T]
) -> t.Callable[["U | Promise[U]"], "Promise[T]"]:
"""
Lifts a synchronous function to work within the Promise context,
making it return a Promise of the result and allowing it to be used
Expand Down Expand Up @@ -834,10 +842,14 @@ def new_run_state(s: S) -> t.Tuple[A, S]:
return State(new_run_state)

def unwrap(self) -> A:
raise NotImplementedError("State cannot be directly unwrapped without providing an initial state.")
raise NotImplementedError(
"State cannot be directly unwrapped without providing an initial state."
)

def unwrap_or(self, default: B) -> t.Union[A, B]:
raise NotImplementedError("State cannot directly return a value without an initial state.")
raise NotImplementedError(
"State cannot directly return a value without an initial state."
)

def __hash__(self) -> int:
return id(self.run_state)
Expand All @@ -853,7 +865,9 @@ def __repr__(self) -> str:
return f"State({self.run_state})"

@classmethod
def lift(cls, func: t.Callable[[U], A]) -> t.Callable[["U | State[S, U]"], "State[S, A]"]:
def lift(
cls, func: t.Callable[[U], A]
) -> t.Callable[["U | State[S, U]"], "State[S, A]"]:
"""Lifts a function to work within the State monad.
Args:
func: A function to lift.
Expand Down

0 comments on commit b0312db

Please sign in to comment.