Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add attribute exclusion mecanism #92

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zephvr
Copy link
Contributor

@zephvr zephvr commented Jul 17, 2022

Hi
I would like to propose this PR to fulfill #75 request

Sadly attributes cannot be decorated, so I introduce a new syntax that allow an attribute to be ignore.
Simply commenting #聽tap: ignore will ignore the attribute

With it this code

# code.py
from typing import ClassVar
from tap import Tap

class Args(Tap):
    attr_to_ignore: str  # tap: ignore
    """A comment for my IDE"""
    classvar_attr: ClassVar[str]
    hello: bool = True

args = Args().parse_args()

Gives

$ python code.py -h
usage: code.py [--hello] [-h]

options:
  --hello     (bool, default=True)
  -h, --help  show this help message and exit

Tell me if there is anything I can improve on this PR 馃槃

@martinjm97
Copy link
Collaborator

Hey @zephvr,

Thank you so much for the PR and sorry for the massive delay in response. We really like the overall setup. In general, we don't want the behavior of the Tap object to change based on comments, so we'd argue against # tap: ignore. We also think because ClassVar is not extremely well known, it could be confusing to users for that argument not to show up in the parsed object. One option is to have a thin wrapper around ClassVar called TapIgnore.

We're imagining something that looks like:

# code.py
from tap import Tap, TapIgnore

class Args(Tap):
    """A comment for my IDE"""
    attr_to_ignore: TapIgnore[str]
    classvar_attr: TapIgnore[str]
    hello: bool = True

args = Args().parse_args()

We would appreciate if you could make these changes, but ideally, we'll do it eventually.

Thanks,
Jesse and Kyle

@rainyl
Copy link

rainyl commented Jul 31, 2023

Well, I do like this feature, any progress?

@rainyl rainyl mentioned this pull request Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants