Skip to content

add Callable[[], str] type annotaion for configureOutput prefix #241

Description

@n-arakawa

Currently, the prefix parameter of the configureOutput function is annotated as follows:
prefix: Union[str, Literal[Sentinel.absent]] = Sentinel.absent,

Defining a prefix as a function results in a type validation error.

$ cat /tmp/a.py 
#!/usr/bin/env python3
from icecream import ic
from datetime import datetime

ic.configureOutput(prefix=lambda: datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
ic("hello")

$ mypy /tmp/a.py 
/tmp/a.py:5: error: Argument "prefix" to "configureOutput" of "IceCreamDebugger" has incompatible type "Callable[[], str]"; expected "str | Literal[Sentinel.absent]"  [arg-type]
Found 1 error in 1 file (checked 1 source file)


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions