From 6e1dfffdfc6ce497e9aee2589ab302bf5cbd7bf7 Mon Sep 17 00:00:00 2001 From: David C Ellis Date: Tue, 5 Nov 2024 17:11:05 +0000 Subject: [PATCH] Allow for attributes to be both kw_only and not in init. --- src/ducktools/classbuilder/__init__.py | 5 ----- tests/prefab/shared/examples/fails/creation_1.py | 6 ------ tests/prefab/shared/test_creation.py | 9 --------- 3 files changed, 20 deletions(-) delete mode 100644 tests/prefab/shared/examples/fails/creation_1.py diff --git a/src/ducktools/classbuilder/__init__.py b/src/ducktools/classbuilder/__init__.py index 22833f0..97cd03b 100644 --- a/src/ducktools/classbuilder/__init__.py +++ b/src/ducktools/classbuilder/__init__.py @@ -654,11 +654,6 @@ def validate_field(self): f"{cls_name} cannot define both a default value and a default factory." ) - if self.kw_only and not self.init: - raise AttributeError( - f"{cls_name} cannot be keyword only if it is not in init." - ) - @classmethod def from_field(cls, fld, /, **kwargs): """ diff --git a/tests/prefab/shared/examples/fails/creation_1.py b/tests/prefab/shared/examples/fails/creation_1.py deleted file mode 100644 index 6af785b..0000000 --- a/tests/prefab/shared/examples/fails/creation_1.py +++ /dev/null @@ -1,6 +0,0 @@ -from ducktools.classbuilder.prefab import prefab, attribute - - -@prefab -class Construct: - x = attribute(default="test", kw_only=True, init=False) diff --git a/tests/prefab/shared/test_creation.py b/tests/prefab/shared/test_creation.py index 04b2327..c5d01f0 100644 --- a/tests/prefab/shared/test_creation.py +++ b/tests/prefab/shared/test_creation.py @@ -144,15 +144,6 @@ def test_skipped_annotated_classvars(self): class TestExceptions: - def test_kw_not_in_init(self): - with pytest.raises(AttributeError) as e_info: - from fails.creation_1 import Construct - - assert ( - e_info.value.args[0] - == "Attribute cannot be keyword only if it is not in init." - ) - def test_positional_after_kw_error(self): with pytest.raises(SyntaxError) as e_info: from fails.creation_2 import FailSyntax