PEP 737 – Unify type name formatting

I prepared a PEP 737 change to address comments.

Changes:

  • Add %N and %#N formats.
  • The %T and %#T formats now expect an object instead of a type.
  • Exchange %T and %#T formats: %T now formats the fully qualified name.
  • Recommend using the type fully qualified name in error messages and in __repr__() methods when writing new code.

If __main__ is omitted, is there a risk to have other types with the same short name in other modules? Does "__main__." makes the type unambiguous?

Another attribute name which was not proposed so far: type.__fullname__ :slight_smile:

I updated the PEP to recommend using the fully qualified name when writing new code. I modified %T format to use the fully qualified name.

In my update, I made it explicit: I would like to modify the whole stdlib to no longer truncate type names. Type names longer than 100 characters are unlikely, so this specific change should not affect anyway in practice.

I’m thinking about Python/formatter_unicode.c which uses a regular specification for format() string. The grammar of this specification can be found in the Python documentation.