Skip to content

Commit

Permalink
Fix ParamDict dunder attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhad6 committed Jun 26, 2024
1 parent 47a000d commit 83234a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ project adheres to clauses 1–8 of [Semantic Versioning](https://semver.org/spe

## [Unreleased]

## [0.15.1] (Jun 25 2024)

### Fixed

- `ParamDict` treats dunder names (e.g. `__init__`) as attributes, allowing internal
Python functionalities to work.

## [0.15.0] (Jun 21 2024)

### Added
Expand Down
7 changes: 4 additions & 3 deletions paramdb/_param_data/_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ def __delattr__(self, name: str) -> None:

def _is_attribute(self, name: str) -> bool:
"""
If the given name matches an existing attribute or has a corresponding class
type hint, treat it as the name of an attribute.
If the given name matches an existing attribute, has a corresponding class type
hint, or is a dunder name (e.g. __init__), treat it as the name of an attribute.
"""
try:
self.__getattribute__(name) # pylint: disable=unnecessary-dunder-call
Expand All @@ -221,4 +221,5 @@ def _is_attribute(self, name: str) -> bool:
class_annotations: dict[str, Any] = {}
for cls in type(self).mro():
class_annotations |= getattr(cls, "__annotations__", {})
return existing_attribute or name in class_annotations
dunder = name.startswith("__") and name.endswith("__")
return existing_attribute or name in class_annotations or dunder

0 comments on commit 83234a0

Please sign in to comment.