Skip to content
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

Support partial TypedDicts #403

Open
1 task done
skeggse opened this issue Sep 11, 2023 · 1 comment
Open
1 task done

Support partial TypedDicts #403

skeggse opened this issue Sep 11, 2023 · 1 comment

Comments

@skeggse
Copy link

skeggse commented Sep 11, 2023

Things to check first

  • I have searched the existing issues and didn't find my feature already requested there

Feature description

Following up on #376:

There isn't a standard way in Python's type hints system to express that a TypedDict should permit fields other than those explicitly enumerated.

I don't see a reason for the stdlib to add that functionality; my read is that it's largely targeted at static typecheckers like mypy and pyright, and during static analysis you have no reason to model extra fields. For runtime type checking, however, it's very useful to be able to say that a TypedDict should have this subset of fields, in case an external library adds new fields.

Is there any room in typeguard to implement a non-standard flag or option to indicate that a TypedDict should be allowed to have extra fields? Or a place to set a global configuration option?

Use case

This is quite relevant to my use-case, because the third-party in question has been adding a new field basically every week for the past several months. It's looking like typeguard isn't quite the right tool for the job, though it's helped us catch API regressions too, so I'm a little hesitant to rip it out.

@d-k-bo
Copy link

d-k-bo commented Oct 22, 2023

There isn't a standard way in Python's type hints system to express that a TypedDict should permit fields other than those explicitly enumerated.

I don't see a reason for the stdlib to add that functionality;

This is actually a recurring suggestion and there seems to be some interest to add this option. See also https://discuss.python.org/t/add-to-typeddict-new-argument-for-extra-keys/32526.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants