Skip to content

Commit

Permalink
tests: add test for invalid default for literal
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthieuDartiailh committed Jan 20, 2025
1 parent 2098dd7 commit 4aaff05
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.10', '3.11', '3.12', '3.13-dev']
python-version: ['3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v4
- name: Get history and tags for SCM versioning to work
Expand Down
4 changes: 3 additions & 1 deletion atom/meta/annotation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def generate_member_from_type_or_generic(
m_cls = Enum
if default is not _NO_DEFAULT:
if default not in parameters:
raise ValueError("Default value does not appear in Literal")
raise ValueError(
f"Default value {default} does not appear in Literal: {parameters}"
)
# Make the default value the first in the enum arguments.
p = list(parameters)
p.pop(p.index(default))
Expand Down
7 changes: 7 additions & 0 deletions tests/test_atom_from_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,10 @@ class A(Atom, use_annotations=True):

class B(Atom, use_annotations=True):
a: Optional[Iterable] = []


def test_annotations_invalid_default_for_literal():
with pytest.raises(ValueError):

class A(Atom, use_annotations=True):
a: Literal['a', 'b'] = 'c'

0 comments on commit 4aaff05

Please sign in to comment.