Skip to content

Use Annotated to add aliases to options #100

@richieadler

Description

@richieadler

The documentation gives an example of how to create aliases:

def echo(*text:Parameter.REQUIRED,
         prefix:'p'='', suffix:'s'='', reverse:'r'=False, repeat:'n'=1):
    ...

This, however, causes most linters to warn:

Unresolved reference 'p'

for all the aliases thus defined.

Since Python 3.9, typing.Annotated is available to add metadata to annotations, so this could be defined as

def echo(*text:Parameter.REQUIRED,
         prefix: Annotated[str, 'p'] ='', 
         suffix: Annotated[str, 's'] = '', 
         reverse: Annotated[str, 'r'] = False, 
         repeat: Annotated[int, 'n'] = 1,
):
    ...

and linters wouldn't complain.

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