Giter Club home page Giter Club logo

pydargs's People

Contributors

antonsteenvoorden avatar gverstegen avatar rogiervandergeer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pydargs's Issues

Actions

Support actions, and action specific arguments, for example:

For example:

class Action1:
  a: int


class Action2:
  b: str


class Config:
  action: Union[Action1, Action2]

Which would allow either:
cmd Action1 --a 1
cmd Action2 --b abc

Lists

Allow lists (or sequences). Would be great if we can support two options for:

@dataclass
class Config:
  a: list[int]
  1. cmd --a 1 --a 2 --a 3
  2. cmd --a [1, 2, 3]

Where option 2 is probably best implemented as JSON.

We most likely need an option for the user to choose between one of the two instead of allowing both

Support bytes

As bytes("a string") also requires an encoding, we would need an encoding metadata field

Help

Allow the user to pass arguments to

  • ArgumentParser(...) to add help for the whole command,
  • As well as a description for each field.

pydargs considers `init=False` fields mandatory

Consider the following script:

from dataclasses import dataclass, field

from pydargs import parse


@dataclass
class Name:
    first_name: str
    last_name: str
    full_name: str = field(init=False)

    def __post_init__(self):
        self.full_name = f"{self.first_name} {self.last_name}"

parse(Name)

When called as python example.py --first-name John --last-name Doe, it errors: example.py: error: the following arguments are required: --full-name even though I can instantiate Name without supplying a value for full_name.

It's easily resolved in practice by giving full_name any default (e.g. an empty string) which is then immediately overwritten in __post_init__, so it's not a big issue. Still, it would be less surprising if pydargs and the dataclass itself agreed on which fields are mandatory.

Short option

Support a short option, such that

@dataclass
class Config:
   a_long_field: str 

can also be configured to allow -a

Unions

Support Unions.

MVP: support unions such that Optional[int] can have a None as default (i.e. all arguments are parsed as int)
Better: allow Union[int, str] that would parse "42" as int and "abc" as str.

Decide how to deal with configuration

Some of our desires features will need to accept configuration, for example the input method of lists / sequences.

We need to decide how we expect the user to provide this information. I see two options:

1. field metadata

Use the metadata of the dataclasses.field see here

@dataclass
class Config:
  a_field: str = field(metadata=dict(of="whatever", fields="we", will="need")

2. annotations

@dataclass
class Config:
  a_field: Annotated[str, dict(of="whatever", fields="we", will="need")]

But this may be difficult to do well in python3.9.

Nested dataclasses

Support dataclasses as an argument.

For example:

@dataclass
class Sub:
  a: int
  b: str

@dataclass
class Config:
  sub: Sub

It would be great if this could be supported with:

  1. --sub-a 42 --sub-b abc, as well as
  2. --sub '{"a": 42, "b": "abc"}

Booleans

Implement booleans, such that

@dataclass
class Config:
  b: bool

Creates two arguments: --b which sets b to True, and --no-b which sets b to False.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.