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
It would be great to be able to define the key type and value type generically like Dict[str, str], e.g.:
frombenedictimportbenedictfrompydanticimportTypeAdapter# just used for deep-checking equivalent to isinstance()defexample_function() ->benedict[str, int]:
returnbenedict({'abc': 123})
TypeAdapter(benedict[str, int]).validate_python(example_function())
# this should succeed
But also separately I think it would be cool to be able to use them like TypedDicts as well, with hardcoded (total=True/False keys) that are always expected to be present, e.g.:
frombenedictimportTypedBenedictclassMyCustomBenedict(TypedBenedict, total=True):
abc: intxyz: strtest1=MyCustomBenedict({'abc': 123, 'xyz': 'test string'})
# this should worktest2=MyCustomBenedict({'abc': 123, 'notallowed': 'something else'})
# this should raise an error because notallowed is not present in the spec
The text was updated successfully, but these errors were encountered: