frozendict is unable to be instantiated with an iterator or generator
nolsto opened this issue · comments
gelidum/gelidum/collections/frozendict.py
Line 26 in 850c061
The __init__
method of frozendict assumes that the class will only ever be called with a parameter of subtype collections.abc.Mapping
(has an items()
method).
An iteratable/iterator or generator type parameter should be handled as well.
Something along the lines of:
if isinstance(mapping, Mapping):
super().__init__(
{key: freeze_func(value) for key, value in mapping.items()}
)
else:
super().__init__(
{key: freeze_func(value) for key, value in mapping}
)
I'm not up on typing yet, so am hesitant to make a pull request.
Additionally, the __init__
method signature could be changed to handle dict creation by kwargs much like the builtin dict class.
def __init__(self, mapping=None, /, freeze_func=None, **kwargs):
There could be another case for this:
if isinstance(mapping, Mapping):
...
elif mapping is None and kwargs:
super().__init__(
{key: freeze_func(value) for key, value in kwargs.items()}
)
else:
...
Version 0.5.8 in pypi includes this change.
Thank you @nolsto for your help. Any other issue, don't hesitate to contact me.
Cheers.