Whole file
maldoinc/wireup
The author described this change as “Raise on generators + transient dependencies”. It counts as a record because the check below fails on the code as it stood at be601b6d1 and passes on d59a3d721, with nothing else changed between the two runs.
Projectmaldoinc/wireup
Fix saved2024-10-19
Sharing licenceMIT ·
Change size+6 −1
What the code was meant to do, written into the code itself as a save note
Raise on generators + transient dependencies
The change
| 19 | 19 | ContainerCloseError, | |
| 20 | 20 | InvalidRegistrationTypeError, | |
| 21 | 21 | UnknownServiceRequestedError, | |
| 22 | + | WireupError, | |
| 22 | 23 | ) | |
| 23 | 24 | from wireup.ioc.service_registry import ServiceRegistry | |
| 24 | 25 | from wireup.ioc.types import ( | |
| ⋯ | |||
| 249 | 250 | if res := self._get_ctor(klass=klass, qualifier=qualifier): | |
| 250 | 251 | ctor, resolved_type = res | |
| 251 | 252 | instance_or_generator = ctor(**self.__callable_get_params_to_inject(ctor)) | |
| 253 | + | is_generator = inspect.isgenerator(instance_or_generator) | |
| 252 | 254 | ||
| 253 | - | if inspect.isgenerator(instance_or_generator): | |
| 255 | + | if is_generator: | |
| 254 | 256 | self.__exit_stack.append(instance_or_generator) | |
| 255 | 257 | instance = next(instance_or_generator) | |
| 256 | 258 | else: | |
| ⋯ | |||
| 258 | 260 | ||
| 259 | 261 | if self._registry.is_impl_singleton(resolved_type): | |
| 260 | 262 | self._initialized_objects[resolved_type, qualifier] = instance | |
| 263 | + | elif is_generator: | |
| 264 | + | msg = "Generators are not currently supported with transient-scoped dependencies." | |
| 265 | + | raise WireupError(msg) | |
| 261 | 266 | ||
| 262 | 267 | return instance | |
| 263 | 268 | ||
The check that tells the two apart
fail→pass·test/unit/test_generator_factory.py::test_raises_on_transient_dependency
Check file test/unit/test_generator_factory.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 itbe601b6d1f0dddb7eb27817d402e129216c2a6e1
Broken version dated2024-10-19
Modulewireup.ioc.dependency_container
Units changedDependencyContainer
Fingerprint0638c8604b49432d
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.