Whole file

meadsteve/lagom

The author described this change as Fix bug where aliases could be used to skip build definitions. It counts as a record because the check below fails on the code as it stood at 2d3b35135 and passes on c5e0e1c20, with nothing else changed between the two runs.

Fix saved2021-03-21
Sharing licenceMIT · LICENSE
Change size+13 6

What the code was meant to do, written into the code itself as a save note

Fix bug where aliases could be used to skip build definitions

The change

5858 """When one class is asked for the other should be returned"""
5959
6060 alias_type: Type[X]
61+ skip_definitions: bool
6162
62- def __init__(self, alias_type):
63+ def __init__(self, alias_type, skip_definitions=False):
6364 self.alias_type = alias_type
65+ self.skip_definitions = skip_definitions
6466
6567 def get_instance(self, container: ReadableContainer) -> X:
66- return container.resolve(self.alias_type, skip_definitions=True)
68+ return container.resolve(
69+ self.alias_type, skip_definitions=self.skip_definitions
70+ )
6771
6872
6973 class SingletonWrapper(SpecialDepDefinition[X]):
99103
100104
101105 class Singleton(SingletonWrapper[X]):
102- """Builds only onlambda: ce then saves the built instance"""
106+ """Builds only once then saves the built instance"""
103107
104108 def __init__(self, singleton_type: TypeResolver):
105- super().__init__(normalise(singleton_type))
109+ super().__init__(normalise(singleton_type, skip_alias_definitions=True))
106110
107111
108112 class PlainInstance(SpecialDepDefinition[X]):
134138 raise TypeResolutionBlocked(self._msg_or_exception)
135139
136140
137-def normalise(resolver: TypeResolver) -> SpecialDepDefinition:
141+def normalise(
142+ resolver: TypeResolver, skip_alias_definitions=False
143+) -> SpecialDepDefinition:
138144 """
139145 :param resolver:
146+ :param skip_alias_definitions if an alias is loaded should futher definitions be skipped
140147 :return:
141148 """
142149 if isinstance(resolver, SpecialDepDefinition):
146153 elif inspect.iscoroutinefunction(resolver):
147154 return construction(resolver)
148155 elif inspect.isclass(resolver):
149- return Alias(resolver)
156+ return Alias(resolver, skip_alias_definitions)
150157 else:
151158 return PlainInstance(resolver)
152159

The check that tells the two apart

failpass·tests/bug_fixes/test_alias_to_constructor_skipped.py::test_an_alias_doesnt_skip_a_defined_constructor

Check file tests/bug_fixes/test_alias_to_constructor_skipped.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it2d3b35135a5df32ee60a46fe7791d3eabf3f2d87
Broken version dated2021-03-21
Modulelagom.definitions
Units changedAlias, Singleton, normalise
Fingerprint13d3e3ec097b13a2
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in meadsteve/lagom