AI-Planning / pddl

Unquestionable PDDL 3.1 parser
https://ai-planning.github.io/pddl/
MIT License
85 stars 27 forks source link

Make the type of value in NumericValue actually a number #123

Open DillonZChen opened 1 month ago

DillonZChen commented 1 month ago

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 apply

Checklist

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.