bobthemighty / punq

An IoC container for Python 3.6+
MIT License
301 stars 13 forks source link

fix: Bug introduced by special case in resolve for lists #182

Closed neilmacintyre closed 3 weeks ago

neilmacintyre commented 3 weeks ago

Before this PR the following code

from typing import List

import punq

container = punq.Container()

container.register(List[str], instance=['hi'])
print(container.resolve(List[str]))
print(container.resolve(List[str]))
print(container.resolve_all(List[str]))
print(container.resolve(List[str]))

would result in

[]
[]
[['hi']]
['hi']

Resolve should resolve the List[str] in the first two resolve calls. Further be idempotent, as long as nothing nothing new is registered and the resolve_all call should not effect the result of subsequent calls to resolve.

After this PR the result is:

['hi']
['hi']
[['hi']]
['hi']