Skip to content

No way to alter dynamic default value help text representation #2099

@pocek

Description

@pocek

Before 78a62b3 it was possible to pass a default value in a form of a callable object with __str__ defined. An object's string representation made its way to the help text - a behavior which was actually a feature. Now it's always just (dynamic) which is fine for simple functions, but not very useful and limiting in case of callable objects. To showcase that this can be actually a useful feature, an example:

class EnvDefault:
    """A default which shows the actual value of an environment variable
    in the help text. This is different from envvar=.
    """
    def __init__(self, envvar, default):
        self.envvar = envvar
        self.default = default
    def __call__(self):
        return os.environ.get(self.envvar, self.default)
    def __str__(self):
        return str(self())

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions