Skip to content

Commit

Permalink
Type-hint comments for CarlaDataProvider (#1066)
Browse files Browse the repository at this point in the history
* Type-hint comments for CarlaDataProvider

* Suppress Any import warning

* Removed None values, increased type-coverage
  • Loading branch information
Daraan authored May 21, 2024
1 parent c5b70b1 commit 2a23a7e
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions srunner/scenariomanager/carla_data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,26 @@ class CarlaDataProvider(object): # pylint: disable=too-many-public-methods
In addition it provides access to the map and the transform of all traffic lights
"""

_actor_velocity_map = {}
_actor_location_map = {}
_actor_transform_map = {}
_traffic_light_map = {}
_carla_actor_pool = {}
_global_osc_parameters = {}
_client = None
_world = None
_map = None
_sync_flag = False
_spawn_points = None
_actor_velocity_map = {} # type: dict[carla.Actor, float]
_actor_location_map = {} # type: dict[carla.Actor, carla.Location]
_actor_transform_map = {} # type: dict[carla.Actor, carla.Transform]
_traffic_light_map = {} # type: dict[carla.TrafficLight, carla.Transform]
_carla_actor_pool = {} # type: dict[int, carla.Actor]
_global_osc_parameters = {} # type: dict[str, Any] # type: ignore : suppresses the missing Any import
_client = None # type: carla.Client
_world = None # type: carla.World
_map = None # type: carla.Map
_sync_flag = False # type: bool
_spawn_points = None # type: list[carla.Transform]
_spawn_index = 0
_blueprint_library = None
_all_actors = None
_blueprint_library = None # type: carla.BlueprintLibrary
_all_actors = None # type: carla.ActorList
_ego_vehicle_route = None
_traffic_manager_port = 8000
_random_seed = 2000
_rng = random.RandomState(_random_seed)
_local_planner = None
_grp = None
_grp = None # type: GlobalRoutePlanner
_runtime_init_flag = False
_lock = threading.Lock()

Expand Down Expand Up @@ -184,6 +184,7 @@ def get_location(actor):

@staticmethod
def get_transform(actor):
# type: (carla.Actor) -> carla.Transform | None
"""
returns the transform for the given actor
"""
Expand All @@ -202,6 +203,7 @@ def get_transform(actor):

@staticmethod
def set_client(client):
# type: (carla.Client) -> None
"""
Set the CARLA client
"""
Expand All @@ -216,6 +218,7 @@ def get_client():

@staticmethod
def set_world(world):
# type: (carla.World) -> None
"""
Set the world and world settings
"""
Expand All @@ -236,6 +239,7 @@ def get_world():

@staticmethod
def get_map(world=None):
# type: (carla.World | None) -> carla.Map
"""
Get the current map
"""
Expand Down Expand Up @@ -286,6 +290,7 @@ def is_sync_mode():

@staticmethod
def set_runtime_init_mode(flag):
# type: (bool) -> None
"""
Set the runtime init mode
"""
Expand Down Expand Up @@ -330,6 +335,7 @@ def prepare_map():

@staticmethod
def annotate_trafficlight_in_group(traffic_light):
# type: (carla.TrafficLight) -> dict[str, list[carla.TrafficLight]]
"""
Get dictionary with traffic light group info for a given traffic light
"""
Expand Down Expand Up @@ -390,10 +396,11 @@ def rotate_point(point, angle):

@staticmethod
def update_light_states(ego_light, annotations, states, freeze=False, timeout=1000000000):
# type: (carla.TrafficLight, dict[str, list[carla.TrafficLight]], dict[str, carla.TrafficLightState], bool, float) -> list[dict[str, carla.TrafficLight | carla.TrafficLightState | float]] # pylint: disable=line-too-long
"""
Update traffic light states
"""
reset_params = []
reset_params = [] # type: list[dict]

for state in states:
relevant_lights = []
Expand Down Expand Up @@ -502,6 +509,7 @@ def check_road_length(wp, length: float):

@staticmethod
def get_road_lanes(wp):
# type: (carla.Waypoint) -> list[carla.Waypoint]
if wp.is_junction:
return []
# find the most left lane's waypoint
Expand Down Expand Up @@ -564,6 +572,7 @@ def get_waypoint_by_laneid(lane_num: int):

@staticmethod
def create_blueprint(model, rolename='scenario', color=None, actor_category="car", attribute_filter=None):
# type: (str, str, carla.Color | None, str, dict | None) -> carla.ActorBlueprint
"""
Function to setup the blueprint of an actor given its model and other relevant parameters
"""
Expand Down Expand Up @@ -683,7 +692,7 @@ def handle_actor_batch(batch, tick=True):

@staticmethod
def spawn_actor(bp, spawn_point, must_spawn=False, track_physics=None, attach_to=None, attachment_type=carla.AttachmentType.Rigid):
# type: (carla.ActorBlueprint, carla.Waypoint | carla.Transform, bool, bool | None, carla.Actor | None, carla.AttachmentType) -> carla.Actor | None
# type: (carla.ActorBlueprint, carla.Waypoint | carla.Transform, bool, bool | None, carla.Actor | None, carla.AttachmentType) -> carla.Actor | None # pylint: disable=line-too-long
"""
The method will spawn and return an actor.
The actor will need an available blueprint to be created.
Expand Down Expand Up @@ -980,7 +989,7 @@ def remove_actor_by_id(actor_id):
"""
if actor_id in CarlaDataProvider._carla_actor_pool:
CarlaDataProvider._carla_actor_pool[actor_id].destroy()
CarlaDataProvider._carla_actor_pool[actor_id] = None
CarlaDataProvider._carla_actor_pool[actor_id] = None # type: ignore
CarlaDataProvider._carla_actor_pool.pop(actor_id)
else:
print("Trying to remove a non-existing actor id {}".format(actor_id))
Expand Down Expand Up @@ -1008,6 +1017,7 @@ def get_traffic_manager_port():

@staticmethod
def set_traffic_manager_port(tm_port):
# type: (int) -> None
"""
Set the port to use for the traffic manager.
"""
Expand Down

0 comments on commit 2a23a7e

Please sign in to comment.