-
Notifications
You must be signed in to change notification settings - Fork 6
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
Ability to parse JSON with arbitrary keys #19
Comments
Not at the moment. As you demonstrated trycast currently requires that there be no extra keys when checking assignability to a TypedDict type. However I actually think trycast's behavior should be changed to allow extra keys by default. Consider the following code which typechecks successfully with mypy: from typing import *
class Packet(TypedDict):
type: str
payload: str
class PacketWithExtra(Packet):
extra: str
p = PacketWithExtra(type='hello', payload='v1', extra='english')
p2: Packet = p
print(p2) Above, the value |
I'm about to be on vacation for a week so I won't have any bandwidth to work on this feature myself in the short term. @jaredculp if you (or anyone else) is interested in making a PR, I may be able to get it merged more quickly (before I leave on Saturday). |
@davidfstr happy to try! Can't get a working dev environment set up on my mac (also tried docker):
|
You're probably running into this issue where Cython 3 broke the build process of PyYAML 5.x Try this:
|
The ability to parse JSON with extra keys that are not in the original TypedDict definition will be in trycast 1.1.0, when it is released, probably in a day or two. |
In particular: * Tests: Fix to recognize TypedDict values with extra keys - References #19
In particular: * Tests: Fix to recognize TypedDict values with extra keys - References #19
In particular: * Tests: Fix to recognize TypedDict values with extra keys - References #19
In particular: * Tests: Fix to recognize TypedDict values with extra keys - References #19
Is it possible to enforce the presence of certain keys but ignore all others? My use case is parsing JSON payloads from an event bus where I want to ignore fields that may be present but that I don't care to include in the
TypedDict
.This functionality would be similar to json-schema's
additionalProperties: true
keyword.For example:
The text was updated successfully, but these errors were encountered: