Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent changes to the value of constants #210

Closed
jacobcook1995 opened this issue Apr 26, 2023 · 0 comments · Fixed by #258
Closed

Prevent changes to the value of constants #210

jacobcook1995 opened this issue Apr 26, 2023 · 0 comments · Fixed by #258

Comments

@jacobcook1995
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
Both dataclass's and simple constants defined using ALL_CAPS notation can be altered during the run of the model. We don't really want this to be possible if these are true constants (e.g. Boltzmann's constant).

Describe the solution you'd like
Data classes can be frozen by specifying @dataclass(frozen=True).

Simple constants can be annotated using typing.Final as follows:

from typing import Final

EXAMPLE_CONSTANT: Final[float] = 0.036

This does not stop the constant from being altered, but altering the constant will cause mypy to raise an error. This should reduce the chance of altering constants incorrectly.

Describe alternatives you've considered
We might decide that this is a bit paranoid, but personally feel that it's better to be careful.

Additional context
Issue #209 basically pertains to the opposite problem, so the two issues are very much linked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant