Automatically convert the value constructor variable of NumericValue into an actual Python number (float or int) as specified in the type hinting. The current parser in the code inputs a lark.lexer.Token when initialising an NumericValue.
Fixes
Added a quick type conversion in the init code and added corresponding test to check that calling the value property indeed returns a float.
Types of changes
What types of changes does your code introduce?
Put an x in the boxes that apply
[x] Bugfix (non-breaking change which fixes an issue)
[ ] New feature (non-breaking change which adds functionality)
[ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
[x] Lint and unit tests pass locally with my changes
[x] I have added tests that prove my fix is effective or that my feature works
Further comments
Using just float(value) breaks test_numerical_hello_world_domain_formatter test because it converts ints to floats, hence why I added some more code to preserve ints where possible. It's probably possible to go down a rabbit hole on specifying different types of numbers such as involving Rationals in order to preserve numerical accuracy, so I'm not sure what is best to do here.
Proposed changes
Automatically convert the value constructor variable of NumericValue into an actual Python number (float or int) as specified in the type hinting. The current parser in the code inputs a lark.lexer.Token when initialising an NumericValue.
Fixes
Added a quick type conversion in the init code and added corresponding test to check that calling the value property indeed returns a float.
Types of changes
What types of changes does your code introduce? Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply.Further comments
Using just float(value) breaks
test_numerical_hello_world_domain_formatter
test because it converts ints to floats, hence why I added some more code to preserve ints where possible. It's probably possible to go down a rabbit hole on specifying different types of numbers such as involving Rationals in order to preserve numerical accuracy, so I'm not sure what is best to do here.