diff --git a/.bumpversion.cfg b/.bumpversion.cfg index fc057e8..be99ebb 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.1.1 +current_version = 2.1.2 commit = false tag = false serialize = diff --git a/README.md b/README.md index 6959f72..ed0576d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ # Labrea A framework for declarative, functional dataset definitions. -![](https://img.shields.io/badge/version-2.1.1-blue.svg) +![](https://img.shields.io/badge/version-2.1.2-blue.svg) [![lifecycle](https://img.shields.io/badge/lifecycle-stable-green.svg)](https://www.tidyverse.org/lifecycle/#stable) [![PyPI Downloads](https://img.shields.io/pypi/dm/labrea.svg?label=PyPI%20downloads)](https://pypi.org/project/labrea/) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) diff --git a/docs/source/changelog.md b/docs/source/changelog.md index 8dc92a5..8574de6 100644 --- a/docs/source/changelog.md +++ b/docs/source/changelog.md @@ -1,5 +1,8 @@ # Changelog +## Version 2.1.2 +- Update type-hint for `@Option.namespace` to make namespaces easier to use with type checkers + ## Version 2.1.1 - Fix bug introduced in 2.1.0 where exceptions raised during `.evaluate` are all masked as `EvaluationError` diff --git a/labrea/_version.py b/labrea/_version.py index 58039f5..4eabd0b 100644 --- a/labrea/_version.py +++ b/labrea/_version.py @@ -1 +1 @@ -__version__ = "2.1.1" +__version__ = "2.1.2" diff --git a/labrea/option.py b/labrea/option.py index 2340d01..6be521d 100644 --- a/labrea/option.py +++ b/labrea/option.py @@ -34,6 +34,8 @@ A = TypeVar("A", covariant=True, bound="JSON") B = TypeVar("B", covariant=True) +T = TypeVar("T", bound=JSON) +T_type = TypeVar("T_type", bound=Type) _Domain = Union[Container[A], Callable[[A], bool]] Domain = Evaluatable[_Domain] @@ -226,18 +228,18 @@ def __class_getitem__(cls, type: Any): @overload @staticmethod - def namespace(__namespace: Type) -> "Namespace": ... # pragma: no cover + def namespace(__namespace: T_type) -> T_type: ... # pragma: no cover @overload @staticmethod def namespace( __namespace: str, - ) -> Callable[[Type], "Namespace"]: ... # pragma: no cover + ) -> Callable[[T_type], T_type]: ... # pragma: no cover @staticmethod def namespace( - __namespace: Union[Type, str], - ) -> Union["Namespace", Callable[[Type], "Namespace"]]: + __namespace: Union[T_type, str], + ) -> Union["Namespace", Callable[[T_type], T_type]]: """Create an option namespace from a class definition This allows all of the options for a module to be grouped together. Namespaces can contain @@ -271,16 +273,16 @@ def namespace( Option MY_PACKAGE.MODULE-2.A (default 10) """ if isinstance(__namespace, str): - return lambda cls: Namespace._from_type(cls, name=__namespace) + return lambda cls: Namespace._from_type(cls, name=__namespace) # type: ignore[return-value] return Namespace._from_type(__namespace) @staticmethod def auto( default: MaybeMissing[MaybeEvaluatable[A]] = MISSING, doc: str = "", - type: Type[A] = cast(Type, Any), + type: Type[T] = cast(Type, Any), domain: MaybeMissing[MaybeEvaluatable[_Domain]] = MISSING, - ) -> "Option[A]": + ) -> "Option[T]": """Create an option in a namespace with an inferred key Sometimes when creating a namespace, we want to add an option with a docstring or some