Improved get_waypoints and Literal type hints

This commit is contained in:
Daniel 2024-07-29 18:01:28 +02:00 committed by Daraan
parent 17120e0609
commit 9a77f5a054
1 changed files with 11 additions and 5 deletions

View File

@ -1,6 +1,7 @@
from enum import Enum, Flag, IntFlag from enum import Enum, Flag, IntFlag
import sys import sys
from typing import Callable, Iterable, Iterator, Union, Optional, overload, ClassVar, Any, Literal from typing import Callable, Iterable, Iterator, Union, Optional, overload, ClassVar, Any
if sys.version_info >= (3, 11): if sys.version_info >= (3, 11):
from typing import Self from typing import Self
else: else:
@ -11,6 +12,11 @@ if sys.version_info >= (3, 9):
else: else:
from typing_extensions import Annotated from typing_extensions import Annotated
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
class __CarlaEnum(Enum): class __CarlaEnum(Enum):
""" """
CARLA's Enums have a `values` and `names` attribute that are not part of the python `enum.Enum` CARLA's Enums have a `values` and `names` attribute that are not part of the python `enum.Enum`
@ -2556,14 +2562,14 @@ class Map():
... ...
@overload @overload
def get_waypoint(self, location: Location, project_to_road: Literal[True]=True, lane_type=LaneType.Driving) -> Waypoint: def get_waypoint(self, location: Location, project_to_road: Literal[False], lane_type:LaneType=LaneType.Driving) -> Waypoint | None:
... ...
@overload @overload
def get_waypoint(self, location: Location, project_to_road: Literal[False], lane_type=LaneType.Driving) -> Waypoint | None: def get_waypoint(self, location: Location, project_to_road: Literal[True]=True, lane_type: Literal[LaneType.Driving]=LaneType.Driving) -> Waypoint:
... ...
def get_waypoint(self, location: Location, project_to_road=True, lane_type=LaneType.Driving): def get_waypoint(self, location: Location, project_to_road:bool=True, lane_type: LaneType=LaneType.Driving) -> Waypoint | None:
"""Returns a waypoint that can be located in an exact location or translated to the center of the nearest lane. Said lane type can be defined using flags such as `LaneType.Driving & LaneType.Shoulder`. """Returns a waypoint that can be located in an exact location or translated to the center of the nearest lane. Said lane type can be defined using flags such as `LaneType.Driving & LaneType.Shoulder`.
The method will return `None` if the waypoint is not found, which may happen only when trying to retrieve a waypoint for an exact location. That eases checking if a point is inside a certain road, as otherwise, it will return the corresponding waypoint. The method will return `None` if the waypoint is not found, which may happen only when trying to retrieve a waypoint for an exact location. That eases checking if a point is inside a certain road, as otherwise, it will return the corresponding waypoint.