Whole file
meadsteve/lagom
The author described this change as “Fix bug where typed self caused loading issues”. It counts as a record because the check below fails on the code as it stood at 0bf84398d and passes on d50fabea6, with nothing else changed between the two runs.
Projectmeadsteve/lagom
Fix saved2020-06-13
Sharing licenceMIT · LICENSE
Change size+6 −2
What the code was meant to do, written into the code itself as a save note
Fix bug where typed self caused loading issues
The change
| 206 | 206 | ||
| 207 | 207 | def _reflection_build(self, dep_type: Type[X]) -> X: | |
| 208 | 208 | spec = self._reflector.get_function_spec(dep_type.__init__) | |
| 209 | - | sub_deps = self._infer_dependencies(spec) | |
| 209 | + | sub_deps = self._infer_dependencies(spec, types_to_skip={dep_type}) | |
| 210 | 210 | try: | |
| 211 | 211 | return dep_type(**sub_deps) # type: ignore | |
| 212 | 212 | except TypeError as type_error: | |
| ⋯ | |||
| 218 | 218 | suppress_error=False, | |
| 219 | 219 | keys_to_skip: List[str] = None, | |
| 220 | 220 | skip_pos_up_to=0, | |
| 221 | + | types_to_skip: Set[Type] = None, | |
| 221 | 222 | ): | |
| 222 | 223 | supplied_arguments = spec.args[0:skip_pos_up_to] | |
| 223 | 224 | keys_to_skip = (keys_to_skip or []) + supplied_arguments | |
| 225 | + | types_to_skip = types_to_skip or set() | |
| 224 | 226 | sub_deps = { | |
| 225 | 227 | key: self.resolve(sub_dep_type, suppress_error=suppress_error) | |
| 226 | 228 | for (key, sub_dep_type) in spec.annotations.items() | |
| 227 | - | if sub_dep_type != Any and key not in keys_to_skip | |
| 229 | + | if sub_dep_type != Any | |
| 230 | + | and (key not in keys_to_skip) | |
| 231 | + | and (sub_dep_type not in types_to_skip) | |
| 228 | 232 | } | |
| 229 | 233 | filtered_deps = {key: dep for (key, dep) in sub_deps.items() if dep is not None} | |
| 230 | 234 | return filtered_deps | |
The check that tells the two apart
fail→pass·tests/test_objects.py::test_explicitly_typing_self_doesnt_cause_problems
Check file tests/test_objects.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 it0bf84398d8c34c2453326a5026b022be54ae807a
Broken version dated2020-06-13
Modulelagom.container
Units changedContainer
Fingerprintf57d380b477f7d41
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
- 2021-03-21Fix bug where aliases could be used to skip build definitions
- 2020-06-13CachingReflector