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

Make instanceof schema work with arbitrary types #5947

Merged
merged 1 commit into from
May 31, 2023

Conversation

dmontagu
Copy link
Contributor

@dmontagu dmontagu commented May 31, 2023

Inspired by #5581 (reply in thread).

One of the original motivations (and I'm pretty sure requested in an issue I closed because I thought it was addressed..) of InstanceOf was to be able to remove the need for arbitrary_types_allowed=True in the config by using this annotation, and only needing to use it on the actual arbitrary types. However as @adriangb noted, this doesn't currently work because it tries to generate the schema for loading from JSON.

This change allows that to fail, in which case a standard is_instance_schema is used. This keeps some of the functionality behaving nicely (namely, InstanceOf[Sequence[str]] remains compatible with JSON loading, etc.), but resolves one of the actual reasons this InstanceOf type was introduced.

I've also added it to the exports; I'm assuming its lack of inclusion was an oversight, but if we purposely weren't exporting it for the sake of not making it a "public API", then I guess we can remove it again, but I think these types merit inclusion in the public API.

Selected Reviewer: @adriangb

@dmontagu
Copy link
Contributor Author

please review

@adriangb adriangb merged commit cf48b1a into main May 31, 2023
53 checks passed
@adriangb adriangb deleted the instance-of-arbitrary-types branch May 31, 2023 15:17
Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adriangb
Copy link
Member

Too late!

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

Successfully merging this pull request may close these issues.

None yet

3 participants