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.

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

1919 ContainerCloseError,
2020 InvalidRegistrationTypeError,
2121 UnknownServiceRequestedError,
22+ WireupError,
2223 )
2324 from wireup.ioc.service_registry import ServiceRegistry
2425 from wireup.ioc.types import (
249250 if res := self._get_ctor(klass=klass, qualifier=qualifier):
250251 ctor, resolved_type = res
251252 instance_or_generator = ctor(**self.__callable_get_params_to_inject(ctor))
253+ is_generator = inspect.isgenerator(instance_or_generator)
252254
253- if inspect.isgenerator(instance_or_generator):
255+ if is_generator:
254256 self.__exit_stack.append(instance_or_generator)
255257 instance = next(instance_or_generator)
256258 else:
258260
259261 if self._registry.is_impl_singleton(resolved_type):
260262 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)
261266
262267 return instance
263268

The check that tells the two apart

failpass·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.

Other bugs found in maldoinc/wireup