-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support msgspec defined classes as source classes for cappa.
- Loading branch information
Showing
10 changed files
with
366 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# Changelog | ||
|
||
## 0.19 | ||
|
||
### 0.19.0 | ||
|
||
- feat: Add support for `msgspec` based class definitions. | ||
|
||
## 0.18 | ||
|
||
### 0.18.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import example | ||
import pytest | ||
|
||
import example | ||
|
||
|
||
def test_help(): | ||
with pytest.raises(SystemExit): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Optional | ||
|
||
import cappa | ||
import msgspec | ||
from typing_extensions import Annotated | ||
|
||
from tests.utils import backends, parse | ||
|
||
|
||
class PydanticCommand(msgspec.Struct): | ||
name: str | ||
foo: Annotated[int, cappa.Arg(short=True)] | ||
|
||
|
||
@backends | ||
def test_base_model(backend): | ||
result = parse(PydanticCommand, "meow", "-f", "4", backend=backend) | ||
assert result == PydanticCommand(name="meow", foo=4) | ||
|
||
|
||
class OptSub(msgspec.Struct): | ||
name: Optional[str] = None | ||
|
||
|
||
class OptionalSubcommand(msgspec.Struct): | ||
sub: cappa.Subcommands[Optional[OptSub]] = None | ||
|
||
|
||
@backends | ||
def test_optional_subcommand(backend): | ||
result = parse(OptionalSubcommand, backend=backend) | ||
assert result == OptionalSubcommand(sub=None) | ||
|
||
result = parse(OptionalSubcommand, "opt-sub", backend=backend) | ||
assert result == OptionalSubcommand(sub=OptSub(name=None)) | ||
|
||
result = parse(OptionalSubcommand, "opt-sub", "foo", backend=backend) | ||
assert result == OptionalSubcommand(sub=OptSub(name="foo")) |