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
The changes introduced in #268 include a call to inspect.signature, which was done under the assuption that this function could parse all callables. Unfortunetly this is not correct, as inspect.signature will raise for callables that are defined in C (float, int, dict, etc.) and those are therefore no longer usable as Optional defaults.
Examples
In [1]: fromschemaimportSchema, OptionalIn [2]: dict_schema=Schema({
...: Optional('foo', default=dict): dict,
...: })
in [3]: dict_schema.validate({})
---------------------------------------------------------------------------ValueErrorTraceback (mostrecentcalllast)
<ipython-input-8-d42ec1bc3a4c>in<module>---->1DictSchema.validate({})
~/opt/anaconda3/envs/test/lib/python3.9/site-packages/schema.pyinvalidate(self, data, **kwargs)
429defaults=set(kforkinsifisinstance(k, Optional) andhasattr(k, "default")) -coverage430fordefaultindefaults:
-->431new[default.key] =_invoke_with_optional_kwargs(default.default, **kwargs) ifcallable(default.default) elsedefault.default432433returnnew~/opt/anaconda3/envs/test/lib/python3.9/site-packages/schema.pyin_invoke_with_optional_kwargs(f, **kwargs)
275276def_invoke_with_optional_kwargs(f, **kwargs):
-->277s=inspect.signature(f)
278iflen(s.parameters) ==0:
279returnf()
~/opt/anaconda3/envs/test/lib/python3.9/inspect.pyinsignature(obj, follow_wrapped)
3109defsignature(obj, *, follow_wrapped=True):
3110"""Get a signature object for the passed callable."""->3111returnSignature.from_callable(obj, follow_wrapped=follow_wrapped)
31123113~/opt/anaconda3/envs/test/lib/python3.9/inspect.pyinfrom_callable(cls, obj, follow_wrapped)
2858deffrom_callable(cls, obj, *, follow_wrapped=True):
2859"""Constructs Signature for the given callable object."""->2860return_signature_from_callable(obj, sigcls=cls,
2861follow_wrapper_chains=follow_wrapped)
2862~/opt/anaconda3/envs/test/lib/python3.9/inspect.pyin_signature_from_callable(obj, follow_wrapper_chains, skip_bound_arg, sigcls)
2393returnsigcls.from_callable(object)
2394else:
->2395raiseValueError(
2396'no signature found for builtin type {!r}'.format(obj))
2397ValueError: nosignaturefoundforbuiltintype<class'dict'>
Info
schema version: 0.7.5
python version: 3.9.7
The text was updated successfully, but these errors were encountered:
BvB93
pushed a commit
to nlesc-nano/CAT
that referenced
this issue
Dec 2, 2021
The changes introduced in #268 include a call to
inspect.signature
, which was done under the assuption that this function could parse all callables. Unfortunetly this is not correct, asinspect.signature
will raise for callables that are defined in C (float
,int
,dict
, etc.) and those are therefore no longer usable asOptional
defaults.Examples
Info
schema version: 0.7.5
python version: 3.9.7
The text was updated successfully, but these errors were encountered: