Skip to content

Commit 1b9367b

Browse files
Prepare for 2.0.8
1 parent 62c910b commit 1b9367b

File tree

5 files changed

+18
-31
lines changed

5 files changed

+18
-31
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.0.8] - 2025-04-12
9+
10+
- Add the link to the [documentation](https://www.neoteroi.dev/rodi/).
11+
- Remove the `UnsupportedUnionTypeException` as `Rodi` supports union types,
12+
they only require proper handling.
13+
814
## [2.0.7] - 2025-03-28
915

1016
- Add the possibility to specify the `ActivationScope` class when instantiating

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![versions](https://img.shields.io/pypi/pyversions/rodi.svg)](https://github.com/Neoteroi/rodi)
44
[![codecov](https://codecov.io/gh/Neoteroi/rodi/branch/main/graph/badge.svg?token=VzAnusWIZt)](https://codecov.io/gh/Neoteroi/rodi)
55
[![license](https://img.shields.io/github/license/Neoteroi/rodi.svg)](https://github.com/Neoteroi/rodi/blob/main/LICENSE)
6+
[![documentation](https://img.shields.io/badge/📖-docs-purple)](https://www.neoteroi.dev/rodi/)
67

78
# Implementation of dependency injection for Python 3
89

@@ -24,6 +25,10 @@ Core](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injec
2425
application](https://andrewlock.net/using-dependency-injection-in-a-net-core-console-application/)_).
2526
The `ContainerProtocol` for v2 is inspired by [punq](https://github.com/bobthemighty/punq).
2627

28+
## Documentation
29+
30+
Rodi is documented here: [https://www.neoteroi.dev/rodi/](https://www.neoteroi.dev/rodi/).
31+
2732
## Installation
2833

2934
```bash
@@ -86,7 +91,3 @@ relying on the HTTP Request object being a service registered in your container.
8691
`rodi` is used in the [BlackSheep](https://www.neoteroi.dev/blacksheep/)
8792
web framework to implement [dependency injection](https://www.neoteroi.dev/blacksheep/dependency-injection/) for
8893
request handlers.
89-
90-
# Documentation
91-
92-
Under construction. 🚧

rodi/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.0.7"
1+
__version__ = "2.0.8"

rodi/__init__.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,6 @@ def __init__(self, param_name, desired_type):
131131
)
132132

133133

134-
class UnsupportedUnionTypeException(DIException):
135-
"""Exception risen when a parameter type is defined
136-
as Optional or Union of several types."""
137-
138-
def __init__(self, param_name, desired_type):
139-
super().__init__(
140-
f"Union or Optional type declaration is not supported. "
141-
f"Cannot resolve parameter '{param_name}' "
142-
f"when resolving '{class_name(desired_type)}'"
143-
)
144-
145-
146134
class OverridingServiceException(DIException):
147135
"""
148136
Exception risen when registering a service
@@ -548,12 +536,6 @@ def _get_resolvers_for_parameters(
548536

549537
param_type = param.annotation
550538

551-
if hasattr(param_type, "__origin__") and param_type.__origin__ is Union:
552-
# NB: we could cycle through possible types using: param_type.__args__
553-
# Right now Union and Optional types resolution is not implemented,
554-
# but at least Optional could be supported in the future
555-
raise UnsupportedUnionTypeException(param_name, concrete_type)
556-
557539
if param_type is _empty:
558540
if services.strict:
559541
raise CannotResolveParameterException(param_name, concrete_type)

tests/test_services.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
Iterable,
1111
List,
1212
Mapping,
13+
Optional,
1314
Sequence,
1415
Tuple,
1516
Type,
@@ -38,7 +39,6 @@
3839
ServiceLifeStyle,
3940
Services,
4041
TrackingActivationScope,
41-
UnsupportedUnionTypeException,
4242
_get_factory_annotations_or_throw,
4343
inject,
4444
to_standard_param_name,
@@ -321,15 +321,13 @@ def test_add_instance_with_declared_type():
321321
assert isinstance(icircle, Circle)
322322

323323

324-
def test_raises_for_optional_parameter():
324+
def test_optional_parameter():
325325
container = Container()
326-
container._add_exact_transient(Foo)
327-
container._add_exact_transient(TypeWithOptional)
328-
329-
with pytest.raises(UnsupportedUnionTypeException) as context:
330-
container.build_provider()
326+
container.add_transient(Optional[Foo], Foo) # type: ignore
327+
container.add_transient(TypeWithOptional)
331328

332-
assert "foo" in str(context.value)
329+
a = container.resolve(TypeWithOptional)
330+
assert isinstance(a.foo, Foo)
333331

334332

335333
def test_raises_for_nested_circular_dependency():

0 commit comments

Comments
 (0)