Handle arg=<sentinel value> in stubgenc by generating an ellipsis default annotated as Incomplete - #22019
Handle arg=<sentinel value> in stubgenc by generating an ellipsis default annotated as Incomplete#22019edgarrmondragon wants to merge 4 commits into
Incomplete#22019Conversation
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
9afa235 to
45e6b87
Compare
Incomplete
JelleZijlstra
left a comment
There was a problem hiding this comment.
This is only stubgenc, should we do something similar for regular stubgen?
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
It seems that it's handled by stubgenc in the Lines 1811 to 1820 in dc8858f I've added both a |
|
@JukkaL @p-sawicki It looks like |
| [out] | ||
| from _typeshed import Incomplete | ||
|
|
||
| def f(x: Incomplete = ...): ... |
There was a problem hiding this comment.
I feel ideally we should generate a stub for the sentinel here and annotate the parameter as Incomplete | _MISSING.
There was a problem hiding this comment.
I feel ideally we should generate a stub for the sentinel here and annotate the parameter as
Incomplete | _MISSING.
Do you mean specifically for private sentinel variable? AFAICT stubgen skips runtime introspection of types for private variables:
Lines 910 to 917 in b645e06
I can see the value in generating Incomplete | MISSING though, i.e. doing runtime introspection of a public sentinel.
There was a problem hiding this comment.
Could go either way with private sentinels, but definitely for public sentinels we should be doing this.
Even for private sentinels, as a typeshed maintainer I'd prefer having the sentinel in the stub for code like this. Others might disagree though.
There was a problem hiding this comment.
Done in e82ca74, but I do have a question about generating backward compatible stubs. A sentinel can be created using
builtins.sentinel/sentinel: Python 3.15+typing_extensions.sentinel: typing_extensions 4.16.0+typing_extensions.Sentinel: typing_extensions 4.14.0+, soft deprecated in 4.16.0
but perhaps a stub should be as version-agnostic as possible? That is, use typing_extensions.Sentinel?
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
| # dotted form (not add_name) since a module constructing a | ||
| # sentinel will itself have already imported the bare `sentinel` | ||
| # name, which would otherwise force an alias here. | ||
| return "typing_extensions.sentinel" |
There was a problem hiding this comment.
This is typing-extensions 4.16.0+. Should we bump the min requirement here?
Lines 56 to 57 in b645e06
mypy was generating stubs like
def test(self, arg0: sentinel = ...) -> None: ..., where thesentinelannotation isn't really helpful.Related:
sentineldefaults, but notobject()markers #22013 (comment)