Skip to content

Commit 20ad605

Browse files
committed
fix: ensure NotRequired import works for both Python 3.11+ and earlier via typing_extensions fallback
1 parent 369ef46 commit 20ad605

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

gempy/modules/json_io/schema.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,48 @@ class Orientation(TypedDict):
2323
nugget: float
2424
polarity: int # 1 for normal, -1 for reverse
2525

26-
class Surface(TypedDict):
27-
name: str
28-
id: int
29-
color: Optional[str] # Hex color code
30-
vertices: Optional[List[List[float]]] # List of [x, y, z] coordinates
26+
class Surface(TypedDict, total=False):
27+
name: str # Required
28+
id: NotRequired[int] # Optional, will be auto-generated if not provided
29+
color: NotRequired[Optional[str]] # Optional hex color code
30+
vertices: NotRequired[Optional[List[List[float]]]] # Optional list of [x, y, z] coordinates
3131

32-
class Fault(TypedDict):
33-
name: str
34-
id: int
35-
is_active: bool
32+
class Fault(TypedDict, total=False):
33+
name: str # Required
34+
id: NotRequired[int] # Optional, will be auto-generated
35+
is_active: NotRequired[bool] # Optional, defaults to True
3636
surface: Surface
3737

3838
class Series(TypedDict, total=False):
3939
name: str # Required
40-
id: int
41-
is_active: bool
42-
is_fault: bool
43-
order_series: int
44-
surfaces: List[str] # Required, list of surface names
45-
faults: List[Fault]
40+
surfaces: Union[List[str], List[Surface]] # Required, can be list of names or Surface objects
41+
id: NotRequired[int] # Optional, will be auto-generated
42+
is_active: NotRequired[bool] # Optional, defaults to True
43+
is_fault: NotRequired[bool] # Optional, defaults to False
44+
order_series: NotRequired[int] # Optional, will be auto-generated
45+
faults: NotRequired[List[Fault]] # Optional, defaults to empty list
4646
structural_relation: NotRequired[str] # Optional, defaults to "ONLAP"
47-
colors: NotRequired[Optional[List[str]]] # Optional list of hex color codes
47+
colors: NotRequired[Optional[List[str]]] # Optional
4848

49-
class GridSettings(TypedDict):
50-
regular_grid_resolution: List[int]
51-
regular_grid_extent: List[float]
52-
octree_levels: Optional[int]
49+
class GridSettings(TypedDict, total=False):
50+
regular_grid_resolution: NotRequired[List[int]] # Optional, defaults to [10, 10, 10]
51+
regular_grid_extent: NotRequired[List[float]] # Optional, auto-calculated from data
52+
octree_levels: NotRequired[Optional[int]] # Optional
5353

54-
class ModelMetadata(TypedDict):
55-
name: str
56-
creation_date: str
57-
last_modification_date: str
58-
owner: Optional[str]
54+
class ModelMetadata(TypedDict, total=False):
55+
name: NotRequired[str] # Optional, defaults to "GemPy Model"
56+
creation_date: NotRequired[str] # Optional, defaults to current date
57+
last_modification_date: NotRequired[str] # Optional, defaults to current date
58+
owner: NotRequired[Optional[str]] # Optional, defaults to "GemPy Team"
5959

60-
class IdNameMapping(TypedDict):
61-
name_to_id: Dict[str, int]
60+
class IdNameMapping(TypedDict, total=False):
61+
name_to_id: Dict[str, int] # Required if id_name_mapping is provided
6262

63-
class GemPyModelJson(TypedDict, total=False):
64-
metadata: ModelMetadata
65-
surface_points: List[SurfacePoint]
66-
orientations: List[Orientation]
67-
series: List[Series]
68-
grid_settings: Optional[GridSettings]
69-
interpolation_options: Optional[Dict[str, Any]]
70-
id_name_mapping: IdNameMapping
63+
class GemPyModelJson(TypedDict):
64+
surface_points: List[SurfacePoint] # Required
65+
orientations: List[Orientation] # Required
66+
series: List[Series] # Required but with minimal required fields
67+
metadata: NotRequired[ModelMetadata] # Optional
68+
grid_settings: NotRequired[Optional[GridSettings]] # Optional
69+
interpolation_options: NotRequired[Optional[Dict[str, Any]]] # Optional
70+
id_name_mapping: NotRequired[IdNameMapping] # Optional

0 commit comments

Comments
 (0)