Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.1.1
current_version = 2.1.2
commit = false
tag = false
serialize =
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions docs/source/changelog.md
Original file line number Diff line number Diff line change
@@ -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`

Expand Down
2 changes: 1 addition & 1 deletion labrea/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.1.1"
__version__ = "2.1.2"
16 changes: 9 additions & 7 deletions labrea/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading