Module dollar_lambda.args
Expand source code +Browse git
"""
Defines the `Args` dataclass and associated functions.
@@ -33,7 +46,7 @@ Module dollar_lambda.args
import dataclasses
import typing
from dataclasses import Field, dataclass, fields
-from typing import Any, Callable, Iterator, Optional, Union
+from typing import Any, Callable, Iterator, Optional
from dollar_lambda.key_value import KeyValue, KeyValueTuple
from dollar_lambda.parser import Parser, done, flag, nonpositional, option, type_
@@ -43,7 +56,7 @@ Module dollar_lambda.args
def field(
help: Optional[str] = None,
metadata: Optional[dict] = None,
- type: Optional[Union[type, Callable[[str], Any]]] = None,
+ type: Optional["type | Callable[[str], Any]"] = None,
**kwargs,
) -> Field:
"""
@@ -55,7 +68,7 @@ Module dollar_lambda.args
An optional help string for the argument.
metadata : str
Identical to the `metadata` argument for [`dataclasses.field`](https://docs.python.org/3/library/dataclasses.html#dataclasses.field).
- type : Optional[Union[type, Callable[[str], Any]]]
+ type : Optional[type | Callable[[str], Any]]
A function that takes a string and returns a value just like the `type` argument for
[`ArgumentParser.add_argument`](https://docs.python.org/3/library/argparse.html#type).
@@ -218,7 +231,7 @@ Module dollar_lambda.args
@classmethod
def parse_args(
cls, *args, flip_bools: bool = True
- ) -> typing.Sequence[KeyValueTuple] | typing.Dict[str, Any]:
+ ) -> "typing.Sequence[KeyValueTuple] | typing.Dict[str, Any]":
"""
Parses the arguments and returns a dictionary of the parsed values.
"""
@@ -233,7 +246,7 @@ Module dollar_lambda.args
Functions
-def field(help: Optional[str] = None, metadata: Optional[dict] = None, type: Union[type, Callable[[str], Any], ForwardRef(None)] = None, **kwargs) ‑> dataclasses.Field
+def field(help: Optional[str] = None, metadata: Optional[dict] = None, type: Optional[ForwardRef('type | Callable[[str], Any]')] = None, **kwargs) -> dataclasses.Field
-
This is a thin wrapper around dataclasses.field
.
@@ -243,7 +256,7 @@ Parameters
- An optional help string for the argument.
metadata
: str
- Identical to the
metadata
argument for dataclasses.field
.
-type
: Optional[Union[type, Callable[[str], Any]]]
+type
: Optional[type | Callable[[str], Any]]
- A function that takes a string and returns a value just like the
type
argument for
ArgumentParser.add_argument
.
@@ -253,11 +266,12 @@ Returns
Expand source code
+Browse git
def field(
help: Optional[str] = None,
metadata: Optional[dict] = None,
- type: Optional[Union[type, Callable[[str], Any]]] = None,
+ type: Optional["type | Callable[[str], Any]"] = None,
**kwargs,
) -> Field:
"""
@@ -269,7 +283,7 @@ Returns
An optional help string for the argument.
metadata : str
Identical to the `metadata` argument for [`dataclasses.field`](https://docs.python.org/3/library/dataclasses.html#dataclasses.field).
- type : Optional[Union[type, Callable[[str], Any]]]
+ type : Optional[type | Callable[[str], Any]]
A function that takes a string and returns a value just like the `type` argument for
[`ArgumentParser.add_argument`](https://docs.python.org/3/library/argparse.html#type).
@@ -344,6 +358,7 @@ Classes
Expand source code
+Browse git
@dataclass
class Args:
@@ -430,7 +445,7 @@ Classes
@classmethod
def parse_args(
cls, *args, flip_bools: bool = True
- ) -> typing.Sequence[KeyValueTuple] | typing.Dict[str, Any]:
+ ) -> "typing.Sequence[KeyValueTuple] | typing.Dict[str, Any]":
"""
Parses the arguments and returns a dictionary of the parsed values.
"""
@@ -439,18 +454,19 @@ Classes
Static methods
-def parse_args(*args, flip_bools: bool = True) ‑> Union[Sequence[KeyValueTuple], Dict[str, Any]]
+def parse_args(*args, flip_bools: bool = True) -> Union[Sequence[KeyValueTuple], Dict[str, Any]]
-
Parses the arguments and returns a dictionary of the parsed values.
Expand source code
+Browse git
@classmethod
def parse_args(
cls, *args, flip_bools: bool = True
-) -> typing.Sequence[KeyValueTuple] | typing.Dict[str, Any]:
+) -> "typing.Sequence[KeyValueTuple] | typing.Dict[str, Any]":
"""
Parses the arguments and returns a dictionary of the parsed values.
"""
@@ -458,7 +474,7 @@ Static methods
-def parser(flip_bools: bool = True) ‑> Parser[Sequence[KeyValue[typing.Any]]]
+def parser(flip_bools: bool = True) -> Parser[Sequence[KeyValue[typing.Any]]]
-
Returns a parser for the dataclass.
@@ -487,6 +503,7 @@
Examples
Expand source code
+Browse git
@classmethod
def parser(cls, flip_bools: bool = True) -> Parser[Sequence[KeyValue[Any]]]:
@@ -527,6 +544,52 @@ Examples