Skip to content

Commit c186f23

Browse files
aaron-skydioasa
authored andcommitted
[SymForce-External] Convert skymarshal templates from py2 to py3 style annotations
Convert skymarshal templates from py2 to py3 style annotations Update skymarshal Python code generation templates to use Python 3-style inline type annotations instead of Python 2-style comment annotations. Changes: - Update python_enum.py.template: convert all method signatures from `# type: (args) -> return` comments to inline `(args: T) -> R` syntax - Update python_struct.py.template: remove quotes from forward-reference return types (e.g., `-> "Name"` becomes `-> Name`) - Add `from __future__ import annotations` to wrapper templates (python_enum_default_wrapper.py.template and python_struct_default_wrapper.py.template) to enable PEP 563 postponed annotation evaluation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> Topic: skymarshal-py3-annotations Closes symforce-org/symforce#451 GitOrigin-RevId: 59feda7d816d6ad99c1de193a7716a1065038fff
1 parent 1aabe88 commit c186f23

File tree

40 files changed

+275
-209
lines changed

40 files changed

+275
-209
lines changed

test/symforce_function_codegen_test_data/symengine/codegen_cpp_test_data/python/lcmtypes/codegen_cpp_test/_constants_t.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# fmt: off
44
# isort: off
55

6+
from __future__ import annotations
7+
68
import copy
79
import typing as T
810

@@ -25,7 +27,7 @@ def __init__(
2527
@staticmethod
2628
def from_all_fields(
2729
epsilon: float,
28-
) -> "constants_t":
30+
) -> constants_t:
2931
return constants_t(
3032
epsilon=epsilon,
3133
)
@@ -39,7 +41,7 @@ def _skytype_meta() -> T.Dict[str, str]:
3941
)
4042

4143
@classmethod
42-
def _default(cls) -> "constants_t":
44+
def _default(cls) -> constants_t:
4345
return cls()
4446

4547
def __repr__(self) -> str:
@@ -65,7 +67,7 @@ def _encode_one(self, buf: T.BinaryIO) -> None:
6567
buf.write(constants_t._CACHED_STRUCT_0.pack(self.epsilon))
6668

6769
@staticmethod
68-
def decode(data: T.Union[bytes, T.BinaryIO]) -> "constants_t":
70+
def decode(data: T.Union[bytes, T.BinaryIO]) -> constants_t:
6971
# NOTE(eric): This function can technically accept either a BinaryIO or
7072
# anything that supports the C++ Buffer Protocol,
7173
# which is unspecifiable in type hints.
@@ -81,7 +83,7 @@ def decode(data: T.Union[bytes, T.BinaryIO]) -> "constants_t":
8183
return constants_t._decode_one(buf)
8284

8385
@staticmethod
84-
def _decode_one(buf: T.BinaryIO) -> "constants_t":
86+
def _decode_one(buf: T.BinaryIO) -> constants_t:
8587
self = constants_t(_skip_initialize=True)
8688
self.epsilon = constants_t._CACHED_STRUCT_0.unpack(buf.read(8))[0]
8789
return self
@@ -101,7 +103,7 @@ def _get_packed_fingerprint() -> bytes:
101103
constants_t._packed_fingerprint = struct.pack(">Q", constants_t._get_hash_recursive([]))
102104
return constants_t._packed_fingerprint
103105

104-
def deepcopy(self, **kwargs: T.Any) -> "constants_t":
106+
def deepcopy(self, **kwargs: T.Any) -> constants_t:
105107
"""
106108
Deep copy of this LCM type
107109

test/symforce_function_codegen_test_data/symengine/codegen_cpp_test_data/python/lcmtypes/codegen_cpp_test/_states_t.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# fmt: off
44
# isort: off
55

6+
from __future__ import annotations
7+
68
import copy
79
import typing as T
810

@@ -26,7 +28,7 @@ def __init__(
2628
@staticmethod
2729
def from_all_fields(
2830
p: Vector2d,
29-
) -> "states_t":
31+
) -> states_t:
3032
return states_t(
3133
p=p,
3234
)
@@ -40,7 +42,7 @@ def _skytype_meta() -> T.Dict[str, str]:
4042
)
4143

4244
@classmethod
43-
def _default(cls) -> "states_t":
45+
def _default(cls) -> states_t:
4446
return cls()
4547

4648
def __repr__(self) -> str:
@@ -70,7 +72,7 @@ def _encode_one(self, buf: T.BinaryIO) -> None:
7072
self.p._encode_one(buf)
7173

7274
@staticmethod
73-
def decode(data: T.Union[bytes, T.BinaryIO]) -> "states_t":
75+
def decode(data: T.Union[bytes, T.BinaryIO]) -> states_t:
7476
# NOTE(eric): This function can technically accept either a BinaryIO or
7577
# anything that supports the C++ Buffer Protocol,
7678
# which is unspecifiable in type hints.
@@ -86,7 +88,7 @@ def decode(data: T.Union[bytes, T.BinaryIO]) -> "states_t":
8688
return states_t._decode_one(buf)
8789

8890
@staticmethod
89-
def _decode_one(buf: T.BinaryIO) -> "states_t":
91+
def _decode_one(buf: T.BinaryIO) -> states_t:
9092
self = states_t(_skip_initialize=True)
9193
self.p = Vector2d._decode_one(buf)
9294
return self
@@ -107,7 +109,7 @@ def _get_packed_fingerprint() -> bytes:
107109
states_t._packed_fingerprint = struct.pack(">Q", states_t._get_hash_recursive([]))
108110
return states_t._packed_fingerprint
109111

110-
def deepcopy(self, **kwargs: T.Any) -> "states_t":
112+
def deepcopy(self, **kwargs: T.Any) -> states_t:
111113
"""
112114
Deep copy of this LCM type
113115

