From 100b17ebfed2cd667a29d4a1df8f041630131500 Mon Sep 17 00:00:00 2001 From: Austin Warner Date: Sat, 3 May 2025 08:43:39 -0400 Subject: [PATCH 1/3] Tell the type-checker that Option.namespace returns the class unchanged --- labrea/option.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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 From 027d9cf1140602b25662d3ed87affdbf341b7359 Mon Sep 17 00:00:00 2001 From: Austin Warner Date: Sat, 3 May 2025 08:48:44 -0400 Subject: [PATCH 2/3] Update docs --- docs/source/changelog.md | 3 +++ 1 file changed, 3 insertions(+) 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` From 01ac603668a705f9119fc925dea31cd82c5d8527 Mon Sep 17 00:00:00 2001 From: Austin Warner Date: Sat, 3 May 2025 08:48:59 -0400 Subject: [PATCH 3/3] Bump Version --- .bumpversion.cfg | 2 +- README.md | 2 +- labrea/_version.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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/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"