Skip to content

Commit 2e51f95

Browse files
add mypy (#1109) (#1110)
(cherry picked from commit 5b182c6) Signed-off-by: Michael Carlstrom <[email protected]> Co-authored-by: Michael Carlstrom <[email protected]>
1 parent f4ce52a commit 2e51f95

File tree

9 files changed

+39
-5
lines changed

9 files changed

+39
-5
lines changed

ros2pkg/ros2pkg/api/create.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ def populate_ament_python(package, package_directory, source_directory, python_n
169169
source_directory,
170170
'__init__.py',
171171
{})
172+
_create_template_file('ament_python',
173+
'py.typed.em',
174+
source_directory,
175+
'py.typed',
176+
{})
172177

173178
test_directory = _create_folder('test', package_directory)
174179
_create_template_file('ament_python',
@@ -181,6 +186,11 @@ def populate_ament_python(package, package_directory, source_directory, python_n
181186
test_directory,
182187
'test_flake8.py',
183188
{})
189+
_create_template_file('ament_python',
190+
'test_mypy.py.em',
191+
test_directory,
192+
'test_mypy.py',
193+
{})
184194
_create_template_file('ament_python',
185195
'test_pep257.py.em',
186196
test_directory,

ros2pkg/ros2pkg/resource/ament_python/main.py.em

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def main():
1+
def main() -> None:
22
print('Hi from @project_name.')
33

44

ros2pkg/ros2pkg/resource/ament_python/py.typed.em

Whitespace-only changes.

ros2pkg/ros2pkg/resource/ament_python/setup.py.em

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ setup(
1111
['resource/' + package_name]),
1212
('share/' + package_name, ['package.xml']),
1313
],
14+
package_data={'': ['py.typed']},
1415
install_requires=['setuptools'],
1516
zip_safe=True,
1617
maintainer='@maintainer_name',

ros2pkg/ros2pkg/resource/ament_python/test_copyright.py.em

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ import pytest
2020
@@pytest.mark.skip(reason='No copyright header has been placed in the generated source file.')
2121
@@pytest.mark.copyright
2222
@@pytest.mark.linter
23-
def test_copyright():
23+
def test_copyright() -> None:
2424
rc = main(argv=['.', 'test'])
2525
assert rc == 0, 'Found errors'

ros2pkg/ros2pkg/resource/ament_python/test_flake8.py.em

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import pytest
1818

1919
@@pytest.mark.flake8
2020
@@pytest.mark.linter
21-
def test_flake8():
21+
def test_flake8() -> None:
2222
rc, errors = main_with_errors(argv=[])
2323
assert rc == 0, \
2424
'Found %d code style errors / warnings:\n' % len(errors) + \
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2025 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from ament_mypy.main import main
16+
import pytest
17+
18+
19+
@@pytest.mark.mypy
20+
@@pytest.mark.linter
21+
def test_mypy() -> None:
22+
rc = main(argv=[])
23+
assert rc == 0, 'Found type errors!'

ros2pkg/ros2pkg/resource/ament_python/test_pep257.py.em

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ import pytest
1818

1919
@@pytest.mark.linter
2020
@@pytest.mark.pep257
21-
def test_pep257():
21+
def test_pep257() -> None:
2222
rc = main(argv=['.', 'test'])
2323
assert rc == 0, 'Found code style errors / warnings'

ros2pkg/ros2pkg/verb/create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def get_git_config(key: str) -> Optional[str]:
145145
if args.build_type == 'ament_cmake':
146146
test_dependencies = ['ament_lint_auto', 'ament_lint_common']
147147
if args.build_type == 'ament_python':
148-
test_dependencies = ['ament_copyright', 'ament_flake8', 'ament_pep257',
148+
test_dependencies = ['ament_copyright', 'ament_flake8', 'ament_mypy', 'ament_pep257',
149149
'ament_xmllint', 'python3-pytest']
150150

151151
if args.build_type == 'ament_python' and args.package_name == 'test':

0 commit comments

Comments
 (0)