Skip to content

Commit b3de024

Browse files
committed
Use python 3.12 type syntax
1 parent a2807da commit b3de024

2 files changed

Lines changed: 7 additions & 16 deletions

File tree

docs/conf.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def add_reference_type(prefix, objs):
134134
"Sentinel",
135135
"ObserveHandler",
136136
"dict[K, V]",
137+
"T",
137138
"G",
138139
"K",
139140
"V",
@@ -144,11 +145,8 @@ def add_reference_type(prefix, objs):
144145
"astropy.coordinates.baseframe.BaseCoordinateFrame",
145146
"astropy.table.table.Table",
146147
"eventio.simtel.simtelfile.SimTelFile",
147-
"ctapipe.core.container.T",
148148
"ctapipe.core.container.T1",
149149
"ctapipe.core.container.T2",
150-
"ctapipe.core.container.K",
151-
"ctapipe.core.container.V",
152150
"DTypeLike",
153151
],
154152
)
@@ -167,11 +165,9 @@ def add_reference_type(prefix, objs):
167165
"-v", # fix for wrong syntax in a traitlets docstring
168166
"cls",
169167
"name",
170-
"ctapipe.core.container.T",
168+
"T",
171169
"ctapipe.core.container.T1",
172170
"ctapipe.core.container.T2",
173-
"ctapipe.core.container.K",
174-
"ctapipe.core.container.V",
175171
],
176172
)
177173
nitpick_ignore += add_reference_type(

src/ctapipe/core/container.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from inspect import isclass
66
from pprint import pformat
77
from textwrap import dedent, wrap
8-
from typing import Any, Callable, Generic, Self, Type, TypeVar, overload
8+
from typing import Any, Callable, Self, Type, TypeVar, overload
99

1010
import numpy as np
1111
from astropy.units import Quantity, Unit, UnitBase, UnitConversionError
@@ -24,12 +24,11 @@ class FieldValidationError(ValueError):
2424
pass
2525

2626

27-
T = TypeVar("T")
2827
T1 = TypeVar("T1")
2928
T2 = TypeVar("T2")
3029

3130

32-
class Field(Generic[T]):
31+
class Field[T]:
3332
"""
3433
Class for storing data in a `Container`.
3534
@@ -178,11 +177,11 @@ def __init__(
178177
# we only specify the Descriptor protocol __get__ here has it helps type checkers
179178
# and IDEs to provide insights on types of container fields. It is not actually used at runtime
180179
# since the ContainerMeta turns Fields into __slots__ based access to member variables.
181-
# 2. When accessed via the class (e.g., MyContainer.foo), only owner present
180+
# 1. When accessed via the class (e.g., MyContainer.foo), only owner present
182181
@overload
183182
def __get__(self, instance: None, owner: Any) -> Self: ...
184183

185-
# 1. access via instance, both arguments present
184+
# 2. access via instance, both arguments present
186185
@overload
187186
def __get__(self, instance: "Container", owner: "Type[Container]") -> T: ...
188187

@@ -567,11 +566,7 @@ def validate(self):
567566
)
568567

569568

570-
K = TypeVar("K")
571-
V = TypeVar("V")
572-
573-
574-
class Map(defaultdict[K, V]):
569+
class Map[K, V](defaultdict[K, V]):
575570
"""A dictionary of sub-containers that can be added to a Container. This
576571
may be used e.g. to store a set of identical sub-Containers (e.g. indexed
577572
by ``tel_id`` or algorithm name).

0 commit comments

Comments
 (0)