Repository navigation
Add check to make sure all reserved keywords are attributes and not properties #1490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
bb3c712
1cd45d4
e715aba
d0ab998
ac5b0e1
bca3d0e
370c784
ba29581
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -340,6 +340,68 @@ def inputs(self) -> tuple[list[str], list[str]]: | |
| def outputs(self) -> tuple[list[str], list[str]]: | ||
| return [], [] | ||
|
|
||
| def test_name_property_decorator(self): | ||
| """Test that ProcessingStage raises an error if a derived class defines 'name' as a @property.""" | ||
| with pytest.raises(TypeError, match="must not define 'name' as a @property"): | ||
|
|
||
| class MockStagePropertyName(ProcessingStage[MockTask, MockTask]): | ||
| @property | ||
| def name(self) -> str: | ||
| return "PropertyName" | ||
|
|
||
| def process(self, task: MockTask) -> MockTask: | ||
| return task | ||
|
|
||
| def test_resources_property_decorator(self): | ||
| """Test that ProcessingStage raises an error if a derived class defines 'resources' as a @property.""" | ||
| with pytest.raises(TypeError, match="must not define 'resources' as a @property"): | ||
|
|
||
| class MockStagePropertyResources(ProcessingStage[MockTask, MockTask]): | ||
| name = "MockStagePropertyResources" | ||
|
|
||
| @property | ||
| def resources(self) -> Resources: | ||
| return Resources(cpus=1.0) | ||
|
|
||
| def process(self, task: MockTask) -> MockTask: | ||
| return task | ||
|
|
||
| def test_batch_size_property_decorator(self): | ||
| """Test that ProcessingStage raises an error if a derived class defines 'batch_size' as a @property.""" | ||
| with pytest.raises(TypeError, match="must not define 'batch_size' as a @property"): | ||
|
|
||
| class MockStagePropertyBatchSize(ProcessingStage[MockTask, MockTask]): | ||
| name = "MockStagePropertyBatchSize" | ||
|
|
||
| @property | ||
| def batch_size(self) -> int: | ||
| return 1 | ||
|
|
||
| def process(self, task: MockTask) -> MockTask: | ||
| return task | ||
|
|
||
| def test_plain_attribute_override_allowed(self): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this may not be needed and should already be covered by
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right... |
||
| """Test that plain attribute overrides for name, resources, and batch_size are still allowed.""" | ||
|
|
||
| class PlainAttrStage(ProcessingStage[MockTask, MockTask]): | ||
| name = "PlainAttrStage" | ||
| resources = Resources(cpus=4.0) | ||
| batch_size = 8 | ||
|
|
||
| def process(self, task: MockTask) -> MockTask: | ||
| return task | ||
|
|
||
| stage = PlainAttrStage() | ||
| assert stage.name == "PlainAttrStage" | ||
| assert stage.resources == Resources(cpus=4.0) | ||
| assert stage.batch_size == 8 | ||
|
|
||
| # with_() should work fine on plain attributes | ||
| modified = stage.with_(name="Modified", resources=Resources(cpus=2.0), batch_size=4) | ||
| assert modified.name == "Modified" | ||
| assert modified.resources == Resources(cpus=2.0) | ||
| assert modified.batch_size == 4 | ||
|
|
||
| def test_nested_class_inheritance(self): | ||
| """Test that nested class inheritance raises an error if a derived class overrides the _name, _resources, or _batch_size property.""" | ||
| with pytest.raises(TypeError, match="MockStageNestedOverriddenName must not override '_name'"): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.