py_trees
py_trees copied to clipboard
Typing enhancements
This PR makes a few typing-related changes:
- enables typing "approximately project wide" - py_trees and tests are checked, setup.py and doc/ is not
- Adds Generics to ComparisonExpression (https://github.com/splintered-reality/py_trees/issues/336)
- Adds a return type to create_behaviour_from_function() (https://github.com/splintered-reality/py_trees/issues/334)
- Removes parenthesis from some asserts - using parens around asserts is bad practice, especially when you want to add a description to the assert. This became apparent when I enabled mypy on tests/. Note this revealed a failing test which I don't know how to address. See https://stackoverflow.com/a/3112178/1017787 for more details.
I also experimented with addressing #337 and #335, bit found the solutions were not as obvious.
I fixed the test that was failing by adding timer.join()
to the setup() function. This ensures the timer thread is stopped before continuing, which will (trivially I think) slow down setup() in production.
An alternative would have been to add the timer.join() to the test, or a time.sleep(.05) or something like that, which wouldn't slow production code down, but seems less rigorous. Because setup() should be called infrequently and the timer is stopping anyway, I think the solution I picked is the best option.
Long time in coming, but the very large mypy upgrade in #380. Thanks for pointing the way!
Followups:
- #336 to do something better than
typing.Any
inComparisonExpression
- #382 to track cleaning up asserts.