Skip to content

Commit

Permalink
revert newer black formatting (added in part of wip commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpmcginty committed Jan 6, 2025
1 parent 17dbeb8 commit 15460cc
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 46 deletions.
21 changes: 14 additions & 7 deletions src/aibs_informatics_core/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,31 +253,38 @@ def get_name(self, env_base: EnvBase) -> str:


@overload
def get_env_base() -> EnvBase: ...
def get_env_base() -> EnvBase:
...


@overload
def get_env_base(env_base: Union[str, EnvBase]) -> EnvBase: ...
def get_env_base(env_base: Union[str, EnvBase]) -> EnvBase:
...


@overload
def get_env_base(env_base: Literal[None]) -> EnvBase: ...
def get_env_base(env_base: Literal[None]) -> EnvBase:
...


@overload
def get_env_base(env_base: Literal[None], env_base_class: Literal[None]) -> EnvBase: ...
def get_env_base(env_base: Literal[None], env_base_class: Literal[None]) -> EnvBase:
...


@overload
def get_env_base(env_base: Literal[None], env_base_class: Type[E]) -> E: ...
def get_env_base(env_base: Literal[None], env_base_class: Type[E]) -> E:
...


@overload
def get_env_base(env_base: Union[str, E], env_base_class: Type[E]) -> E: ...
def get_env_base(env_base: Union[str, E], env_base_class: Type[E]) -> E:
...


@overload
def get_env_base(env_base: Union[str, E], env_base_class: Literal[None]) -> EnvBase: ...
def get_env_base(env_base: Union[str, E], env_base_class: Literal[None]) -> EnvBase:
...


def get_env_base(
Expand Down
20 changes: 12 additions & 8 deletions src/aibs_informatics_core/models/api/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,29 +323,32 @@ def route_method(self: ApiClientInterface, request: API_REQUEST) -> API_RESPONSE
class ApiClientInterface(Protocol):
def call(
self, route: ApiRoute[API_REQUEST, API_RESPONSE], request: API_REQUEST
) -> API_RESPONSE: ... # pragma: no cover
) -> API_RESPONSE:
... # pragma: no cover


# Solution for adding class methods to client class with named arguments
# https://github.com/python/typing/discussions/1040
class BoundClientRouteMethod(Protocol, Generic[API_REQUEST, API_RESPONSE]): # type: ignore
def __call__(self, request: API_REQUEST) -> API_RESPONSE: ... # pragma: no cover
def __call__(self, request: API_REQUEST) -> API_RESPONSE:
... # pragma: no cover


class ClientRouteMethod(Protocol, Generic[API_REQUEST, API_RESPONSE]): # type: ignore
def __call__(
__self, self: ApiClientInterface, request: API_REQUEST
) -> API_RESPONSE: ... # pragma: no cover
def __call__(__self, self: ApiClientInterface, request: API_REQUEST) -> API_RESPONSE:
... # pragma: no cover

@overload
def __get__(
self, obj: ApiClientInterface, objtype: Optional[Type[ApiClientInterface]] = None
) -> BoundClientRouteMethod[API_REQUEST, API_RESPONSE]: ... # pragma: no cover
) -> BoundClientRouteMethod[API_REQUEST, API_RESPONSE]:
... # pragma: no cover

@overload
def __get__( # type: ignore[misc]
self, obj: None, objtype: Optional[Type[ApiClientInterface]] = None
) -> ClientRouteMethod[API_REQUEST, API_RESPONSE]: ... # pragma: no cover
) -> ClientRouteMethod[API_REQUEST, API_RESPONSE]:
... # pragma: no cover

def __get__(
self,
Expand All @@ -354,4 +357,5 @@ def __get__(
) -> Union[
BoundClientRouteMethod[API_REQUEST, API_RESPONSE],
ClientRouteMethod[API_REQUEST, API_RESPONSE],
]: ... # pragma: no cover
]:
... # pragma: no cover
9 changes: 6 additions & 3 deletions src/aibs_informatics_core/models/base/field_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ def custom_field(
mm_field: Optional[mm.fields.Field] = None,
encoder: Optional[EncoderType] = None,
decoder: Optional[DecoderType] = None,
) -> T: ... # pragma: no cover
) -> T:
... # pragma: no cover


@overload
Expand All @@ -186,7 +187,8 @@ def custom_field(
mm_field: Optional[mm.fields.Field] = None,
encoder: Optional[EncoderType] = None,
decoder: Optional[DecoderType] = None,
) -> T: ... # pragma: no cover
) -> T:
... # pragma: no cover


@overload
Expand All @@ -200,7 +202,8 @@ def custom_field(
mm_field: Optional[mm.fields.Field] = None,
encoder: Optional[EncoderType] = None,
decoder: Optional[DecoderType] = None,
) -> Any: ... # pragma: no cover
) -> Any:
... # pragma: no cover


