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
4 changes: 2 additions & 2 deletions injection/_core/common/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Iterator,
)
from inspect import isclass, isfunction
from types import GenericAlias, UnionType
from types import GenericAlias, NoneType, UnionType
from typing import (
Annotated,
Any,
Expand Down Expand Up @@ -74,7 +74,7 @@ def standardize_types(
with_origin: bool = False,
) -> Iterator[TypeDef[Any]]:
for tp in types:
if tp is None:
if tp in (None, NoneType):
continue

origin = get_origin(tp)
Expand Down
29 changes: 22 additions & 7 deletions tests/core/test_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ class _RawData: ...

class TestMappedScope:
def test_set_name_with_multiple_owner_raise_type_error(self):
class ContextA:
class BindingsA:
scope = MappedScope("some_scope")

with pytest.raises(TypeError):

class ContextB:
scope = ContextA.scope
class BindingsB:
scope = BindingsA.scope

async def test_aopen_with_success(self, module):
@dataclass
class ScopeContext:
class Bindings:
data: Scoped[_RawData]

scope = MappedScope("some_scope", module=module)

data = _RawData()
context = ScopeContext(data)
context = Bindings(data)

assert module.get_instance(_RawData) is NotImplemented

Expand All @@ -37,14 +37,14 @@ class ScopeContext:

def test_open_with_success(self, module):
@dataclass
class ScopeContext:
class Bindings:
data: Scoped[_RawData]
unscoped_data: int

scope = MappedScope("some_scope", module=module)

data = _RawData()
context = ScopeContext(data, 2)
context = Bindings(data, 2)

assert module.get_instance(_RawData) is NotImplemented

Expand All @@ -54,6 +54,21 @@ class ScopeContext:

assert module.get_instance(_RawData) is NotImplemented

def test_open_with_optional_types(self, module):
@dataclass
class Bindings:
data: Scoped[_RawData | None] = None
name: Scoped[str | None] = None

scope = MappedScope("some_scope", module=module)

data = _RawData()
context = Bindings(data)

with context.scope.define():
assert module.get_instance(_RawData) is data
assert module.get_instance(str) is NotImplemented


class TestLazyInstance:
def test_lazy_instance_with_instance_return_t(self):
Expand Down