From 4aaff054ee71d520bce55ecc0ffd454b7451cb5e Mon Sep 17 00:00:00 2001 From: MatthieuDartiailh Date: Mon, 20 Jan 2025 09:20:58 +0100 Subject: [PATCH] tests: add test for invalid default for literal --- .github/workflows/ci.yml | 2 +- atom/meta/annotation_utils.py | 4 +++- tests/test_atom_from_annotations.py | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6911e42..2e61e253 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/atom/meta/annotation_utils.py b/atom/meta/annotation_utils.py index c9a22c67..576d4193 100644 --- a/atom/meta/annotation_utils.py +++ b/atom/meta/annotation_utils.py @@ -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)) diff --git a/tests/test_atom_from_annotations.py b/tests/test_atom_from_annotations.py index 8e595fe3..69ff54e1 100644 --- a/tests/test_atom_from_annotations.py +++ b/tests/test_atom_from_annotations.py @@ -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'