Skip to content

Commit afb10d4

Browse files
committed
lint: Applied ruff fixes.
1 parent ed2606e commit afb10d4

6 files changed

Lines changed: 22 additions & 22 deletions

File tree

examples/benchmark/injection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def _iterator(x: float) -> typing.Iterator[float]:
1515

1616

1717
class _Container(BaseContainer):
18-
grandparent = providers.Singleton(lambda: random.random())
18+
grandparent = providers.Singleton(random.random)
1919
parent = providers.Factory(lambda x: x, grandparent.cast)
2020
item = providers.ContextResource(_iterator, parent.cast).with_config(scope=ContextScopes.REQUEST)
2121

tests/experimental/test_container_2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Container2(BaseContainer):
3939
obj_2 = providers.Object(2)
4040
async_context_provider = providers.ContextResource(_async_creator)
4141
sync_context_provider = providers.ContextResource(_sync_creator)
42-
singleton_provider = providers.Singleton(lambda: random.random())
42+
singleton_provider = providers.Singleton(random.random)
4343

4444

4545
async def test_lazy_provider_resolution_async() -> None:

tests/providers/test_attr_getter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def __init__(self, v: float) -> None:
166166
self.v = v
167167

168168
class _Container(BaseContainer):
169-
parent = providers.Singleton(lambda: random.random())
169+
parent = providers.Singleton(random.random)
170170
child = providers.Singleton(_Item, parent.cast)
171171

172172
attr_getter = _Container.child.v

tests/test_container.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async def test_container_tear_down() -> None:
3434

3535
async def test_container_sync_tear_down_propagation() -> None:
3636
class _DependentContainer(BaseContainer):
37-
singleton = providers.Singleton(lambda: random.random())
37+
singleton = providers.Singleton(random.random)
3838
resource = providers.Resource(_sync_resource)
3939

4040
DIContainer.connect_containers(_DependentContainer)
@@ -60,7 +60,7 @@ async def _async_resource() -> typing.AsyncIterator[float]:
6060
class _DependentContainer(BaseContainer):
6161
async_singleton = providers.AsyncSingleton(_async_singleton)
6262
async_resource = providers.Resource(_async_resource)
63-
sync_singleton = providers.Singleton(lambda: random.random())
63+
sync_singleton = providers.Singleton(random.random)
6464
sync_resource = providers.Resource(_sync_resource)
6565

6666
DIContainer.connect_containers(_DependentContainer)

tests/test_injection.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ def injected(repo: DocumentRepository = Provide[_Container._factory_provider]) -
559559

560560
def test_simple_injection_into_iterator_sync() -> None:
561561
class _Container(BaseContainer):
562-
sync_resource = providers.Factory(lambda: random.random())
562+
sync_resource = providers.Factory(random.random)
563563

564564
@contextmanager
565565
@inject
@@ -592,7 +592,7 @@ def test_simple_injection_into_generator_sync() -> None:
592592
_max_multiplier = 3
593593

594594
class _Container(BaseContainer):
595-
sync_resource = providers.Factory(lambda: random.random())
595+
sync_resource = providers.Factory(random.random)
596596

597597
@inject
598598
def _injected(val: float = Provide["_Container.sync_resource"]) -> typing.Generator[float, None, None]:
@@ -659,7 +659,7 @@ async def _injected(val: float = Provide[_Container.sync_resource]) -> typing.As
659659

660660
def test_simple_override_injection_into_iterator_sync() -> None:
661661
class _Container(BaseContainer):
662-
sync_resource = providers.Factory(lambda: random.random())
662+
sync_resource = providers.Factory(random.random)
663663

664664
@contextmanager
665665
@inject
@@ -692,7 +692,7 @@ async def _injected(val: float = Provide[_Container.async_resource]) -> typing.A
692692

693693
def test_simple_injection_into_generator_with_receive_sync() -> None:
694694
class _Container(BaseContainer):
695-
sync_resource = providers.Factory(lambda: random.random())
695+
sync_resource = providers.Factory(random.random)
696696

697697
value_to_send = 5
698698

@@ -717,7 +717,7 @@ def _injected_receive(initial_val: float = Provide[_Container.sync_resource]) ->
717717

718718
def test_simple_injection_into_generator_with_return_sync() -> None:
719719
class _Container(BaseContainer):
720-
sync_resource = providers.Factory(lambda: random.random())
720+
sync_resource = providers.Factory(random.random)
721721

722722
multiplier = 4
723723

