Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,19 @@ jobs:
runs-on: ubuntu-latest
container:
image: rostooling/setup-ros-docker:ubuntu-noble-ros-rolling-ros-base-latest
strategy:
matrix:
mypy_packages:
- "nav2_smac_planner"
steps:
- uses: actions/checkout@v4

- name: Install typeshed
run: sudo apt update && sudo apt install -y python3-typeshed

- uses: ros-tooling/action-ros-lint@v0.1
with:
linter: mypy
distribution: rolling
package-name: "nav2_smac_planner"
package-name: "${{ join(matrix.mypy_packages, ' ') }}"
arguments: --config tools/pyproject.toml
1 change: 1 addition & 0 deletions nav2_common/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<depend>osrf_pycommon</depend>
<depend>rclpy</depend>
<depend>python3-yaml</depend>
<depend>python3-types-pyyaml</depend>

<buildtool_depend>ament_cmake_core</buildtool_depend>

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import time
from typing import Any, cast, Dict, List, TypedDict

import constants
from lattice_generator import ConfigDict, LatticeGenerator
import matplotlib.pyplot as plt
from nav2_smac_planner.lattice_primitives import constants
from nav2_smac_planner.lattice_primitives.lattice_generator import ConfigDict, LatticeGenerator
from nav2_smac_planner.lattice_primitives.trajectory import Trajectory
import numpy as np
from trajectory import Trajectory

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
Expand Down
9 changes: 4 additions & 5 deletions nav2_smac_planner/lattice_primitives/lattice_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
from enum import Enum
from typing import Any, Dict, List, Tuple, TypedDict

from helper import angle_difference, interpolate_yaws
from nav2_smac_planner.lattice_primitives.helper import angle_difference, interpolate_yaws
from nav2_smac_planner.lattice_primitives.trajectory import (AnyFloat, FloatNDArray, Path,
Trajectory, TrajectoryParameters)
from nav2_smac_planner.lattice_primitives.trajectory_generator import TrajectoryGenerator
import numpy as np
from rtree import index

from trajectory import AnyFloat, FloatNDArray, Path, Trajectory, TrajectoryParameters

from trajectory_generator import TrajectoryGenerator


class ConfigDict(TypedDict):
grid_resolution: float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import unittest

from lattice_generator import ConfigDict, LatticeGenerator
from nav2_smac_planner.lattice_primitives.lattice_generator import ConfigDict, LatticeGenerator
import numpy as np

MOTION_MODEL = 'ackermann'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
from typing import cast
import unittest

from nav2_smac_planner.lattice_primitives.trajectory import Trajectory
from nav2_smac_planner.lattice_primitives.trajectory_generator import (
TrajectoryGenerator, TrajectoryGeneratorConfigDict)
import numpy as np
from trajectory import Trajectory
from trajectory_generator import TrajectoryGenerator, TrajectoryGeneratorConfigDict

TURNING_RADIUS = 1
STEP_DISTANCE = 0.1
Expand Down
5 changes: 3 additions & 2 deletions nav2_smac_planner/lattice_primitives/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from dataclasses import dataclass
from typing import Any, Union

from helper import angle_difference, normalize_angle
from nav2_smac_planner.lattice_primitives.helper import angle_difference, normalize_angle
import numpy as np
from numpy.typing import NDArray

Expand Down Expand Up @@ -61,9 +61,10 @@ class TrajectoryParameters:
@property
def arc_length(self) -> TrajectoryFloat:
"""Arc length of the trajectory."""
return self.turning_radius * angle_difference(
result: TrajectoryFloat = self.turning_radius * angle_difference(
self.start_angle, self.end_angle, self.left_turn
)
return result

@property
def start_straight_length(self) -> AnyFloat:
Expand Down
4 changes: 2 additions & 2 deletions nav2_smac_planner/lattice_primitives/trajectory_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import logging
from typing import Any, List, Tuple, TypedDict, Union

from nav2_smac_planner.lattice_primitives.trajectory import (FloatNDArray, Path, Trajectory,
TrajectoryFloat, TrajectoryParameters)
import numpy as np

from trajectory import FloatNDArray, Path, Trajectory, TrajectoryFloat, TrajectoryParameters

logger = logging.getLogger(__name__)


Expand Down
8 changes: 8 additions & 0 deletions tools/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ write-changes = false
profile = "google"
force_single_line = false
line_length = 99

[tool.mypy]
explicit_package_bases = true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit surprised that this is not part of the ament_mypy configuration. Maybe we should open a PR regarding this configuration setting in the ament_lint repo.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree if you think its good to include!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong feeling one way or another on this one, should we keep it on?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default ament_mypy_configuration has ignore_missing_imports = true. I have additionally added explicit_package_bases = true to treat each package independently.

I think this can be added as a PR for the ament_lint repository.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can keep this file, to include strict = true for strict type checking.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these 2 additions sound good to me. Just waiting for @Nils-ChristianIseke's OK

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes let use strict = True. However that will result in many mypy errors, so you just have to configure mypy to only check the packages that have type hints (currently only nav2_smac_planner). An you will most certanly have to tweak the type hints of nav2_smac_planner.

strict = true

[[tool.mypy.overrides]]
module = ["matplotlib.*", "rtree.*"]
ignore_missing_imports = true
Copy link
Copy Markdown
Contributor

@Nils-ChristianIseke Nils-ChristianIseke Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? If that is set globally we are weakening the static type checking very much (see mypy doc. If there are imports that do not support typing, they should be ignored by adding the following to pyproject.toml:


[[tool.mypy.overrides]]
module = ["foobar.*"]
ignore_missing_imports = true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the tip!
I have applied this to the package accordingly :)

Loading