-
Notifications
You must be signed in to change notification settings - Fork 168
Open
Labels
enhancementhackathon2025Good issues for the hackathon at the Parcels anniversary event in 2025.Good issues for the hackathon at the Parcels anniversary event in 2025.v4
Description
Just parking this code here until we have a migration guide that we can link to.
class MyClass:
def some_method(): ...
def __getattr__(self, name):
... # default behaviour of __getattr__, if already defined
# if the code hasn't already returned here, then the names weren't expected and we should raise an AttributeError
_attribute_error_with_v3_to_v4_hint(self, name, deprecated_names=["some_removed_name"])
# in a utils file
def _attribute_error_with_v3_to_v4_hint(obj, name, *, deprecated_names):
hint = ""
if name in deprecated_names:
hint += (
f" HINT: '{name}' is removed in v4 of Parcels, see our migration guide "
"for more info LINK_TO_MIGRATION_GUIDE."
)
msg = f"'{type(obj).__name__}' object has no attribute '{name}'.{hint}"
raise AttributeError(msg)
# tests file
import pytest
def test_v3_to_v4_migration_hint_removed_method_attr():
obj = MyClass()
with pytest.raises(
AttributeError,
match="'MyClass' object has no attribute 'some_removed_name'. "
"HINT: 'some_removed_name' is removed in v4 of Parcels, see our migration guide "
"for more info LINK_TO_MIGRATION_GUIDE.",
):
obj.some_removed_name
with pytest.raises(
AttributeError,
match="'MyClass' object has no attribute 'some_name_that_never_existed'.",
):
obj.some_name_that_never_existedMetadata
Metadata
Assignees
Labels
enhancementhackathon2025Good issues for the hackathon at the Parcels anniversary event in 2025.Good issues for the hackathon at the Parcels anniversary event in 2025.v4
Type
Projects
Status
Backlog
Status
Backlog