You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possibly wrong type annotations in register_structure_hook_factory #281
It seems like the type annotations for Converter.register_structue_hook_factory() are not correct.
They suggest a function signature that, when applied, leads to errors in my tests.
What I Did
My code:
defregister_attrs_hook_factory(converter: Converter) ->None:
""" Register a hook factory that allows using instances of attrs classes where cattrs would normally expect a dictionary. These instances are then returned as-is and without further processing. """defallow_attrs_instances(typ: Any) ->Callable[[Any, Any], Any]:
# According to mypy, this should be:# def structure_attrs(val: Any) -> Any:defstructure_attrs(val: Any, _: Any) ->Any:
ifisinstance(val, typ):
returnvalreturnconverter.structure_attrs_fromdict(val, typ)
returnstructure_attrsconverter.register_structure_hook_factory(has, allow_attrs_instances) # mypy complains here
Mypy complains when I do def structure_attrs(val: Any, _: Any) -> Any:
src/typed_settings/converters.py:77: error: Argument 2 to "register_structure_hook_factory" of "Converter"
has incompatible type "Callable[[Any], Callable[[Any, Any], Any]]";
expected "Callable[[Any], Callable[[Any], Any]]" [arg-type]
But pytest complains when I do def structure_attrs(val: Any) -> Any:
typed_settings.exceptions.InvalidValueError: structure_attrs() takes 1 positional argument but 2 were given
Fact of the matter is, the insides of cattrs aren't checked with Mypy since Mypy is far from being able to handle what we need at time this. So the type hints are essentially just inline type stubs. Hence the preponderence of Any.
Activity
Tinche commentedon Jul 4, 2022
I think you might be right, actually.
Fact of the matter is, the insides of cattrs aren't checked with Mypy since Mypy is far from being able to handle what we need at time this. So the type hints are essentially just inline type stubs. Hence the preponderence of
Any.Tinche commentedon Jul 4, 2022
@sscherfke I applied a fix to
main, check if it's good for you now?sscherfke commentedon Jul 4, 2022
I will try it. There might be other, similar places at well. I’ll check it.
Tinche commentedon Jul 4, 2022
Bring em forward and we'll iron them out.
Flesh out type annotations
sscherfke commentedon Jul 8, 2022
Looks like I need to create a PR .. 😬
sscherfke commentedon Jul 8, 2022
Maybe this?
chore(deps): Update cattrs requirement from <22.2,>=1.8 to >=1.8,<22.…
Flesh out type annotations