Skip to content

Include {name} in default format string #53

@Evidlo

Description

@Evidlo

A small quality-of-life improvement would be if the default format string included the name attribute by default.

>>> t = Timer('foobar')
>>> t.start()
>>> time.sleep(1)
>>> t.stop()
foobar elapsed time: 1.000 seconds
>>> t = Timer()
>>> t.start()
>>> time.sleep(1)
>>> t.stop()
Elapsed time: 1.000 seconds

This might be achieved with the following __post_init__ function:

    def __post_init__(self):
        if self.name is None:
            self.text = "Elapsed time: {:0.4f} seconds"
        else:
            self.text = "{name} elapsed time {:0.4f} seconds"

Alternatively, name could just have a non-None default value (e.g. "Timer" or "Elapsed").

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions