-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add foundation for TypeVar defaults (PEP 696) #14872
Conversation
This comment has been minimized.
This comment has been minimized.
c3cc492
to
f63386b
Compare
This comment has been minimized.
This comment has been minimized.
f63386b
to
f2f5810
Compare
This comment has been minimized.
This comment has been minimized.
f2f5810
to
ccc0eef
Compare
This comment has been minimized.
This comment has been minimized.
ccc0eef
to
bca0afc
Compare
This comment has been minimized.
This comment has been minimized.
mypy/semanal.py
Outdated
# Similar to regular (user defined) type variables. | ||
self.process_placeholder( | ||
None, | ||
"Self upper bound", | ||
"Self upper bound or default", |
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.
Maybe better to have a separate message for the two cases?
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.
In this particular instance I believe it isn't even necessary to check it at all. For Self
the default
is always set to AnyType(TypeOfAny.from_omitted_generics)
and thus can't include a placeholder. I've split the calls in process_typevar_declaration
though.
Also noticed that I was missing these checks in process_paramspec_declaration
and process_typevartuple_declaration
which I added now.
This comment has been minimized.
This comment has been minimized.
e5d9c3c
to
6d94f22
Compare
This comment has been minimized.
This comment has been minimized.
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.
Looks good, one suggestion
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Thanks @JelleZijlstra! I'll take a closer look at my followup PR tomorrow. |
Done:
topic-pep-696
|
Start implementing PEP 696 TypeVar defaults. This PR
default
parameter toTypeVarLikeExpr
andTypeVarLikeType
.default
parameter.default
=>AnyType(TypeOfAny.from_omitted_generics)
.A followup PR will update the semantic analyzer and add basic tests for
TypeVar
,ParamSpec
, andTypeVarTuple
calls with adefault
argument. -> #14873Ref #14851