-
|
When both Perhaps, when we add |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
I'm not sure i understand the question/problem. A minimal example of a cli and the situations in which you'd expect a specific value or not would be very helpful. Setting a default implies Based on your other issue, i wonder if this is relating to a more complex/dynamic default and you're perhaps looking for default value fallbacks? |
Beta Was this translation helpful? Give feedback.
-
|
Here is an MRE: from dataclasses import dataclass
from typing import Annotated
import cappa
@dataclass
class Test:
num1: Annotated[int, cappa.Arg(default=1, required=False)]
num2: Annotated[int | None, cappa.Arg(default=2, required=False)]
def __call__(self):
if self.num1:
print(self.num1)
if self.num2:
print(self.num2)
cappa.invoke(Test)By default, In my opinion, we should defer the evaluation of
Here is another scenario: By default, num2 always returns empty/None. This seems to align with what I described above, but I'm not sure if this is an issue or expected. |
Beta Was this translation helpful? Give feedback.
Yea i'm not sure what purpose
default=2has in your original example, particularly if you're looking forNone. Why would you not be setting the default to None versus 2 here?On "Optional" types we do infer
Noneas a default (by default) if you have no explicit default provided, but any provided default is meant to imply that the user doesn't want that behavior and chooses their own.For
num2: Annotated[int | None, cappa.Arg(default=2, required=False)] = Nonedefaulting toNone, this seems more like a bug. i'd consider any explicit values provided to cappa machinery (e.g. Arg) to have higher precedence than more generic sources of information like the dataclass-level default/default_facto…