test/symforce_function_codegen_test_data/symengine/codegen_cpp_test_data/python/lcmtypes/codegen_cpp_test/_values_vec_t.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# fmt: off
44
# isort: off
55

6+
from __future__ import annotations
7+
68
import copy
79
import typing as T
810

@@ -41,7 +43,7 @@ def from_all_fields(
4143
rot_vec: T.List[Vector4d],
4244
scalar_vec: T.List[float],
4345
list_of_lists: T.List[T.List[Vector4d]],
44-
) -> "values_vec_t":
46+
) -> values_vec_t:
4547
return values_vec_t(
4648
x=x,
4749
y=y,
@@ -60,7 +62,7 @@ def _skytype_meta() -> T.Dict[str, str]:
6062
)
6163

6264
@classmethod
63-
def _default(cls) -> "values_vec_t":
65+
def _default(cls) -> values_vec_t:
6466
return cls()
6567

6668
def __repr__(self) -> str:
@@ -110,7 +112,7 @@ def _encode_one(self, buf: T.BinaryIO) -> None:
110112
self.list_of_lists[i0][i1]._encode_one(buf)
111113

112114
@staticmethod
113-
def decode(data: T.Union[bytes, T.BinaryIO]) -> "values_vec_t":
115+
def decode(data: T.Union[bytes, T.BinaryIO]) -> values_vec_t:
114116
# NOTE(eric): This function can technically accept either a BinaryIO or
115117
# anything that supports the C++ Buffer Protocol,
116118
# which is unspecifiable in type hints.
@@ -126,7 +128,7 @@ def decode(data: T.Union[bytes, T.BinaryIO]) -> "values_vec_t":
126128
return values_vec_t._decode_one(buf)
127129

128130
@staticmethod
129-
def _decode_one(buf: T.BinaryIO) -> "values_vec_t":
131+
def _decode_one(buf: T.BinaryIO) -> values_vec_t:
130132
self = values_vec_t(_skip_initialize=True)
131133
self.x, self.y = values_vec_t._CACHED_STRUCT_0.unpack(buf.read(16))
132134
self.rot = Vector4d._decode_one(buf)
@@ -157,7 +159,7 @@ def _get_packed_fingerprint() -> bytes:
157159
values_vec_t._packed_fingerprint = struct.pack(">Q", values_vec_t._get_hash_recursive([]))
158160
return values_vec_t._packed_fingerprint
159161

