-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Blacklist default globals to support exotic user code with __ prefixed annotations
#10136
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: |
fca234c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6b878348.pydantic-docs.pages.dev |
| Branch Preview URL: | https://blacklist.pydantic-docs.pages.dev |
CodSpeed Performance ReportMerging #10136 will not alter performanceComparing Summary
|
pydantic/_internal/_typing_extra.py
Outdated
| def _remove_default_globals_from_ns(namespace: dict[str, Any]) -> dict[str, Any]: | ||
| """Remove default globals like __name__, __doc__, etc that aren't needed for type evaluation.""" | ||
| return {k: v for k, v in namespace.items() if not k.startswith(('__', '@'))} | ||
| return {k: v for k, v in namespace.items() if not k.startswith('@') and k not in _DEFAULT_GLOBALS} |
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.
I'm wondering, @ was taken from pytest-examples but is it really possible to have something starting with that in the namespace? @.* isn't a valid identifier
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, yeah, I saw lots of vars starting with @ in the module namespace when I was running pytest, but perhaps that's not important for real applications. I guess I'm inclined to keep it bc it seems like the performance drawback is negligible, and it ensures the namespace is pretty clean.
|
Actually, I'd like to wait on merging this, I'm seeing this slow down the |
__ prefixed annotations
|
Alright, removing the double check made it such that we're not seeing any significant performance changes. Going to merge :). |
This way, if someone uses something like
__test__as a type annotation, we don't remove that from the namespace.Contributing to #10074