Skip to content

Commit

Permalink
Fix mypy (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthijsBurgh authored Sep 18, 2023
1 parent f171996 commit 7804e2f
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 69 deletions.
52 changes: 27 additions & 25 deletions pykdl_ros/pykdl_ros/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ def __init__(self, frame: kdl.Frame, stamp: Time, frame_id: str):
self.frame = frame
self.header = Header(frame_id=frame_id, stamp=stamp)

def __repr__(self):
def __repr__(self) -> str:
pos = f"(x={self.frame.p.x()}, y={self.frame.p.y()}, z={self.frame.p.z()})"
r, p, y = self.frame.M.GetRPY()
rot = f"(r={r}, p={p}, y={y})"
return f"FrameStamped({pos=}, {rot=} @ {self.header.frame_id})"

def __eq__(self, other):
def __eq__(self, other: object) -> bool:
if isinstance(other, FrameStamped):
return self.frame == other.frame and self.header.frame_id == other.header.frame_id
return self.frame == other.frame and self.header.frame_id == other.header.frame_id # type: ignore
else:
return False

def __ne__(self, other):
def __ne__(self, other: object) -> bool:
return not self.__eq__(other)

def __hash__(self):
def __hash__(self) -> int:
return hash((self.frame, self.header.frame_id))

@classmethod
Expand Down Expand Up @@ -82,7 +82,7 @@ class TwistStamped:

__slots__ = "twist", "header"

def __init__(self, twist: kdl.Twist, stamp: Time, frame_id: str):
def __init__(self, twist: kdl.Twist, stamp: Time, frame_id: str) -> None:
"""
Construct a TwistStamped object.
Expand All @@ -96,21 +96,21 @@ def __init__(self, twist: kdl.Twist, stamp: Time, frame_id: str):
self.twist = twist
self.header = Header(frame_id=frame_id, stamp=stamp)

def __repr__(self):
def __repr__(self) -> str:
vel = f"(x={self.twist.vel.x()}, y={self.twist.vel.y()}, z={self.twist.vel.z()})"
rot = f"(r={self.twist.rot.x()}, p={self.twist.rot.y()}, y={self.twist.rot.z()})"
return f"TwistStamped({vel=}, {rot=} @ {self.header.frame_id})"

def __eq__(self, other):
def __eq__(self, other: object) -> bool:
if isinstance(other, TwistStamped):
return self.twist == other.twist and self.header.frame_id == other.header.frame_id
return self.twist == other.twist and self.header.frame_id == other.header.frame_id # type: ignore
else:
return False

def __ne__(self, other):
def __ne__(self, other: object) -> bool:
return not self.__eq__(other)

def __hash__(self):
def __hash__(self) -> int:
return hash((self.twist, self.header.frame_id))

@classmethod
Expand All @@ -126,7 +126,9 @@ def zero(cls, stamp: Time, frame_id: str) -> TwistStamped:
return cls(twist, stamp, frame_id)

@classmethod
def from_xyz_rpy(cls, vx: float, vy: float, vz: float, wx: float, wy: float, wz: float, stamp: Time, frame_id: str):
def from_xyz_rpy(
cls, vx: float, vy: float, vz: float, wx: float, wy: float, wz: float, stamp: Time, frame_id: str
) -> TwistStamped:
"""
Construct a TwistStamped from velocity and XYZ and RPY.
Expand All @@ -151,7 +153,7 @@ class VectorStamped:

__slots__ = "vector", "header"

def __init__(self, vector: kdl.Vector, stamp: Time, frame_id: str):
def __init__(self, vector: kdl.Vector, stamp: Time, frame_id: str) -> None:
"""
Construct a VectorStamped object.
Expand All @@ -165,20 +167,20 @@ def __init__(self, vector: kdl.Vector, stamp: Time, frame_id: str):
self.vector = vector
self.header = Header(frame_id=frame_id, stamp=stamp)

def __repr__(self):
def __repr__(self) -> str:
xyz = f"(x={self.vector.x()}, y={self.vector.y()}, z={self.vector.z()})"
return f"VectorStamped({xyz} @ {self.header.frame_id})"

def __eq__(self, other):
def __eq__(self, other: object) -> bool:
if isinstance(other, VectorStamped):
return self.vector == other.vector and self.header.frame_id == other.header.frame_id
return self.vector == other.vector and self.header.frame_id == other.header.frame_id # type: ignore
else:
return False

def __ne__(self, other):
def __ne__(self, other: object) -> bool:
return not self.__eq__(other)

def __hash__(self):
def __hash__(self) -> int:
return hash((self.vector, self.header.frame_id))

@classmethod
Expand Down Expand Up @@ -224,7 +226,7 @@ class WrenchStamped:

__slots__ = "wrench", "header"

def __init__(self, wrench: kdl.Wrench, stamp: Time, frame_id: str):
def __init__(self, wrench: kdl.Wrench, stamp: Time, frame_id: str) -> None:
"""
Construct a WrenchStamped object.
Expand All @@ -238,21 +240,21 @@ def __init__(self, wrench: kdl.Wrench, stamp: Time, frame_id: str):
self.wrench = wrench
self.header = Header(frame_id=frame_id, stamp=stamp)

def __repr__(self):
def __repr__(self) -> str:
force = f"(x={self.wrench.force.x()}, y={self.wrench.force.y()}, z={self.wrench.force.z()})"
torque = f"(x={self.wrench.torque.x()}, y={self.wrench.torque.y()}, z={self.wrench.torque.z()})"
return f"WrenchStamped({force=}, {torque=} @ {self.header.frame_id})"

def __eq__(self, other):
def __eq__(self, other: object) -> bool:
if isinstance(other, WrenchStamped):
return self.wrench == other.wrench and self.header.frame_id == other.header.frame_id
return self.wrench == other.wrench and self.header.frame_id == other.header.frame_id # type: ignore
else:
return False

def __ne__(self, other):
def __ne__(self, other: object) -> bool:
return not self.__eq__(other)

def __hash__(self):
def __hash__(self) -> int:
return hash((self.wrench, self.header.frame_id))

@classmethod
Expand All @@ -270,7 +272,7 @@ def zero(cls, stamp: Time, frame_id: str) -> WrenchStamped:
@classmethod
def from_fxfyfz_txtytz(
cls, fx: float, fy: float, fz: float, tx: float, ty: float, tz: float, stamp: Time, frame_id: str
):
) -> WrenchStamped:
"""
Construct a WrenchStamped from force and torque in XYZ.
Expand Down
1 change: 1 addition & 0 deletions pykdl_ros/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ skip_gitignore = true

[tool.mypy]
disallow_untyped_defs = true
ignore_missing_imports = true
no_implicit_optional = true
pretty = true
show_error_codes = true
Expand Down
2 changes: 1 addition & 1 deletion pykdl_ros/test/test_copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
@pytest.mark.skip(reason="No copyright header has been placed in the generated source file.")
@pytest.mark.copyright
@pytest.mark.linter
def test_copyright():
def test_copyright() -> None:
rc = main(argv=[".", "test"])
assert rc == 0, "Found errors"
2 changes: 1 addition & 1 deletion pykdl_ros/test/test_flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

@pytest.mark.flake8
@pytest.mark.linter
def test_flake8():
def test_flake8() -> None:
rc, errors = main_with_errors(argv=["--linelength", "120"])
assert rc == 0, "Found %d code style errors / warnings:\n" % len(errors) + "\n".join(errors)
4 changes: 2 additions & 2 deletions pykdl_ros/test/test_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@pytest.mark.mypy
@pytest.mark.linter
def test_mypy():
def test_mypy() -> None:
try:
import importlib.resources as _ # noqa: F401
except ModuleNotFoundError:
Expand All @@ -28,4 +28,4 @@ def test_mypy():
# There is a bug in mypy that manifests when this try/except import pattern is
# used: https://github.com/python/mypy/issues/1153
pytest.skip("This platform does not support mypy checking of importlib properly")
assert main(argv=[]) == 0, "Found errors"
assert main(argv=["--config", ""]) == 0, "Found errors"
2 changes: 1 addition & 1 deletion pykdl_ros/test/test_pep257.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

@pytest.mark.linter
@pytest.mark.pep257
def test_pep257():
def test_pep257() -> None:
rc = main(argv=[".", "test"])
assert rc == 0, "Found code style errors / warnings"
2 changes: 1 addition & 1 deletion pykdl_ros/test/test_xmllint.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

@pytest.mark.linter
@pytest.mark.xmllint
def test_xmllint():
def test_xmllint() -> None:
rc = main(argv=[])
assert rc == 0, "Found errors"
1 change: 1 addition & 0 deletions tf2_pykdl_ros/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ skip_gitignore = true

[tool.mypy]
disallow_untyped_defs = true
ignore_missing_imports = true
no_implicit_optional = true
pretty = true
show_error_codes = true
Expand Down
2 changes: 1 addition & 1 deletion tf2_pykdl_ros/test/test_copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
@pytest.mark.skip(reason="No copyright header has been placed in the generated source file.")
@pytest.mark.copyright
@pytest.mark.linter
def test_copyright():
def test_copyright() -> None:
rc = main(argv=[".", "test"])
assert rc == 0, "Found errors"
2 changes: 1 addition & 1 deletion tf2_pykdl_ros/test/test_flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

@pytest.mark.flake8
@pytest.mark.linter
def test_flake8():
def test_flake8() -> None:
rc, errors = main_with_errors(argv=["--linelength", "120"])
assert rc == 0, "Found %d code style errors / warnings:\n" % len(errors) + "\n".join(errors)
4 changes: 2 additions & 2 deletions tf2_pykdl_ros/test/test_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@pytest.mark.mypy
@pytest.mark.linter
def test_mypy():
def test_mypy() -> None:
try:
import importlib.resources as _ # noqa: F401
except ModuleNotFoundError:
Expand All @@ -28,4 +28,4 @@ def test_mypy():
# There is a bug in mypy that manifests when this try/except import pattern is
# used: https://github.com/python/mypy/issues/1153
pytest.skip("This platform does not support mypy checking of importlib properly")
assert main(argv=[]) == 0, "Found errors"
assert main(argv=["--config", ""]) == 0, "Found errors"
2 changes: 1 addition & 1 deletion tf2_pykdl_ros/test/test_pep257.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

@pytest.mark.linter
@pytest.mark.pep257
def test_pep257():
def test_pep257() -> None:
rc = main(argv=[".", "test"])
assert rc == 0, "Found code style errors / warnings"
Loading

0 comments on commit 7804e2f

Please sign in to comment.