Skip to content

Add flag to reveal simpler types#20854

Closed
ilevkivskyi wants to merge 3 commits into
python:masterfrom
ilevkivskyi:simple-reveal
Closed

Add flag to reveal simpler types#20854
ilevkivskyi wants to merge 3 commits into
python:masterfrom
ilevkivskyi:simple-reveal

Conversation

@ilevkivskyi

Copy link
Copy Markdown
Member

Something that always bothered me is that our revealed types are verbose. Sometimes they are painful to visually parse (especially for complex types). Here I propose to add a flag that for more clean/compact revealed types. With just few tweaks a typical length of a revealed type is reduced by ~half.

I know this may sometimes cause ambiguous types, but IMO such situations are very rare. We can polish this if people will like it, and maybe make the default in a distant future.

@ilevkivskyi ilevkivskyi marked this pull request as ready for review February 21, 2026 01:26
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@ilevkivskyi

Copy link
Copy Markdown
Member Author

@JukkaL Any objections to this? This makes long revealed types much readable.

@JukkaL

JukkaL commented Feb 23, 2026

Copy link
Copy Markdown
Collaborator

I need to think about this. One of the use cases of reveal_type is to investigate what a non-specific type name which could be defined in any number of modules actually refers to. In large codebases it's quite common to have multiple classes with the same short name. It might be better to just simplify builtins prefixes and maybe TypeVar prefixes as well, as these are unlikely to be confusing and will account for a large fraction of the noise probably.

@ilevkivskyi

Copy link
Copy Markdown
Member Author

As discussed offline, we are going to:

  • Split this into few smaller PRs
  • Keep full names for everything non-builtin
  • Make this the default behavior (no public flags, just an internal flag to simplify migrating tests)

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.

2 participants