def custom_field(
Expand Down
26 changes: 16 additions & 10 deletions src/aibs_informatics_core/models/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,25 @@
@runtime_checkable
class ModelProtocol(Protocol):
@classmethod
def from_dict(cls: Type[T], data: JSONObject, **kwargs) -> T: ... # pragma: no cover
def from_dict(cls: Type[T], data: JSONObject, **kwargs) -> T:
... # pragma: no cover

def to_dict(self, **kwargs) -> JSONObject: ... # pragma: no cover
def to_dict(self, **kwargs) -> JSONObject:
... # pragma: no cover

@classmethod
def from_json(cls: Type[T], data: str, **kwargs) -> T: ... # pragma: no cover
def from_json(cls: Type[T], data: str, **kwargs) -> T:
... # pragma: no cover

def to_json(self, **kwargs) -> str: ... # pragma: no cover
def to_json(self, **kwargs) -> str:
... # pragma: no cover

@classmethod
def from_path(cls: Type[T], path: Path, **kwargs) -> T: ... # pragma: no cover
def from_path(cls: Type[T], path: Path, **kwargs) -> T:
... # pragma: no cover

def to_path(self, path: Path, **kwargs): ... # pragma: no cover
def to_path(self, path: Path, **kwargs):
... # pragma: no cover


# --------------------------------------------------------------
Expand Down Expand Up @@ -367,13 +373,13 @@ def copy(self: SM, partial: bool = DEFAULT_PARTIAL, **kwargs) -> SM:


class ModelSchemaMethod(Protocol):
def __call__(
self, cls: Type[SM], partial: bool, **kwargs
) -> mm.Schema: ... # pragma: no cover
def __call__(self, cls: Type[SM], partial: bool, **kwargs) -> mm.Schema:
... # pragma: no cover


class ModelClassMethod(Protocol):
def __call__(*args, **kwargs) -> Any: ... # pragma: no cover
def __call__(*args, **kwargs) -> Any:
... # pragma: no cover


def attach_schema_hooks(cls: Type[SchemaModel], remove_post_load_hooks: bool = True):
Expand Down
8 changes: 4 additions & 4 deletions src/aibs_informatics_core/utils/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def as_module_type(package: Union[str, ModuleType]) -> ModuleType:


@overload
def load_type_from_qualified_name(qualified_name: str, expected_type: Type[T]) -> T: ...
def load_type_from_qualified_name(qualified_name: str, expected_type: Type[T]) -> T:
...


@overload
def load_type_from_qualified_name(
qualified_name: str, expected_type: Literal[None] = None
) -> Any: ...
def load_type_from_qualified_name(qualified_name: str, expected_type: Literal[None] = None) -> Any:
...


def load_type_from_qualified_name(
Expand Down
42 changes: 28 additions & 14 deletions src/aibs_informatics_core/utils/os_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@ def find_all_paths(


@overload
def get_env_var(*keys: str) -> Optional[str]: ... # pragma: no cover
def get_env_var(*keys: str) -> Optional[str]:
... # pragma: no cover


@overload
def get_env_var(*keys: str, default_value: Literal[None]) -> Optional[str]: ... # pragma: no cover
def get_env_var(*keys: str, default_value: Literal[None]) -> Optional[str]:
... # pragma: no cover


@overload
def get_env_var(*keys: str, default_value: str) -> str: ... # pragma: no cover
def get_env_var(*keys: str, default_value: str) -> str:
... # pragma: no cover


def get_env_var(*keys: str, default_value: Optional[str] = None) -> Optional[str]:
Expand Down Expand Up @@ -132,10 +135,12 @@ class EnvVarItem:
value: str

@overload
def to_dict(self, lower: Literal[False] = False) -> EnvVarDictItemUpper: ...
def to_dict(self, lower: Literal[False] = False) -> EnvVarDictItemUpper:
...

@overload
def to_dict(self, lower: Literal[True]) -> EnvVarDictItemLower: ...
def to_dict(self, lower: Literal[True]) -> EnvVarDictItemLower:
...

def to_dict(self, lower: bool = False) -> Union[EnvVarDictItemUpper, EnvVarDictItemLower]:
if lower:
Expand Down Expand Up @@ -207,31 +212,36 @@ def to_env_var_dict(env_vars: EnvVarCollection) -> Dict[str, str]:


@overload
def to_env_var_list(env_vars: EnvVarCollection) -> List[EnvVarTupleItem]: ...
def to_env_var_list(env_vars: EnvVarCollection) -> List[EnvVarTupleItem]:
...


@overload
def to_env_var_list(
env_vars: EnvVarCollection, env_var_format: Literal[EnvVarFormat.TUPLE]
) -> List[EnvVarTupleItem]: ...
) -> List[EnvVarTupleItem]:
...


@overload
def to_env_var_list(
env_vars: EnvVarCollection, env_var_format: Literal[EnvVarFormat.OBJECT]
) -> List[EnvVarItem]: ...
) -> List[EnvVarItem]:
...


@overload
def to_env_var_list(
env_vars: EnvVarCollection, env_var_format: Literal[EnvVarFormat.DICT_LOWER]
) -> List[EnvVarDictItemLower]: ...
) -> List[EnvVarDictItemLower]:
...


@overload
def to_env_var_list(
env_vars: EnvVarCollection, env_var_format: Literal[EnvVarFormat.DICT_UPPER]
) -> List[EnvVarDictItemUpper]: ...
) -> List[EnvVarDictItemUpper]:
...


def to_env_var_list(
Expand Down Expand Up @@ -260,25 +270,29 @@ def to_env_var_list(
@overload
def order_env_vars(
env_vars: EnvVarCollection, env_var_format: Literal[EnvVarFormat.OBJECT]
) -> List[EnvVarItem]: ...
) -> List[EnvVarItem]:
...


@overload
def order_env_vars(
env_vars: EnvVarCollection, env_var_format: Literal[EnvVarFormat.TUPLE]
) -> List[EnvVarTupleItem]: ...
) -> List[EnvVarTupleItem]:
...


@overload
def order_env_vars(
env_vars: EnvVarCollection, env_var_format: Literal[EnvVarFormat.DICT_LOWER]
) -> List[EnvVarDictItemLower]: ...
) -> List[EnvVarDictItemLower]:
...


@overload
def order_env_vars(
env_vars: EnvVarCollection, env_var_format: Literal[EnvVarFormat.DICT_UPPER]
) -> List[EnvVarDictItemUpper]: ...
) -> List[EnvVarDictItemUpper]:
...


def order_env_vars(
Expand Down

0 comments on commit 15460cc

Please sign in to comment.