Skip to content

Commit

Permalink
Add heritage page (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
aboucaud authored May 5, 2022
1 parent be34b16 commit fce53b3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/guides/heritage.md
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"
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ nav:
- Parameters: parameters.md
- Guides:
- Getting Started: guides/getting-started.md
- Extend galcheat objects: guides/heritage.md
- Releases: guides/releases.md
- API:
- galcheat.survey: api/survey.md
Expand Down

0 comments on commit fce53b3

Please sign in to comment.