Skip to content

Handle arg=<sentinel value> in stubgenc by generating an ellipsis default annotated as Incomplete - #22019

Open
edgarrmondragon wants to merge 3 commits into
python:masterfrom
edgarrmondragon:stubgen-sentinel
Open

edgarrmondragon wants to merge 3 commits into
python:masterfrom
edgarrmondragon:stubgen-sentinel

Conversation

@edgarrmondragon

Copy link
Copy Markdown
Contributor

mypy was generating stubs like def test(self, arg0: sentinel = ...) -> None: ..., where the sentinel annotation isn't really helpful.

Related:

@edgarrmondragon edgarrmondragon changed the title Handle arg=<sentinen value> in stubgenc Handle arg=<sentinel value> in stubgenc Sep 21, 2026
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
@edgarrmondragon edgarrmondragon changed the title Handle arg=<sentinel value> in stubgenc Handle arg=<sentinel value> in stubgenc by generating an ellipsis default annotated as Incomplete Sep 21, 2026
@edgarrmondragon
edgarrmondragon marked this pull request as ready for review September 21, 2026 18:58

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only stubgenc, should we do something similar for regular stubgen?

Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
@edgarrmondragon

Copy link
Copy Markdown
Contributor Author

This is only stubgenc, should we do something similar for regular stubgen?

It seems that it's handled by stubgenc in the --inspect-mode case:

mypy/mypy/stubgen.py

Lines 1811 to 1820 in dc8858f

if inspect:
ngen = InspectionStubGenerator(
module_name=mod.module,
known_modules=all_modules,
_all_=mod.runtime_all,
doc_dir=doc_dir,
include_private=include_private,
export_less=export_less,
include_docstrings=include_docstrings,
)

I've added both a testDefaultArgSentinel and testDefaultArgSentinel_inspect to check both cases. I don't think the former infers runtime default values, so that default case in unaffected.

dc8858f

@ilevkivskyi

Copy link
Copy Markdown
Member

@JukkaL @p-sawicki It looks like testConcurrentCircularNativeImports is flaky, see failure in https://github.com/python/mypy/actions/runs/35688997253/job/106621787371?pr=22019

Expected:
Actual:
  Traceback (most recent call last): (diff)
    File "driver.py", line 7, in <module> (diff)
      other_a = future_a.result(timeout=15) (diff)
    File "/opt/hostedtoolcache/Python/3.14.7/arm64-freethreaded/lib/python3.14t/concurrent/futures/_base.py", line 454, in result (diff)
      return self.__get_result() (diff)
             ~~~~~~~~~~~~~~~~~^^ (diff)
    File "/opt/hostedtoolcache/Python/3.14.7/arm64-freethreaded/lib/python3.14t/concurrent/futures/_base.py", line 396, in __get_result (diff)
      raise self._exception (diff)
    File "/opt/hostedtoolcache/Python/3.14.7/arm64-freethreaded/lib/python3.14t/concurrent/futures/thread.py", line 86, in run (diff)
      result = ctx.run(self.task) (diff)
    File "/opt/hostedtoolcache/Python/3.14.7/arm64-freethreaded/lib/python3.14t/concurrent/futures/thread.py", line 73, in run (diff)
      return fn(*args, **kwargs) (diff)
    File "/opt/hostedtoolcache/Python/3.14.7/arm64-freethreaded/lib/python3.14t/importlib/__init__.py", line 88, in import_module (diff)
      return _bootstrap._gcd_import(name[level:], package, level) (diff)
             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (diff)
    File "<frozen importlib._bootstrap>", line 1406, in _gcd_import (diff)
    File "<frozen importlib._bootstrap>", line 1371, in _find_and_load (diff)
    File "<frozen importlib._bootstrap>", line 1342, in _find_and_load_unlocked (diff)
    File "<frozen importlib._bootstrap>", line 938, in _load_unlocked (diff)
    File "<frozen importlib._bootstrap_external>", line 1061, in exec_module (diff)
    File "<frozen importlib._bootstrap>", line 491, in _call_with_frames_removed (diff)
    File "other_a.py", line 7, in <module> (diff)
      import other_b (diff)
  KeyError: 'other_b' (diff)

[out]
from _typeshed import Incomplete

def f(x: Incomplete = ...): ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel ideally we should generate a stub for the sentinel here and annotate the parameter as Incomplete | _MISSING.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants