-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Extend galcheat objects | ||
|
||
## Frozen dataclasses | ||
|
||
The goal of galcheat is to provide a **sourced reference** for survey parameters. Therefore the `Survey` and `Filter` objects have been implemented as frozen dataclasses. This means that trying to modify the attributes of an instance of a `Survey` or a `Filter` will raise a `FrozenInstanceError`. | ||
|
||
Nevertheless, one might possibly want to modify or extend the instances of the dataclasses found in galcheat for specific purposes. This can be achieved through inheritance. | ||
|
||
## Inheritance | ||
|
||
A frozen dataclass creates a class for which the call to the `__setattr__` method raises a `FrozenInstanceError`. A short way to bypass that feature is to inherit from the main class and modify the `__setattr__` method to recover its classic behavior. | ||
|
||
```python | ||
class ExtensibleSurvey(Survey): | ||
def __setattr__(self, x, val): | ||
self.__dict__[x] = val | ||
``` | ||
|
||
The `ExtensibleSurvey` will behave just as the galcheat `Survey` and will be extendable or modifiable. This is also true for the `Filter` class. | ||
|
||
!!! warning "To be used at you own risk" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters