From dabaea0834745d4ce32474214c291780fbec8431 Mon Sep 17 00:00:00 2001 From: narumi Date: Sat, 9 Nov 2024 16:06:30 +0800 Subject: [PATCH] refactor: update type hints to use union syntax for optional parameters --- src/mlconfig/conf.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mlconfig/conf.py b/src/mlconfig/conf.py index f4bb4ff..9cbd587 100644 --- a/src/mlconfig/conf.py +++ b/src/mlconfig/conf.py @@ -1,8 +1,8 @@ +from __future__ import annotations + import copy import functools from typing import Any -from typing import Optional -from typing import Union from omegaconf import DictConfig from omegaconf import ListConfig @@ -12,7 +12,7 @@ _key = "name" -def load(f: Optional[str] = None, obj: Optional[Any] = None) -> Union[ListConfig, DictConfig]: +def load(f: str | None = None, obj: Any | None = None) -> ListConfig | DictConfig: """Load configuration file or structured object. If both are provided, then the configuration from file will override the configuration from structured object. @@ -41,7 +41,7 @@ def load(f: Optional[str] = None, obj: Optional[Any] = None) -> Union[ListConfig return OmegaConf.merge(*configs) -def register(func_or_cls=None, name: Optional[str] = None): +def register(func_or_cls=None, name: str | None = None): r"""Register function or class Args: @@ -84,7 +84,7 @@ def instantiate(conf, *args, **kwargs): return func_or_cls(*args, **kwargs) -def flatten(data: dict, prefix: Optional[str] = None, sep: str = ".") -> dict: +def flatten(data: dict, prefix: str | None = None, sep: str = ".") -> dict: d = {} for key, value in data.items():