Make the type of value in NumericValue actually a number #123
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.