@@ -10,23 +10,23 @@ class _RawData: ...
1010
1111class TestMappedScope :
1212 def test_set_name_with_multiple_owner_raise_type_error (self ):
13- class ContextA :
13+ class BindingsA :
1414 scope = MappedScope ("some_scope" )
1515
1616 with pytest .raises (TypeError ):
1717
18- class ContextB :
19- scope = ContextA .scope
18+ class BindingsB :
19+ scope = BindingsA .scope
2020
2121 async def test_aopen_with_success (self , module ):
2222 @dataclass
23- class ScopeContext :
23+ class Bindings :
2424 data : Scoped [_RawData ]
2525
2626 scope = MappedScope ("some_scope" , module = module )
2727
2828 data = _RawData ()
29- context = ScopeContext (data )
29+ context = Bindings (data )
3030
3131 assert module .get_instance (_RawData ) is NotImplemented
3232
@@ -37,14 +37,14 @@ class ScopeContext:
3737
3838 def test_open_with_success (self , module ):
3939 @dataclass
40- class ScopeContext :
40+ class Bindings :
4141 data : Scoped [_RawData ]
4242 unscoped_data : int
4343
4444 scope = MappedScope ("some_scope" , module = module )
4545
4646 data = _RawData ()
47- context = ScopeContext (data , 2 )
47+ context = Bindings (data , 2 )
4848
4949 assert module .get_instance (_RawData ) is NotImplemented
5050
@@ -54,6 +54,21 @@ class ScopeContext:
5454
5555 assert module .get_instance (_RawData ) is NotImplemented
5656
57+ def test_open_with_optional_types (self , module ):
58+ @dataclass
59+ class Bindings :
60+ data : Scoped [_RawData | None ] = None
61+ name : Scoped [str | None ] = None
62+
63+ scope = MappedScope ("some_scope" , module = module )
64+
65+ data = _RawData ()
66+ context = Bindings (data )
67+
68+ with context .scope .define ():
69+ assert module .get_instance (_RawData ) is data
70+ assert module .get_instance (str ) is NotImplemented
71+
5772
5873class TestLazyInstance :
5974 def test_lazy_instance_with_instance_return_t (self ):
0 commit comments