python / python/mypy

[stubgen] Nested classes in `NamedTuple`s are not produced

Open
#15,752 0 comments 0 reactions 1 assignee View on GitHub

@sobolevn is already working on this.

Since Jul 23, 2023.

bug topic-named-tuple topic-stubgen
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Consider this code:

from typing import NamedTuple

class A(NamedTuple):
    class B: ...

In runtime you can freely access it:

>>> from typing import NamedTuple
>>> 
>>> class A(NamedTuple):
...     class B: ...
... 
>>> A.B
<class '__main__.A.B'>

But, stubgen does ignore it:

» stubgen ex.py && bat out/ex.pyi
Processed 1 modules
Generated out/ex.pyi
───────┬───────────────────────────────────────────────────────────────────────────────────
       │ File: out/ex.pyi
───────┼───────────────────────────────────────────────────────────────────────────────────
   1   │ from typing import NamedTuple
   2   │ 
   3   │ class A(NamedTuple): ...
───────┴───────────────────────────────────────────────────────────────────────────────────

This needs to be fixed.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.