Skip to content

Commit

Permalink
Added Literal type hint for <3.8 Python
Browse files Browse the repository at this point in the history
  • Loading branch information
Daraan committed Apr 2, 2024
1 parent 41f6d9d commit 1b789de
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions PythonAPI/carla/agents/tools/hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
ObstacleDetectionResult = namedtuple('ObstacleDetectionResult', ['obstacle_was_found', 'obstacle', 'distance'])
TrafficLightDetectionResult = namedtuple('TrafficLightDetectionResult', ['traffic_light_was_found', 'traffic_light'])
else:
from typing import NamedTuple, Union
from typing import NamedTuple, Union, TYPE_CHECKING
from carla import Actor, TrafficLight
"""
# Python 3.6+
# Python 3.6+, incompatible with Python 2.7 syntax
class ObstacleDetectionResult(NamedTuple):
obstacle_was_found : bool
obstacle : Union[Actor, None]
Expand All @@ -25,5 +25,10 @@ class TrafficLightDetectionResult(NamedTuple):
traffic_light_was_found : bool
traffic_light : Union[TrafficLight, None]
"""
ObstacleDetectionResult = NamedTuple('ObstacleDetectionResult', [('obstacle_was_found', bool), ('obstacle', Union[Actor, None]), ('distance', float)])
if TYPE_CHECKING:
from typing import Literal
ObstacleDetectionResult = NamedTuple('ObstacleDetectionResult', [('obstacle_was_found', bool), ('obstacle', Union[Actor, None]), ('distance', Union[float, Literal[-1]])])
else:
ObstacleDetectionResult = NamedTuple('ObstacleDetectionResult', [('obstacle_was_found', bool), ('obstacle', Union[Actor, None]), ('distance', float)])

TrafficLightDetectionResult = NamedTuple('TrafficLightDetectionResult', [('traffic_light_was_found', bool), ('traffic_light', Union[TrafficLight, None])])

0 comments on commit 1b789de

Please sign in to comment.