-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Support compiled patterns in protected_namespaces
#10522
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
Conversation
Deploying pydantic-docs with
|
| Latest commit: |
35804ff
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d4c38ffd.pydantic-docs.pages.dev |
| Branch Preview URL: | https://support-re-for-protected-ns.pydantic-docs.pages.dev |
CodSpeed Performance ReportMerging #10522 will not alter performanceComparing Summary
|
| if ann_name.startswith(protected_namespace): | ||
| ns_violation: bool = False | ||
| if isinstance(protected_namespace, Pattern): | ||
| ns_violation = protected_namespace.match(ann_name) is not None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is match better than fullmatch here? I think match might be equally capable and more practical (don't need to include .* on the end to serve as a prefix match I guess), just want to make sure you've thought about it and decided to go with match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question - I think match is more practical, as you can use special characters (ex: ^<pattern>$) to basically ensure fullmatch behavior, whereas fullmatch does that by default and thus offers less customizability 👍
Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
Merge branch 'support-re-for-protected-ns' of https://github.com/pydantic/pydantic into support-re-for-protected-ns
ConfigDict.protected_namespacesnow supports matching on compiled patterns.Whereas we used to only support prefix check for
strtype protected namespaces, this now expands the customizability of a protected namespace significantly.