Skip to content

[suggestion] Use a custom type for help string instead of source code parsing.  #98

@Cnoor0171

Description

@Cnoor0171

An alternate suggestion to #93

Instead of parsing source code (which many will find surprising behavior), a cleaner and more intuitive approach would be to use a custom type that's capable of taking the extra meta information. This pattern is well established by both the standard library and other popular third party libraries like dataclass, sqlalchemy, pydantic etc. For example, when you declare a dataclass,

from dataclass import dataclass, field
@dataclass
class User:
    name: str = "John Doe"  # This is the normal way of setting the default
    password: str = field("p@ssw0rd", repr=False)  # This allows setting the default AND other properties

In case of tap, the declaration would look something like

from tap import Tap, Arg
class SimpleArgumentParser(Tap):
    language: str = 'Python'
    package: str = Arg('Tap', help="Package name")  # Now I can leave comments that don't affect behavior!! e.g.: pylint: disable=...

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions