Skip to content

Conversation

sydney-runkle
Copy link
Contributor

@sydney-runkle sydney-runkle commented Aug 14, 2024

This way, if someone uses something like __test__ as a type annotation, we don't remove that from the namespace.

Contributing to #10074

@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Aug 14, 2024
Copy link

cloudflare-workers-and-pages bot commented Aug 14, 2024

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: fca234c
Status: ✅  Deploy successful!
Preview URL: https://6b878348.pydantic-docs.pages.dev
Branch Preview URL: https://blacklist.pydantic-docs.pages.dev

View logs

Copy link

codspeed-hq bot commented Aug 14, 2024

CodSpeed Performance Report

Merging #10136 will not alter performance

Comparing blacklist (fca234c) with main (9d55365)

Summary

✅ 17 untouched benchmarks

@sydney-runkle sydney-runkle requested a review from Viicos August 14, 2024 18:39
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}
Copy link
Member

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

Copy link
Contributor Author

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.

@sydney-runkle
Copy link
Contributor Author

Actually, I'd like to wait on merging this, I'm seeing this slow down the get_cls_types_namespace function significantly. Perhaps I'll remove the @, or at least consider the effects.

@sydney-runkle sydney-runkle changed the title Blacklist default globals to support exotic user code Blacklist default globals to support exotic user code with __ prefixed annotations Aug 15, 2024
@sydney-runkle
Copy link
Contributor Author

Alright, removing the double check made it such that we're not seeing any significant performance changes. Going to merge :).

@sydney-runkle sydney-runkle enabled auto-merge (squash) August 15, 2024 00:45
Copy link
Contributor

github-actions bot commented Aug 15, 2024

Coverage report

This PR does not seem to contain any modification to coverable code.

@sydney-runkle sydney-runkle merged commit 7abafa4 into main Aug 15, 2024
59 checks passed
@sydney-runkle sydney-runkle deleted the blacklist branch August 15, 2024 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes-fix Used for bugfixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants