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.
Projectmeadsteve/lagom
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
| 58 | 58 | """When one class is asked for the other should be returned""" | |
| 59 | 59 | ||
| 60 | 60 | alias_type: Type[X] | |
| 61 | + | skip_definitions: bool | |
| 61 | 62 | ||
| 62 | - | def __init__(self, alias_type): | |
| 63 | + | def __init__(self, alias_type, skip_definitions=False): | |
| 63 | 64 | self.alias_type = alias_type | |
| 65 | + | self.skip_definitions = skip_definitions | |
| 64 | 66 | ||
| 65 | 67 | 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 | + | ) | |
| 67 | 71 | ||
| 68 | 72 | ||
| 69 | 73 | class SingletonWrapper(SpecialDepDefinition[X]): | |
| ⋯ | |||
| 99 | 103 | ||
| 100 | 104 | ||
| 101 | 105 | class Singleton(SingletonWrapper[X]): | |
| 102 | - | """Builds only onlambda: ce then saves the built instance""" | |
| 106 | + | """Builds only once then saves the built instance""" | |
| 103 | 107 | ||
| 104 | 108 | def __init__(self, singleton_type: TypeResolver): | |
| 105 | - | super().__init__(normalise(singleton_type)) | |
| 109 | + | super().__init__(normalise(singleton_type, skip_alias_definitions=True)) | |
| 106 | 110 | ||
| 107 | 111 | ||
| 108 | 112 | class PlainInstance(SpecialDepDefinition[X]): | |
| ⋯ | |||
| 134 | 138 | raise TypeResolutionBlocked(self._msg_or_exception) | |
| 135 | 139 | ||
| 136 | 140 | ||
| 137 | - | def normalise(resolver: TypeResolver) -> SpecialDepDefinition: | |
| 141 | + | def normalise( | |
| 142 | + | resolver: TypeResolver, skip_alias_definitions=False | |
| 143 | + | ) -> SpecialDepDefinition: | |
| 138 | 144 | """ | |
| 139 | 145 | :param resolver: | |
| 146 | + | :param skip_alias_definitions if an alias is loaded should futher definitions be skipped | |
| 140 | 147 | :return: | |
| 141 | 148 | """ | |
| 142 | 149 | if isinstance(resolver, SpecialDepDefinition): | |
| ⋯ | |||
| 146 | 153 | elif inspect.iscoroutinefunction(resolver): | |
| 147 | 154 | return construction(resolver) | |
| 148 | 155 | elif inspect.isclass(resolver): | |
| 149 | - | return Alias(resolver) | |
| 156 | + | return Alias(resolver, skip_alias_definitions) | |
| 150 | 157 | else: | |
| 151 | 158 | return PlainInstance(resolver) | |
| 152 | 159 | ||
The check that tells the two apart
fail→pass·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
- 2020-06-13CachingReflector
- 2020-06-13Fix bug where typed self caused loading issues