160-
def deepcopy(self, **kwargs: T.Any) -> "values_vec_t":
162+
def deepcopy(self, **kwargs: T.Any) -> values_vec_t:
161163
"""
162164
Deep copy of this LCM type
163165

test/symforce_function_codegen_test_data/symengine/codegen_dataclass_in_values_test_data/python/lcmtypes/codegen_test/_my_dataclass_t.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# fmt: off
44
# isort: off
55

6+
from __future__ import annotations
7+
68
import copy
79
import typing as T
810

@@ -26,7 +28,7 @@ def __init__(
2628
@staticmethod
2729
def from_all_fields(
2830
rot: Vector4d,
29-
) -> "my_dataclass_t":
31+
) -> my_dataclass_t:
3032
return my_dataclass_t(
3133
rot=rot,
3234
)
@@ -40,7 +42,7 @@ def _skytype_meta() -> T.Dict[str, str]:
4042
)
4143

4244
@classmethod
43-
def _default(cls) -> "my_dataclass_t":
45+
def _default(cls) -> my_dataclass_t:
4446
return cls()
4547

4648
def __repr__(self) -> str:
@@ -70,7 +72,7 @@ def _encode_one(self, buf: T.BinaryIO) -> None:
7072
self.rot._encode_one(buf)
7173

7274
@staticmethod
73-
def decode(data: T.Union[bytes, T.BinaryIO]) -> "my_dataclass_t":
75+
def decode(data: T.Union[bytes, T.BinaryIO]) -> my_dataclass_t:
7476
# NOTE(eric): This function can technically accept either a BinaryIO or
7577
# anything that supports the C++ Buffer Protocol,
7678
# which is unspecifiable in type hints.
@@ -86,7 +88,7 @@ def decode(data: T.Union[bytes, T.BinaryIO]) -> "my_dataclass_t":
8688
return my_dataclass_t._decode_one(buf)
8789

8890
@staticmethod
89-
def _decode_one(buf: T.BinaryIO) -> "my_dataclass_t":
91+
def _decode_one(buf: T.BinaryIO) -> my_dataclass_t:
9092
self = my_dataclass_t(_skip_initialize=True)
9193
self.rot = Vector4d._decode_one(buf)
9294
return self
@@ -107,7 +109,7 @@ def _get_packed_fingerprint() -> bytes:
107109
my_dataclass_t._packed_fingerprint = struct.pack(">Q", my_dataclass_t._get_hash_recursive([]))
108110
return my_dataclass_t._packed_fingerprint
109111

110-
def deepcopy(self, **kwargs: T.Any) -> "my_dataclass_t":
112+
def deepcopy(self, **kwargs: T.Any) -> my_dataclass_t:
111113
"""
112114
Deep copy of this LCM type
113115

test/symforce_function_codegen_test_data/symengine/codegen_explicit_template_instantiation_test_data/python/lcmtypes/codegen_explicit_template_instantiation_test/_constants_t.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# fmt: off
44
# isort: off
55

6+
from __future__ import annotations
7+
68
import copy
79
import typing as T
810

@@ -25,7 +27,7 @@ def __init__(
2527
@staticmethod
2628
def from_all_fields(
2729
epsilon: float,
28-
) -> "constants_t":
30+
) -> constants_t:
2931
return constants_t(
3032
epsilon=epsilon,
3133
)
@@ -39,7 +41,7 @@ def _skytype_meta() -> T.Dict[str, str]:
3941
)
4042

4143
@classmethod
42-
def _default(cls) -> "constants_t":
44+
def _default(cls) -> constants_t:
4345
return cls()
4446

4547
def __repr__(self) -> str:
@@ -65,7 +67,7 @@ def _encode_one(self, buf: T.BinaryIO) -> None:
6567
buf.write(constants_t._CACHED_STRUCT_0.pack(self.epsilon))
6668

6769
@staticmethod
68-
def decode(data: T.Union[bytes, T.BinaryIO]) -> "constants_t":
70+
def decode(data: T.Union[bytes, T.BinaryIO]) -> constants_t:
6971
# NOTE(eric): This function can technically accept either a BinaryIO or
7072
# anything that supports the C++ Buffer Protocol,
7173
# which is unspecifiable in type hints.
@@ -81,7 +83,7 @@ def decode(data: T.Union[bytes, T.BinaryIO]) -> "constants_t":
8183
return constants_t._decode_one(buf)
8284

8385
@staticmethod
84-
def _decode_one(buf: T.BinaryIO) -> "constants_t":
86+
def _decode_one(buf: T.BinaryIO) -> constants_t:
8587
self = constants_t(_skip_initialize=True)
8688
self.epsilon = constants_t._CACHED_STRUCT_0.unpack(buf.read(8))[0]
8789
return self
@@ -101,7 +103,7 @@ def _get_packed_fingerprint() -> bytes:
101103
constants_t._packed_fingerprint = struct.pack(">Q", constants_t._get_hash_recursive([]))
102104
return constants_t._packed_fingerprint
103105

