-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore additional properties from input when deserializing to TypedDict #565
Comments
Hi, the purpose of apischema is to be the best possible library 😄 Actually, this behavior of Because, the current behavior can still be useful, and in order to mitigate the breaking change, I think I will add a setting to toggle it, something like Waiting for the release, here is a quick workaround: {
k: v
for k, v in deserialize(PersonTypedDict, data, additional_properties=True).items()
if k in PersonTypedDict.__annotations__
} |
Thanks for considering this use case. PEP 589 actually says additional keys in the TypedDict should raise an error by type checkers.
The sentence you mentioned says i.e. additional keys in the constructor, as well as in assignments as seen in the previous paragraph, should generate an error from a type checker. I know it's going to be a breaking change if you change the current behavior of apischema, but just wanted to give you a heads up. |
Also, since I'm already taking about breaking changes |
I've no issue with breaking change, as long as it's well justified (it is the case here), and its impact is low enough; I don't know how many people rely on this behavior, but it should not be a lot, and the global setting makes it easy to upgrade. Actually, But you are right, this setting name is quite ambiguous and should be refined. I prefer By the way, Thank you for bringing this discussion to the table, things seems way clearer now. (Yes, closing the issue was a misclick) |
Cool! I see JSON schema uses the term allow for additional properties that can be included beyond what's declared in the schema, which is something not possible for dataclasses for example. This is the behavior I was calling "include" above. The way I see it:
And what's the difference between I see how |
I see how
EDIT: Maybe change * According to PEP 589, these should not be allowed anyway. |
That's not exactly true, because of
I have renamed
Object types like dataclasses can have Does the table above seem ok to you? |
So Thanks a lot for thinking this through. |
Hi 👋
I have the intention to use apischema to map between an input
dict
and an outputdict
using aTypedDict
that defines the output format and aliases and conversions that need to happen from the input. Basically mapping between what I receive from one API to what I should send to another API. Not sure if that's one use case that fits apischema's purpose.To achieve this, I'd like to be able to ignore additional properties from the input. I see this works as I expected for
dataclass
es, but not forTypeDict
s:I expected the output of the second deserialize to be
{'first_name': 'John'}
instead.The text was updated successfully, but these errors were encountered: