Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-commit.ci for style and lint checking #48

Merged
merged 6 commits into from
Nov 11, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Apply pyupgrade suggestions
  • Loading branch information
flferretti committed Nov 11, 2024
commit 4c0f014862ec7effaf6551d5894b6f7827deabc1
6 changes: 3 additions & 3 deletions src/rod/builder/primitive_builder.py
Original file line number Diff line number Diff line change
@@ -121,7 +121,7 @@ def add_inertial(
pose: rod.Pose | None = None,
inertial: rod.Inertial | None = None,
) -> PrimitiveBuilder:
if not isinstance(self.element, (rod.Model, rod.Link)):
if not isinstance(self.element, rod.Model | rod.Link):
raise ValueError(type(self.element))

if isinstance(self.element, rod.Model):
@@ -151,7 +151,7 @@ def add_visual(
pose: rod.Pose | None = None,
visual: rod.Visual | None = None,
) -> PrimitiveBuilder:
if not isinstance(self.element, (rod.Model, rod.Link)):
if not isinstance(self.element, rod.Model | rod.Link):
raise ValueError(type(self.element))

if isinstance(self.element, rod.Model):
@@ -187,7 +187,7 @@ def add_collision(
pose: rod.Pose | None = None,
collision: rod.Collision | None = None,
) -> PrimitiveBuilder:
if not isinstance(self.element, (rod.Model, rod.Link)):
if not isinstance(self.element, rod.Model | rod.Link):
raise ValueError(type(self.element))

if isinstance(self.element, rod.Model):
2 changes: 1 addition & 1 deletion src/rod/kinematics/kinematic_tree.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
import copy
import dataclasses
import functools
from typing import Sequence
from collections.abc import Sequence

import numpy as np

2 changes: 1 addition & 1 deletion src/rod/pretty_printer.py
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ def list_to_string(obj: list[Any], level: int = 1) -> str:
if not isinstance(obj, list):
raise TypeError(obj, type(obj))

if all(isinstance(el, (numbers.Number, str)) for el in obj):
if all(isinstance(el, numbers.Number | str) for el in obj):
return str(obj)

spacing = " " * 4
4 changes: 3 additions & 1 deletion src/rod/sdf/geometry.py
Original file line number Diff line number Diff line change
@@ -2,10 +2,12 @@

import dataclasses
import types
from typing import ClassVar, Union
from typing import ClassVar

import mashumaro

from rod import logging

from .element import Element


21 changes: 10 additions & 11 deletions src/rod/sdf/joint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import dataclasses
from typing import Optional

import mashumaro

@@ -10,32 +9,32 @@
@dataclasses.dataclass
class Limit(Element):

lower: Optional[float] = dataclasses.field(
lower: float | None = dataclasses.field(
default=None,
metadata=mashumaro.field_options(serialize=Element.serialize_float),
)

upper: Optional[float] = dataclasses.field(
upper: float | None = dataclasses.field(
default=None,
metadata=mashumaro.field_options(serialize=Element.serialize_float),
)

effort: Optional[float] = dataclasses.field(
effort: float | None = dataclasses.field(
default=None,
metadata=mashumaro.field_options(serialize=Element.serialize_float),
)

velocity: Optional[float] = dataclasses.field(
velocity: float | None = dataclasses.field(
default=None,
metadata=mashumaro.field_options(serialize=Element.serialize_float),
)

stiffness: Optional[float] = dataclasses.field(
stiffness: float | None = dataclasses.field(
default=None,
metadata=mashumaro.field_options(serialize=Element.serialize_float),
)

dissipation: Optional[float] = dataclasses.field(
dissipation: float | None = dataclasses.field(
default=None,
metadata=mashumaro.field_options(serialize=Element.serialize_float),
)
@@ -51,12 +50,12 @@ class Dynamics(Element):
metadata=mashumaro.field_options(serialize=Element.serialize_float),
)

damping: Optional[float] = dataclasses.field(
damping: float | None = dataclasses.field(
default=None,
metadata=mashumaro.field_options(serialize=Element.serialize_float),
)

friction: Optional[float] = dataclasses.field(
friction: float | None = dataclasses.field(
default=None,
metadata=mashumaro.field_options(serialize=Element.serialize_float),
)
@@ -66,7 +65,7 @@ class Dynamics(Element):
class Axis(Element):
xyz: Xyz
limit: Limit
dynamics: Optional[Dynamics] = dataclasses.field(default=None)
dynamics: Dynamics | None = dataclasses.field(default=None)


@dataclasses.dataclass
@@ -78,4 +77,4 @@ class Joint(Element):
child: str

pose: Pose | None = dataclasses.field(default=None)
axis: Optional[Axis] = dataclasses.field(default=None)
axis: Axis | None = dataclasses.field(default=None)
3 changes: 1 addition & 2 deletions src/rod/sdf/physics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import dataclasses
from typing import Optional

import mashumaro

@@ -39,7 +38,7 @@ class Physics(Element):
metadata=mashumaro.field_options(serialize=Element.serialize_float),
)

max_contacts: Optional[float] = dataclasses.field(
max_contacts: float | None = dataclasses.field(
default=None,
metadata=mashumaro.field_options(serialize=Element.serialize_float),
)
3 changes: 1 addition & 2 deletions src/rod/sdf/visual.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import dataclasses
from typing import Optional

import mashumaro

@@ -17,4 +16,4 @@ class Visual(Element):

pose: Pose | None = dataclasses.field(default=None)

material: Optional[Material] = dataclasses.field(default=None)
material: Material | None = dataclasses.field(default=None)
6 changes: 3 additions & 3 deletions src/rod/tree/directed_tree.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import collections.abc
import dataclasses
import functools
from typing import Any, Callable, Iterable
from collections.abc import Callable, Iterable, Sequence
from typing import Any

from .tree_elements import DirectedTreeNode


@dataclasses.dataclass(frozen=True)
class DirectedTree(collections.abc.Sequence):
class DirectedTree(Sequence):
root: DirectedTreeNode

def __post_init__(self):
4 changes: 2 additions & 2 deletions src/rod/urdf/exporter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import abc
import copy
import dataclasses
from typing import Any, ClassVar, Set
from typing import Any, ClassVar

import numpy as np
import xmltodict
@@ -25,7 +25,7 @@ class UrdfExporter(abc.ABC):
# If a list of strings is passed, only the listed fixed joints will be preserved.
gazebo_preserve_fixed_joints: bool | list[str] = False

SupportedSdfJointTypes: ClassVar[Set[str]] = {
SupportedSdfJointTypes: ClassVar[set[str]] = {
"revolute",
"continuous",
"prismatic",
2 changes: 1 addition & 1 deletion src/rod/utils/frame_convention.py
Original file line number Diff line number Diff line change
@@ -312,7 +312,7 @@ def find_parent_link_of_frame(frame: rod.Frame, model: rod.Model) -> str:
)

# At this point, the parent is either a link or another frame.
assert isinstance(parent, (rod.Link, rod.Frame))
assert isinstance(parent, rod.Link | rod.Frame)

match parent:
# If the parent is a link, can stop searching.