Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.2k
FixNameError
when usingvalidate_call
with PEP 695 on a class#10380
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
codspeed-hqbot commentedSep 11, 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#10380 willnot alter performanceComparing Summary
|
github-actionsbot commentedSep 11, 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.
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.
LGTM overall, just a few change requests :).
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 work, thanks!!
899ff2c
intopydantic:mainUh oh!
There was an error while loading.Please reload this page.
kc0506 commentedSep 13, 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.
@sydney-runkle I think the nested scope issues here are different from the case of from __future__importannotationsclassA[T:int](BaseModel):defg1(self):returnTypeAdapter(list[T])defg2(self):@validate_calldeff()->T: ... When calling On the other hand, the So currently I guess the best we could do is to make sure things work without |
Gotcha. My suggestion was that we could add a |
kc0506 commentedSep 13, 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.
importinspectimportsysfrompydantic._internalimport_typing_extra# analogy to `validate_call`, we want to access `a` in this functiondefapi():# ! `f` is NOT in stack# print([f.function for f in inspect.stack()]) # ['api', 'g', '<module>']# print(sys._getframe(1).f_code.co_name) # 'g'# print(sys._getframe(2).f_code.co_name) # '<module>'# parent_depth should add 1 because `parent_frame_namespace` is pushed to call stackprint('ns of g:',_typing_extra.parent_frame_namespace(parent_depth=2))deff():a=1defg1():api()defg2():aapi()returng1,g2g1,g2=f()g1()# ns of g: {}g2()# ns of g: {'a': 1} Here is a simple demo. My point is that by the time |
Uh oh!
There was an error while loading.Please reload this page.
Change Summary
This PR fixes the
NameError
whenfrom __future__ import annotations
and we callvalidate_call
inside a class definition with PEP 695:However, calling
validate_call
in nested scopes will still throwNameError
. This is probably due toparent_frame_namespace
. Example:Related issue number
fix#10150
Checklist