Skip to content

str-format for fill and align specifiers #18800

Open
@jack-tutor

Description

@jack-tutor

Feature

The fill and align string format specifiers do not currently have type checking, but are not supported by all types. Specifically, None does not support them.

Pitch

I ran into a bug where an optional type was being passed to string formatting using <. This would succeed most of the time, but error if the value was None:

>>> "{:<2}".format(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported format string passed to NoneType.__format__

It would be great if mypy would catch this code as a type violation.

I attempted to implement here: #18799 but this was more challenging than I anticipated and I am a first time contributor.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions