1
1
"""STAC types."""
2
2
3
- import sys
4
- from typing import Any , Dict , List , Literal , Optional , Union
3
+ from typing import Any , Dict , List , Literal , Union
5
4
6
5
from stac_pydantic .shared import BBox
7
-
8
- # Avoids a Pydantic error:
9
- # TypeError: You should use `typing_extensions.TypedDict` instead of
10
- # `typing.TypedDict` with Python < 3.12.0. Without it, there is no way to
11
- # differentiate required and optional fields when subclassed.
12
- if sys .version_info < (3 , 12 , 0 ):
13
- from typing_extensions import TypedDict
14
- else :
15
- from typing import TypedDict
6
+ from typing_extensions import NotRequired , TypedDict
16
7
17
8
NumType = Union [float , int ]
18
9
19
10
20
- class Catalog (TypedDict , total = False ):
11
+ class Catalog (TypedDict ):
21
12
"""STAC Catalog."""
22
13
23
14
type : str
24
15
stac_version : str
25
- stac_extensions : Optional [List [str ]]
16
+ stac_extensions : NotRequired [List [str ]]
26
17
id : str
27
- title : Optional [str ]
18
+ title : NotRequired [str ]
28
19
description : str
29
20
links : List [Dict [str , Any ]]
30
21
31
22
32
- class LandingPage (Catalog , total = False ):
23
+ class LandingPage (Catalog ):
33
24
"""STAC Landing Page."""
34
25
35
26
conformsTo : List [str ]
@@ -41,7 +32,7 @@ class Conformance(TypedDict):
41
32
conformsTo : List [str ]
42
33
43
34
44
- class Collection (Catalog , total = False ):
35
+ class Collection (Catalog ):
45
36
"""STAC Collection."""
46
37
47
38
keywords : List [str ]
@@ -52,12 +43,12 @@ class Collection(Catalog, total=False):
52
43
assets : Dict [str , Any ]
53
44
54
45
55
- class Item (TypedDict , total = False ):
46
+ class Item (TypedDict ):
56
47
"""STAC Item."""
57
48
58
49
type : Literal ["Feature" ]
59
50
stac_version : str
60
- stac_extensions : Optional [List [str ]]
51
+ stac_extensions : NotRequired [List [str ]]
61
52
id : str
62
53
geometry : Dict [str , Any ]
63
54
bbox : BBox
@@ -67,22 +58,22 @@ class Item(TypedDict, total=False):
67
58
collection : str
68
59
69
60
70
- class ItemCollection (TypedDict , total = False ):
61
+ class ItemCollection (TypedDict ):
71
62
"""STAC Item Collection."""
72
63
73
64
type : Literal ["FeatureCollection" ]
74
65
features : List [Item ]
75
66
links : List [Dict [str , Any ]]
76
- numberMatched : Optional [int ]
77
- numberReturned : Optional [int ]
67
+ numberMatched : NotRequired [int ]
68
+ numberReturned : NotRequired [int ]
78
69
79
70
80
- class Collections (TypedDict , total = False ):
71
+ class Collections (TypedDict ):
81
72
"""All collections endpoint.
82
73
https://github.com/radiantearth/stac-api-spec/tree/master/collections
83
74
"""
84
75
85
76
collections : List [Collection ]
86
77
links : List [Dict [str , Any ]]
87
- numberMatched : Optional [int ] = None
88
- numberReturned : Optional [int ] = None
78
+ numberMatched : NotRequired [int ]
79
+ numberReturned : NotRequired [int ]
0 commit comments