104-
def deepcopy(self, **kwargs: T.Any) -> "constants_t":
106+
def deepcopy(self, **kwargs: T.Any) -> constants_t:
105107
"""
106108
Deep copy of this LCM type
107109

test/symforce_function_codegen_test_data/symengine/codegen_explicit_template_instantiation_test_data/python/lcmtypes/codegen_explicit_template_instantiation_test/_states_t.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# fmt: off
44
# isort: off
55

6+
from __future__ import annotations
7+
68
import copy
79
import typing as T
810

@@ -26,7 +28,7 @@ def __init__(
2628
@staticmethod
2729
def from_all_fields(
2830
p: Vector2d,
29-
) -> "states_t":
31+
) -> states_t:
3032
return states_t(
3133
p=p,
3234
)
@@ -40,7 +42,7 @@ def _skytype_meta() -> T.Dict[str, str]:
4042
)
4143

4244
@classmethod
43-
def _default(cls) -> "states_t":
45+
def _default(cls) -> states_t:
4446
return cls()
4547

4648
def __repr__(self) -> str:
@@ -70,7 +72,7 @@ def _encode_one(self, buf: T.BinaryIO) -> None:
7072
self.p._encode_one(buf)
7173

7274
@staticmethod
73-
def decode(data: T.Union[bytes, T.BinaryIO]) -> "states_t":
75+
def decode(data: T.Union[bytes, T.BinaryIO]) -> states_t:
7476
# NOTE(eric): This function can technically accept either a BinaryIO or
7577
# anything that supports the C++ Buffer Protocol,
7678
# which is unspecifiable in type hints.
@@ -86,7 +88,7 @@ def decode(data: T.Union[bytes, T.BinaryIO]) -> "states_t":
8688
return states_t._decode_one(buf)
8789

8890
@staticmethod
89-
def _decode_one(buf: T.BinaryIO) -> "states_t":
91+
def _decode_one(buf: T.BinaryIO) -> states_t:
9092
self = states_t(_skip_initialize=True)
9193
self.p = Vector2d._decode_one(buf)
9294
return self
@@ -107,7 +109,7 @@ def _get_packed_fingerprint() -> bytes:
107109
states_t._packed_fingerprint = struct.pack(">Q", states_t._get_hash_recursive([]))
108110
return states_t._packed_fingerprint
109111

110-
def deepcopy(self, **kwargs: T.Any) -> "states_t":
112+
def deepcopy(self, **kwargs: T.Any) -> states_t:
111113
"""
112114
Deep copy of this LCM type
113115

test/symforce_function_codegen_test_data/symengine/codegen_explicit_template_instantiation_test_data/python/lcmtypes/codegen_explicit_template_instantiation_test/_values_vec_t.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# fmt: off
44
# isort: off
55

6+
from __future__ import annotations
7+
68
import copy
79
import typing as T
810

@@ -41,7 +43,7 @@ def from_all_fields(
4143
rot_vec: T.List[Vector4d],
4244
scalar_vec: T.List[float],
4345
list_of_lists: T.List[T.List[Vector4d]],
44-
) -> "values_vec_t":
46+
) -> values_vec_t:
4547
return values_vec_t(
4648
x=x,
4749
y=y,
@@ -60,7 +62,7 @@ def _skytype_meta() -> T.Dict[str, str]:
6062
)
6163

6264
@classmethod
63-
def _default(cls) -> "values_vec_t":
65+
def _default(cls) -> values_vec_t:
6466
return cls()
6567

6668
def __repr__(self) -> str:
@@ -110,7 +112,7 @@ def _encode_one(self, buf: T.BinaryIO) -> None:
110112
self.list_of_lists[i0][i1]._encode_one(buf)
111113

112114
@staticmethod
113-
def decode(data: T.Union[bytes, T.BinaryIO]) -> "values_vec_t":
115+
def decode(data: T.Union[bytes, T.BinaryIO]) -> values_vec_t:
114116
# NOTE(eric): This function can technically accept either a BinaryIO or
115117
# anything that supports the C++ Buffer Protocol,
116118
# which is unspecifiable in type hints.
@@ -126,7 +128,7 @@ def decode(data: T.Union[bytes, T.BinaryIO]) -> "values_vec_t":
126128
return values_vec_t._decode_one(buf)
127129

128130
@staticmethod
129-
def _decode_one(buf: T.BinaryIO) -> "values_vec_t":
131+
def _decode_one(buf: T.BinaryIO) -> values_vec_t:
130132
self = values_vec_t(_skip_initialize=True)
131133
self.x, self.y = values_vec_t._CACHED_STRUCT_0.unpack(buf.read(16))
132134
self.rot = Vector4d._decode_one(buf)
@@ -157,7 +159,7 @@ def _get_packed_fingerprint() -> bytes:
157159
values_vec_t._packed_fingerprint = struct.pack(">Q", values_vec_t._get_hash_recursive([]))
158160
return values_vec_t._packed_fingerprint
159161

160-
def deepcopy(self, **kwargs: T.Any) -> "values_vec_t":
162+
def deepcopy(self, **kwargs: T.Any) -> values_vec_t:
161163
"""
162164
Deep copy of this LCM type
163165

0 commit comments

Comments
 (0)