Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.2k
Refactor_typing_extra
module#10725
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
cloudflare-workers-and-pagesbot commentedOct 27, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Deploying pydantic-docs with |
Latest commit: | 5a43b8d |
Status: | ✅ Deploy successful! |
Preview URL: | https://b118d254.pydantic-docs.pages.dev |
Branch Preview URL: | https://refactor-typing-extra.pydantic-docs.pages.dev |
codspeed-hqbot commentedOct 27, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
CodSpeed Performance ReportMerging#10725 willnot alter performanceComparing Summary
|
github-actionsbot commentedOct 27, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Coverage reportClick to see where and how coverage changed
This report was generated bypython-coverage-comment-action |
279daa8
toc68a904
Comparec68a904
to591dde0
Compare591dde0
to0faf9b6
Comparea5ef806
to088b5c2
Comparepydantic/_internal/_repr.py Outdated
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.
Thisdisplay_as_type
function needs to be refactored, as it is relatively expensive to recursively check forget_origin
,get_args
, etc. It is currently used:
- In
FieldInfo.__repr_args__
, to make a string representation of theannotation
attribute. This can be kept. - In
get_type_ref
, called for each arg of a parametrized type. We should find a simpler way to generate a core schema reference.
088b5c2
to291dd9b
CompareShould we be concerned about some of the minor performance regressions we see for schema building here? https://codspeed.io/pydantic/pydantic/branches/refactor-typing-extra |
My assumption is that the small regression comes from the fact that in hot functions ( I think the real problem is that we should find a way to avoid calling these functions so many times, this is what I'm working on currently as part of#10297 |
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.
Wow, nice work@Viicos. Things feel much cleaner in the internal type management department with this PR. Left some general feedback 👍
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
@@ -184,7 +184,7 @@ def _get_caller_frame_info(depth: int = 2) -> tuple[str | None, bool]: | |||
DictValues: type[Any] = {}.values().__class__ | |||
def iter_contained_typevars(v: Any) -> Iterator[TypeVarType]: | |||
def iter_contained_typevars(v: Any) -> Iterator[TypeVar]: |
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.
Could you explain this change, briefly? Thanks!
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.
TypeVarType
was defined as an alias toAny
as a workaround, because mypy could not understand something like this:
TypeVarType:TypeAlias=TypeVar
But for pyright (and maybe mypy as of today), it is perfectly fine to useTypeVar
as type annotations, it behaves as any other type
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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.
Nice, thanks for incorporating the feedback.
Happy to merge this now, given that we're going to see perf improvements bounce back up with#10769
5b7c290
intomainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Change Summary
_typing_extra
module to:some_obj is typing(_extensions).SomeType
which can break at any time iftyping_extensions
backports some changes from Python, in which casetyping.SomeType is not typing_extensions.SomeType
.is_*
functions (e.g.is_newtype
,is_classvar
).is_classvar_annotation
function, that should be used in most cases. This function handlesClassVar
being wrapped inAnnotated
, and also stringified annotations.all_literal_values
toliteral_values
, replacing the unusedliteral_values
function. When we drop support for Python 3.8, replace usage with a plainget_args
.is_dataclass
function,dataclasses.is_dataclass
provides a type guard return annotation.Related issue number
Checklist