Skip to content

Commit

Permalink
sistana: format
Browse files Browse the repository at this point in the history
  • Loading branch information
GreyElaina committed Oct 9, 2024
1 parent a25ca9d commit d8149ab
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/arclet/alconna/sistana/fragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
if TYPE_CHECKING:
from nepattern import BasePattern


@dataclass(**safe_dcls_kw(slots=True))
class Fragment(_Fragment):
type: Some[Any] = None
Expand Down Expand Up @@ -50,8 +51,9 @@ def _validate(v: Segment):
return True

self.validator = _validate

if self.cast:

def _transform(v: Segment):
return convert(str(v), t)

Expand All @@ -75,6 +77,7 @@ def apply_nepattern(self, pat: BasePattern | None = None, capture_mode: bool = F
else:
self.capture = RegexCapture(pat.alias) # type: ignore
else:

def _validate(v: Segment):
if isinstance(v, (Quoted, UnmatchedQuoted)):
if isinstance(v.ref, str):
Expand All @@ -87,6 +90,7 @@ def _validate(v: Segment):
self.validator = _validate

if self.cast:

def _transform(v: Segment):
return pat.validate(str(v)).value()

Expand Down
2 changes: 1 addition & 1 deletion src/arclet/alconna/sistana/model/fragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ def assert_fragments_order(fragments: Iterable[_Fragment]):
if frag.variadic:
if frag.default is not None:
raise ValueError("A variadic fragment cannot have a default value.")

variadic_exists = True
2 changes: 1 addition & 1 deletion src/arclet/alconna/sistana/model/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def update(self, key: tuple[str, ...], pattern: SubcommandPattern):
def get_subcommand(self, context: SubcommandPattern, val: str):
if val in context._subcommands_bind:
return context._subcommands_bind[val], None

if context._compact_keywords is not None:
prefix = context._compact_keywords.longest_prefix(val).key
if prefix is not None:
Expand Down

0 comments on commit d8149ab

Please sign in to comment.