tombulled / param

Enhanced function parameters
https://pypi.org/project/tombulled-param/
MIT License
0 stars 0 forks source link

DevLog #1

Closed tombulled closed 2 years ago

tombulled commented 2 years ago

Rename Field to Param? E.g:

def foo(name: str = Param(default="sam")):
    ...
tombulled commented 2 years ago

Rename decorator to @fields or @params? E.g:

@params
def say_hello(name: str = Param(default="sam")):
    ...
tombulled commented 2 years ago

Rename repo to param

tombulled commented 2 years ago

Wrapper function should return Field[T]

tombulled commented 2 years ago

Should expose param.get_params() E.g:

def get_params(func: Callable, /) -> List[Parameter]:
    ...

In here, every parameter is converted to a param.Parameter even if it doesn't have a default of param.Param.

Example 1:

def say_hello(name: str, message: str = Param(default="hello")):
    ...
>>> get_params(say_hello)
[
    Parameter(
        name="name",
        annotation=str,
        default=Missing,
        type=ParamType.POS_OR_KW,
    ),
    Parameter(
        name="message",
        annotation=str,
        default="hello",
        type=ParamType.POS_OR_KW,
    ),
]
tombulled commented 2 years ago

Should expose param.get_arguments().

def get_arguments(func: Callable, args: Tuple[Any], kwargs: Dict[str, Any]) -> Arguments:
    ...

Where:

@dataclass
class Arguments:
    args: Tuple[Any]
    kwargs: Dict[str, Any]
    arguments: Dict[str, Any]

Example:

def say_hello(name: str, message: str = Param(default="hello")):
    ...
>>> get_arguments(say_hello, ("bob",), {})
Arguments(
    args=("bob", "hello"),
    kwargs={},
    arguments={"name": "bob", "message": "hello"},
)
tombulled commented 2 years ago

Line 13 of fielded.py currently broken

tombulled commented 2 years ago

Add Description: Enhanced function parameters

tombulled commented 2 years ago

Should this library use arguments under the hood?

tombulled commented 2 years ago

Make param.get_params return Parameter objects containing the Paraminstances?

E.g.

@dataclass
class Parameter:
    name: str
    annotation: Any
    kind: ParameterKind
    spec: Param

Note: As Param() is a wrapper, the underlying class could be named different, e.g. ParameterSpecification

tombulled commented 2 years ago

Make enrich and parse private functions

tombulled commented 2 years ago

sentinels and enums currently sharing the same NoValue class

tombulled commented 2 years ago

__init__ should expose more:

tombulled commented 2 years ago

Rename ParameterKind to ParameterType

tombulled commented 2 years ago

enrich currently throws an exception without the function name

tombulled commented 2 years ago

get_arguments has wrong type hint for args, should be Tuple[Any, ...]

tombulled commented 2 years ago

Add a better usage example to the README, it currently makes the library seem pointless.

E.g:

from param import Param, params

@params
def get(url: str, params: dict = Param(default_factory=dict)):
    ...

Instead of:

def get(url: str, params: Optional[dict]):
    if params is None:
        params = dict()

    ...
tombulled commented 2 years ago

Rename models.Param to models.ParameterSpecification (but keep wrappers.Param as-is)?

tombulled commented 2 years ago

Make ParameterSpecification.default return Missing instead of throwing an error?

tombulled commented 2 years ago

Publish GH release

tombulled commented 2 years ago

Release to PyPI

tombulled commented 2 years ago

Add project metadata

tombulled commented 2 years ago

Add CI/CD