Named and type-hint supporting detection results for the python agents. #7174
+46
−9
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.
Description
When I worked with the agent functions at first I had some trouble understanding the semantics of the return types of the agent's detection functions (obstacle, traffic lights).
e.g
return (False, None, -1)
This PR adds Python <3.6 ( including Python2.7 ) compatible named tuples as return values for these two functions. Adding support for type-hints and improving semantics. Aside from the wrapping of return values into namedtuples this PR changes no functionality of the existing code.
For Python <3.6 it uses
collections.namedtuple
for Python 3.6+ it uses the typed versiontyping.NamedTuple
. Type checkers running on 3.6+ can successfully pick up the typed version even if the non-typed version is used during runtime.I think the agents are itself not Python2.7 compatible, so I think it might be overkill.
If stating that the PR is allowed to only support Python3.6+ it could be made much cleaner.
Where has this been tested?
Possible Drawbacks
Seeing None, despite adding one additional file containing the named tuples. They could be added to the BasicAgent.py themselves. In my opinion it would add unnecessary contents the agent file itself.