How can typos be caught?
See original GitHub issueThis started with my PR #727. Before implementing another suggestion, I feel like there should first be a rough consensus about what the solution should be.
First, the problem: People make typos. When someone writes Flow(variable_cost=42)
, the missing s (did you spot it?) is silently ignored and one gets a wrong result. Thus, the suggestion is to catch these typos. Somehow.
The problem is complicated by people wanting to be able to add arbitrary properties to objects. So, print(Flow(my_cool_property=42).my_cool_property)
should produce 42
.
So, here are some random thoughts about possible aspects of a solution:
- When should typos be checked?
- At each single object construction
- When the
Model
instance is constructured from the energy system - When solving a model
- With an explicit call to
check_for_unknown_properties()
- How should the checking work?
- Instead of having
Flow.__init__(**kwargs):
, only the known properties are available as named arguments. New properties could be added via a specialcustom_properties
argument. (Of course, the name for this argument is open for bike-shedding) - There could be an internal list of known properties. Everything not known is “bad”. Users could add own properties.
- …in a global list of known properties
- …as an argument somewhere somehow to the check itself
- Instead of having
- What should the result of the check be?
- Exception
- SuspiciousUsageWarning
- a list/dict/… of
$SOMETHING
that is returned to the caller - Nothing (the current state of things: no typo checks done)
Uhm… that’s it. These are all the possibilities I could come up with. Feel free to think about this and add more options. If you have the powers to do so, feel free to edit this comment so that there is “a single list of everything”.
No idea how the usual oemof decision making works. Depending on mood, time, and the phase of the moon, I might or might not be able to send a PR for whatever version is preferred.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (8 by maintainers)
Top GitHub Comments
The decision has been made: Arguments will be explicit. We aim to do the change for v0.5.0.
I already suggested an according session: https://github.com/oemof/oemof/wiki/Meeting-December-2020-(online)#function-signatures