carla icon indicating copy to clipboard operation
carla copied to clipboard

Named and type-hint supporting detection results for the python agents.

Open Daraan opened this issue 2 years ago • 1 comments

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 version typing.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?

  • Platform(s): Ubuntu 22.04 (Only python code so not relevant)
  • Python version(s): 2.7, 3.8, 3.10
  • Unreal Engine version(s): 4.26

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.

Daraan avatar Feb 22 '24 10:02 Daraan

A comment if license or copyright information should be added and in which form is appreciated :)

Daraan avatar Feb 22 '24 10:02 Daraan

Approved, this does make thing more readable, so nothing against it. No need to add copyright or license information

glopezdiest avatar May 31 '24 10:05 glopezdiest