@@ -746,7 +746,7 @@ def _injected_return(
746746

747747
def test_simple_injection_into_generator_yield_once_receive_return_sync() -> None: # Renamed test slightly
748748
class _Container(BaseContainer):
749-
sync_resource = providers.Factory(lambda: random.random())
749+
sync_resource = providers.Factory(random.random)
750750

751751
send_value = 7
752752
return_add = 100
@@ -849,7 +849,7 @@ async def _injected(val: float = Provide[_Container.sync_resource]) -> typing.As
849849

850850
def test_injection_by_type_sync() -> None:
851851
class _Container(BaseContainer):
852-
sync_resource = providers.Factory(lambda: random.random()).bind(float)
852+
sync_resource = providers.Factory(random.random).bind(float)
853853

854854
@inject(container=_Container)
855855
def _injected_1(val: float = Provide()) -> float:
@@ -865,7 +865,7 @@ def _injected_2(val: float = Provide()) -> float:
865865

866866
async def test_injection_by_type_async() -> None:
867867
class _Container(BaseContainer):
868-
sync_resource = providers.Factory(lambda: random.random()).bind(float)
868+
sync_resource = providers.Factory(random.random).bind(float)
869869

870870
@inject(container=_Container)
871871
async def _injected_1(val: float = Provide()) -> float:
@@ -881,7 +881,7 @@ async def _injected_2(val: float = Provide()) -> float:
881881

882882
async def test_injection_by_type_async_generator() -> None:
883883
class _Container(BaseContainer):
884-
sync_resource = providers.Factory(lambda: random.random()).bind(float)
884+
sync_resource = providers.Factory(random.random).bind(float)
885885

886886
@inject(container=_Container)
887887
async def _injected_1(val: float = Provide()) -> typing.AsyncGenerator[float, None]:
@@ -897,7 +897,7 @@ async def _injected_2(val: float = Provide()) -> typing.AsyncGenerator[float, No
897897

898898
def test_injection_by_type_sync_generator() -> None:
899899
class _Container(BaseContainer):
900-
sync_resource = providers.Factory(lambda: random.random()).bind(float)
900+
sync_resource = providers.Factory(random.random).bind(float)
901901

902902
@inject(container=_Container)
903903
def _injected_1(val: float = Provide()) -> typing.Generator[float, None, None]:
@@ -945,7 +945,7 @@ async def _injected_2(val: float = Provide()) -> typing.AsyncGenerator[float, No
945945

946946
def test_inject_by_type_fails_if_type_is_not_bound_sync() -> None:
947947
class _Container(BaseContainer):
948-
sync_resource = providers.Factory(lambda: random.random()).bind(float)
948+
sync_resource = providers.Factory(random.random).bind(float)
949949

950950
@_Container.inject
951951
def _injected_1(val: int = Provide()) -> float:
@@ -964,7 +964,7 @@ def _injected_2(val: int = Provide()) -> typing.Generator[float, None, None]:
964964

965965
async def test_inject_by_type_fails_if_type_is_not_bound_async() -> None:
966966
class _Container(BaseContainer):
967-
sync_resource = providers.Factory(lambda: random.random()).bind(float)
967+
sync_resource = providers.Factory(random.random).bind(float)
968968

969969
@_Container.inject
970970
async def _injected_1(val: int = Provide()) -> float:
@@ -986,7 +986,7 @@ class A: ...
986986
class B(A): ...
987987

988988
class _Container(BaseContainer):
989-
sync_resource = providers.Factory(lambda: B()).bind(B, contravariant=True)
989+
sync_resource = providers.Factory(B).bind(B, contravariant=True)
990990

991991
@inject(container=_Container)
992992
def _injected(val_a: A = Provide(), val_b: B = Provide()) -> tuple[A, B]:
@@ -1004,7 +1004,7 @@ class A: ...
10041004
class B(A): ...
10051005

10061006
class _Container(BaseContainer):
1007-
sync_resource = providers.Factory(lambda: B()).bind(B, contravariant=True)
1007+
sync_resource = providers.Factory(B).bind(B, contravariant=True)
10081008

10091009
@inject(container=_Container)
10101010
async def _injected(val_a: A = Provide(), val_b: B = Provide()) -> tuple[A, B]:
@@ -1018,7 +1018,7 @@ async def _injected(val_a: A = Provide(), val_b: B = Provide()) -> tuple[A, B]:
10181018

10191019
def test_type_injection_fails_without_bind_sync() -> None:
10201020
class _Container(BaseContainer):
1021-
sync_resource = providers.Factory(lambda: random.random())
1021+
sync_resource = providers.Factory(random.random)
10221022

10231023
@inject(container=_Container)
10241024
def _injected(val: float = Provide()) -> float:
@@ -1030,7 +1030,7 @@ def _injected(val: float = Provide()) -> float:
10301030

10311031
async def test_type_injection_fails_without_bind_async() -> None:
10321032
class _Container(BaseContainer):
1033-
sync_resource = providers.Factory(lambda: random.random())
1033+
sync_resource = providers.Factory(random.random)
10341034

10351035
@inject(container=_Container)
10361036
async def _injected(val: float = Provide()) -> float:

that_depends/providers/context_resources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def __init__(
481481
self._scope_token: Token[ContextScope | None] | None = None
482482

483483
def _resolve_initial_conditions(self) -> None:
484-
self._scope = self._scope if self._scope else get_current_scope()
484+
self._scope = self._scope or get_current_scope()
485485
if self._preserve_global_context and self._global_context:
486486
if context := _get_container_context():
487487
self._initial_context = {**context, **self._global_context}

0 commit comments

Comments
 (0)