-
Notifications
You must be signed in to change notification settings - Fork 1
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
Remove long list of if/elif, use dict #48
base: main
Are you sure you want to change the base?
Conversation
TYPES = { | ||
LiteralNode: "literal", | ||
NegationNode: "negation", | ||
VariableNode: "variable", | ||
ParameterNode: "parameter", | ||
ComponentParameterNode: "comp_parameter", | ||
ComponentVariableNode: "comp_variable", | ||
AdditionNode: "addition", | ||
MultiplicationNode: "multiplication", | ||
DivisionNode: "division", | ||
SubstractionNode: "substraction", | ||
ComparisonNode: "comparison", | ||
TimeOperatorNode: "time_operator", | ||
TimeAggregatorNode: "time_aggregator", | ||
ScenarioOperatorNode: "scenario_operator", | ||
PortFieldNode: "port_field", | ||
PortFieldAggregatorNode: "port_field_aggregator", | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to define this object once and for all, and not evaluate it for each function call. However I don't remember how to achieve this in Python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe using a single dispatch from functools ?
https://docs.python.org/3/library/functools.html#functools.singledispatch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, you already did what they proposed here:
https://docs.python.org/3/faq/programming.html#how-do-i-use-strings-to-call-functions-methods
You could change the key from a string to the function itself (or a lambda), maybe ?
No description provided.