Skip to content

Commit

Permalink
Add attribute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
KaQuMiQ committed Dec 9, 2024
1 parent d171290 commit 5149d38
Show file tree
Hide file tree
Showing 10 changed files with 1,031 additions and 19 deletions.
2 changes: 1 addition & 1 deletion constraints
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# uv --no-cache pip compile pyproject.toml -o constraints --all-extras
bandit==1.8.0
# via haiway (pyproject.toml)
coverage==7.6.8
coverage==7.6.9
# via pytest-cov
iniconfig==2.0.0
# via pytest
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "haiway"
description = "Framework for dependency injection and state management within structured concurrency model."
version = "0.6.2"
version = "0.6.3"
readme = "README.md"
maintainers = [
{ name = "Kacper Kaliński", email = "[email protected]" },
Expand Down
4 changes: 3 additions & 1 deletion src/haiway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
traced,
wrap_async,
)
from haiway.state import State
from haiway.state import AttributePath, AttributeRequirement, State
from haiway.types import (
MISSING,
Missing,
Expand Down Expand Up @@ -46,6 +46,8 @@
"MISSING",
"ArgumentsTrace",
"AsyncQueue",
"AttributePath",
"AttributeRequirement",
"Disposable",
"Disposables",
"Missing",
Expand Down
4 changes: 4 additions & 0 deletions src/haiway/state/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from haiway.state.attributes import AttributeAnnotation, attribute_annotations
from haiway.state.path import AttributePath
from haiway.state.requirement import AttributeRequirement
from haiway.state.structure import State

__all__ = [
"AttributeAnnotation",
"AttributePath",
"AttributeRequirement",
"State",
"attribute_annotations",
]
29 changes: 15 additions & 14 deletions src/haiway/state/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
__all__ = [
"AttributeAnnotation",
"attribute_annotations",
"resolve_attribute_annotation",
]


Expand Down Expand Up @@ -68,7 +69,7 @@ def attribute_annotations(
if ((get_origin(annotation) or annotation) is ClassVar) or key.startswith("_"):
continue

attributes[key] = _resolve_attribute_annotation(
attributes[key] = resolve_attribute_annotation(
annotation,
self_annotation=self_annotation,
type_parameters=type_parameters,
Expand All @@ -80,7 +81,7 @@ def attribute_annotations(
return attributes


def _resolve_attribute_annotation( # noqa: C901, PLR0911, PLR0912, PLR0913
def resolve_attribute_annotation( # noqa: C901, PLR0911, PLR0912, PLR0913
annotation: Any,
/,
self_annotation: AttributeAnnotation | None,
Expand All @@ -100,7 +101,7 @@ def _resolve_attribute_annotation( # noqa: C901, PLR0911, PLR0912, PLR0913

# forward reference through string
case str() as forward_ref:
return _resolve_attribute_annotation(
return resolve_attribute_annotation(
ForwardRef(forward_ref, module=module)._evaluate(
globalns=None,
localns=localns,
Expand All @@ -115,7 +116,7 @@ def _resolve_attribute_annotation( # noqa: C901, PLR0911, PLR0912, PLR0913

# forward reference directly
case typing.ForwardRef() as reference:
return _resolve_attribute_annotation(
return resolve_attribute_annotation(
reference._evaluate(
globalns=None,
localns=localns,
Expand All @@ -137,7 +138,7 @@ def _resolve_attribute_annotation( # noqa: C901, PLR0911, PLR0912, PLR0913
origin=TypeAliasType,
arguments=[],
)
resolved: AttributeAnnotation = _resolve_attribute_annotation(
resolved: AttributeAnnotation = resolve_attribute_annotation(
alias.__value__,
self_annotation=None,
type_parameters=type_parameters,
Expand Down Expand Up @@ -169,7 +170,7 @@ def _resolve_attribute_annotation( # noqa: C901, PLR0911, PLR0912, PLR0913
return AttributeAnnotation(
origin=parametrized,
arguments=[
_resolve_attribute_annotation(
resolve_attribute_annotation(
argument,
self_annotation=self_annotation,
type_parameters=type_parameters,
Expand All @@ -193,7 +194,7 @@ def _resolve_attribute_annotation( # noqa: C901, PLR0911, PLR0912, PLR0913
return AttributeAnnotation(
origin=origin,
arguments=[
_resolve_attribute_annotation(
resolve_attribute_annotation(
argument,
self_annotation=self_annotation,
type_parameters=type_parameters,
Expand All @@ -211,7 +212,7 @@ def _resolve_attribute_annotation( # noqa: C901, PLR0911, PLR0912, PLR0913
origin=TypeAliasType,
arguments=[],
)
resolved: AttributeAnnotation = _resolve_attribute_annotation(
resolved: AttributeAnnotation = resolve_attribute_annotation(
alias.__value__,
self_annotation=None,
type_parameters=type_parameters,
Expand All @@ -225,7 +226,7 @@ def _resolve_attribute_annotation( # noqa: C901, PLR0911, PLR0912, PLR0913

# type parameter
case typing.TypeVar():
return _resolve_attribute_annotation(
return resolve_attribute_annotation(
# try to resolve it from current parameters if able
type_parameters.get(
annotation.__name__,
Expand Down Expand Up @@ -270,7 +271,7 @@ def _resolve_attribute_annotation( # noqa: C901, PLR0911, PLR0912, PLR0913
arguments=[
recursion_guard.get(
argument,
_resolve_attribute_annotation(
resolve_attribute_annotation(
argument,
self_annotation=self_annotation,
type_parameters=type_parameters,
Expand All @@ -287,7 +288,7 @@ def _resolve_attribute_annotation( # noqa: C901, PLR0911, PLR0912, PLR0913
return AttributeAnnotation(
origin=typing.Callable,
arguments=[
_resolve_attribute_annotation(
resolve_attribute_annotation(
argument,
self_annotation=self_annotation,
type_parameters=type_parameters,
Expand All @@ -314,7 +315,7 @@ def _resolve_attribute_annotation( # noqa: C901, PLR0911, PLR0912, PLR0913

# unwrap from irrelevant type wrappers
case typing.Annotated | typing.Final | typing.Required | typing.NotRequired:
return _resolve_attribute_annotation(
return resolve_attribute_annotation(
get_args(annotation)[0],
self_annotation=self_annotation,
type_parameters=type_parameters,
Expand All @@ -327,7 +328,7 @@ def _resolve_attribute_annotation( # noqa: C901, PLR0911, PLR0912, PLR0913
return AttributeAnnotation(
origin=UnionType, # pyright: ignore[reportArgumentType]
arguments=[
_resolve_attribute_annotation(
resolve_attribute_annotation(
get_args(annotation)[0],
self_annotation=self_annotation,
type_parameters=type_parameters,
Expand All @@ -352,7 +353,7 @@ def _resolve_attribute_annotation( # noqa: C901, PLR0911, PLR0912, PLR0913
return AttributeAnnotation(
origin=other,
arguments=[
_resolve_attribute_annotation(
resolve_attribute_annotation(
argument,
self_annotation=self_annotation,
type_parameters=type_parameters,
Expand Down
Loading

0 comments on commit 5149d38

Please sign in to comment.