Skip to content

fixed getattr default on Typed classes#315

Open
Faraphel wants to merge 1 commit intoy-crdt:mainfrom
Faraphel:patch-typed-getattr-default
Open

fixed getattr default on Typed classes#315
Faraphel wants to merge 1 commit intoy-crdt:mainfrom
Faraphel:patch-typed-getattr-default

Conversation

@Faraphel
Copy link
Copy Markdown

@Faraphel Faraphel commented Oct 9, 2025

See issue #314

reraise KeyError as an AttributeError when using getattr on Typed classes so that the function can recognize when to use the given default value.

reraise KeyError as an AttributeError when using getattr so that the function can recognize when to use the given default value.
try:
return expected_type(self._[key])
except KeyError:
raise AttributeError(f'"{type(self).mro()[0]}" has no attribute "{key}"')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to add a test for this branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants