Skip to content

Commit fbedbf6

Browse files
committed
refactor: replace optional typing usages with | None
1 parent 2d4e5da commit fbedbf6

File tree

7 files changed

+57
-58
lines changed

7 files changed

+57
-58
lines changed

src/firebase_functions/https_fn.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class HttpsError(Exception):
233233
determines the HTTP status code of the response.
234234
"""
235235

236-
details: _typing.Optional[_typing.Any] = None
236+
details: _typing.Any | None = None
237237
"""
238238
Extra data to be converted to JSON and included in the error response.
239239
"""
@@ -247,7 +247,7 @@ def __init__(
247247
self,
248248
code: FunctionsErrorCode,
249249
message: str,
250-
details: _typing.Optional[_typing.Any] = None,
250+
details: _typing.Any | None = None,
251251
):
252252
self.code = code
253253
self.message = message
@@ -326,17 +326,17 @@ class CallableRequest(_typing.Generic[_core.T]):
326326
The raw request handled by the callable.
327327
"""
328328

329-
app: _typing.Optional[AppCheckData] = None
329+
app: AppCheckData | None = None
330330
"""
331331
The result of decoding and verifying a Firebase AppCheck token.
332332
"""
333333

334-
auth: _typing.Optional[AuthData] = None
334+
auth: AuthData | None = None
335335
""""
336336
The result of decoding and verifying a Firebase Auth ID token.
337337
"""
338338

339-
instance_id_token: _typing.Optional[str] = None
339+
instance_id_token: str | None = None
340340
"""
341341
An unverified token for a Firebase Instance ID.
342342
"""

src/firebase_functions/options.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class PubSubOptions(RuntimeOptions):
325325
Internal use only.
326326
"""
327327

328-
retry: _typing.Optional[bool] = None
328+
retry: bool | None = None
329329
"""
330330
Whether failed executions should be delivered again.
331331
"""
@@ -364,7 +364,7 @@ class StorageOptions(RuntimeOptions):
364364
Internal use only.
365365
"""
366366

367-
bucket: _typing.Optional[str] = None
367+
bucket: str | None = None
368368
"""
369369
The name of the bucket to watch for Storage events.
370370
"""
@@ -416,7 +416,7 @@ class DatabaseOptions(RuntimeOptions):
416416
Examples: '/foo/bar', '/foo/{bar}'
417417
"""
418418

419-
instance: _typing.Optional[str] = None
419+
instance: str | None = None
420420
"""
421421
Specify the handler to trigger on a database instance(s).
422422
If present, this value can either be a single instance or a pattern.
@@ -471,7 +471,7 @@ class HttpsOptions(RuntimeOptions):
471471
Invoker to set access control on https functions.
472472
"""
473473

474-
cors: _typing.Optional[CorsOptions] = None
474+
cors: CorsOptions | None = None
475475
"""
476476
Optionally set CORS options for Https functions.
477477
"""

src/firebase_functions/params.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class SelectOptions(_typing.Generic[_T]):
104104
value: _T
105105
"""The value of the option."""
106106

107-
label: _typing.Optional[str] = None
107+
label: str | None = None
108108
"""The displayed label for the option."""
109109

110110

@@ -127,18 +127,18 @@ class TextInput:
127127
validation_regex, if present, will be retried.
128128
"""
129129

130-
example: _typing.Optional[str] = None
130+
example: str | None = None
131131
"""
132132
An example of the input required that will be displayed alongside the input prompt.
133133
"""
134134

135-
validation_regex: _typing.Optional[str] = None
135+
validation_regex: str | None = None
136136
"""
137137
Validation regex for the input.
138138
Input that does not match this regex, if present, will be retried.
139139
"""
140140

141-
validation_error_message: _typing.Optional[str] = None
141+
validation_error_message: str | None = None
142142
"""
143143
An error message that is displayed to the user if validation_regex fails.
144144
"""
@@ -169,22 +169,22 @@ class Param(Expression[_T]):
169169
The environment variable of this parameter. Must be upper case.
170170
"""
171171

172-
default: _typing.Optional[_T] = None
172+
default: _T | None = None
173173
"""
174174
The default value to assign to this param if none provided.
175175
"""
176176

177-
label: _typing.Optional[str] = None
177+
label: str | None = None
178178
"""
179179
A label that is displayed to the user for this param.
180180
"""
181181

182-
description: _typing.Optional[str] = None
182+
description: str | None = None
183183
"""
184184
Description of this param that is displayed to the user.
185185
"""
186186

187-
immutable: _typing.Optional[bool] = None
187+
immutable: bool | None = None
188188
"""
189189
Whether the value of this parameter can change between function
190190
deployments.
@@ -233,17 +233,17 @@ class SecretParam(Expression[str]):
233233
The environment variable of this parameter. Must be upper case.
234234
"""
235235

236-
label: _typing.Optional[str] = None
236+
label: str | None = None
237237
"""
238238
A label that is displayed to the user for this param.
239239
"""
240240

241-
description: _typing.Optional[str] = None
241+
description: str | None = None
242242
"""
243243
Description of this param that is displayed to the user.
244244
"""
245245

246-
immutable: _typing.Optional[bool] = None
246+
immutable: bool | None = None
247247
"""
248248
Whether the value of this parameter can change between function
249249
deployments.

src/firebase_functions/private/manifest.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,28 @@ class VpcSettings(_typing.TypedDict):
9494
class ManifestEndpoint:
9595
"""A definition of a function as appears in the Manifest."""
9696

97-
entryPoint: _typing.Optional[str] = None
98-
region: _typing.Optional[list[str]] = _dataclasses.field(
99-
default_factory=list[str])
100-
platform: _typing.Optional[str] = "gcfv2"
97+
entryPoint: str | None = None
98+
region: list[str] | None = _dataclasses.field(default_factory=list[str])
99+
platform: str | None = "gcfv2"
101100
availableMemoryMb: int | _params.Expression[
102101
int] | _util.Sentinel | None = None
103102
maxInstances: int | _params.Expression[int] | _util.Sentinel | None = None
104103
minInstances: int | _params.Expression[int] | _util.Sentinel | None = None
105104
concurrency: int | _params.Expression[int] | _util.Sentinel | None = None
106-
serviceAccountEmail: _typing.Optional[str | _util.Sentinel] = None
105+
serviceAccountEmail: str | _util.Sentinel | None = None
107106
timeoutSeconds: int | _params.Expression[int] | _util.Sentinel | None = None
108107
cpu: int | str | _util.Sentinel | None = None
109-
vpc: _typing.Optional[VpcSettings] = None
110-
labels: _typing.Optional[dict[str, str]] = None
111-
ingressSettings: _typing.Optional[str] | _util.Sentinel = None
112-
secretEnvironmentVariables: _typing.Optional[
113-
list[SecretEnvironmentVariable] | _util.Sentinel] = _dataclasses.field(
108+
vpc: VpcSettings | None = None
109+
labels: dict[str, str] | None = None
110+
ingressSettings: str | None | _util.Sentinel = None
111+
secretEnvironmentVariables: list[
112+
SecretEnvironmentVariable] | _util.Sentinel | None = _dataclasses.field(
114113
default_factory=list[SecretEnvironmentVariable])
115-
httpsTrigger: _typing.Optional[HttpsTrigger] = None
116-
callableTrigger: _typing.Optional[CallableTrigger] = None
117-
eventTrigger: _typing.Optional[EventTrigger] = None
118-
scheduleTrigger: _typing.Optional[ScheduleTrigger] = None
119-
blockingTrigger: _typing.Optional[BlockingTrigger] = None
114+
httpsTrigger: HttpsTrigger | None = None
115+
callableTrigger: CallableTrigger | None = None
116+
eventTrigger: EventTrigger | None = None
117+
scheduleTrigger: ScheduleTrigger | None = None
118+
blockingTrigger: BlockingTrigger | None = None
120119

121120

122121
class ManifestRequiredApi(_typing.TypedDict):

src/firebase_functions/private/util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _on_call_valid_method(request: _Request) -> bool:
108108

109109
def _on_call_valid_content_type(request: _Request) -> bool:
110110
"""Validate content"""
111-
content_type: _typing.Optional[str] = request.headers.get("Content-Type")
111+
content_type: str | None = request.headers.get("Content-Type")
112112

113113
if content_type is None:
114114
_logging.warning("Request is missing Content-Type.", content_type)
@@ -159,9 +159,9 @@ class _OnCallTokenVerification:
159159
"""
160160

161161
app: OnCallTokenState = OnCallTokenState.INVALID
162-
app_token: _typing.Optional[dict[str, _typing.Any]] = None
162+
app_token: dict[str, _typing.Any] | None = None
163163
auth: OnCallTokenState = OnCallTokenState.INVALID
164-
auth_token: _typing.Optional[dict] = None
164+
auth_token: dict | None = None
165165

166166
def as_dict(self) -> dict:
167167
"""Set dictionary"""
@@ -256,7 +256,7 @@ class FirebaseConfig():
256256
initialize a firebase App.
257257
"""
258258

259-
storage_bucket: _typing.Optional[str]
259+
storage_bucket: str | None
260260
"""
261261
The name of the Google Cloud Storage bucket used for storing application data.
262262
This is the bucket name without any prefixes or additions (without "gs://").

src/firebase_functions/pubsub_fn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Message(_typing.Generic[T]):
6161
"""
6262

6363
@property
64-
def json(self) -> _typing.Optional[T]:
64+
def json(self) -> T | None:
6565
try:
6666
if self.data is not None:
6767
return _json.loads(_base64.b64decode(self.data).decode("utf-8"))

src/firebase_functions/storage_fn.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,57 +60,57 @@ class StorageObjectData:
6060
The name of the bucket containing this object.
6161
"""
6262

63-
cache_control: _typing.Optional[str]
63+
cache_control: str | None
6464
"""
6565
Cache-Control directive for the object data,
6666
matching [RFC 7234 §5.2]([https://tools.ietf.org/html/rfc7234#section-5.2"]).
6767
"""
6868

69-
component_count: _typing.Optional[int]
69+
component_count: int | None
7070
"""
7171
Number of underlying components that make up this object.
7272
Components are accumulated by compose operations.
7373
"""
7474

75-
content_disposition: _typing.Optional[str]
75+
content_disposition: str | None
7676
"""
7777
Content-Disposition of the object data,
7878
matching [RFC 6266]([https://tools.ietf.org/html/rfc6266"]).
7979
"""
8080

81-
content_encoding: _typing.Optional[str]
81+
content_encoding: str | None
8282
"""
8383
Content-Encoding of the object data,
8484
matching [RFC 7231 §3.1.2.2](https://tools.ietf.org/html/rfc7231#section-3.1.2.2)
8585
"""
8686

87-
content_language: _typing.Optional[str]
87+
content_language: str | None
8888
"""
8989
Content-Language of the object data,
9090
matching [RFC 7231 §3.1.3.2](https://tools.ietf.org/html/rfc7231#section-3.1.3.2)
9191
"""
9292

93-
content_type: _typing.Optional[str]
93+
content_type: str | None
9494
"""
9595
Content-Type of the object data, matching
9696
[RFC 7231 §3.1.1.5](https://tools.ietf.org/html/rfc7231#section-3.1.1.5)
9797
If an object is stored without a Content-Type, it is served as
9898
`application/octet-stream`.
9999
"""
100100

101-
crc32c: _typing.Optional[str]
101+
crc32c: str | None
102102
"""
103103
CRC32c checksum. For more information about using the CRC32c checksum, see
104104
[Hashes and ETags: Best Practices](https://cloud.google.com/storage/docs/hashes-etags#_JSONAPI).
105105
"""
106106

107-
customer_encryption: _typing.Optional[CustomerEncryption]
107+
customer_encryption: CustomerEncryption | None
108108
"""
109109
Metadata of customer-supplied encryption key, if the object is encrypted by
110110
such a key.
111111
"""
112112

113-
etag: _typing.Optional[str]
113+
etag: str | None
114114
"""
115115
HTTP 1.1 Entity tag for the object.
116116
"""
@@ -126,22 +126,22 @@ class StorageObjectData:
126126
generation number.
127127
"""
128128

129-
kind: _typing.Optional[str]
129+
kind: str | None
130130
"""
131131
The kind of item this is. For objects, this is always `storage#object`.
132132
"""
133133

134-
md5_hash: _typing.Optional[str]
134+
md5_hash: str | None
135135
"""
136136
MD5 hash of the data; encoded using base64.
137137
"""
138138

139-
media_link: _typing.Optional[str]
139+
media_link: str | None
140140
"""
141141
Media download link.
142142
"""
143143

144-
metadata: _typing.Optional[dict[str, str]]
144+
metadata: dict[str, str] | None
145145
"""
146146
User-provided metadata, in key/value pairs.
147147
"""
@@ -159,7 +159,7 @@ class StorageObjectData:
159159
The name of the object.
160160
"""
161161

162-
self_link: _typing.Optional[str]
162+
self_link: str | None
163163
"""
164164
The link to this object.
165165
"""
@@ -174,22 +174,22 @@ class StorageObjectData:
174174
Storage class of the object.
175175
"""
176176

177-
time_created: _typing.Optional[str]
177+
time_created: str | None
178178
"""
179179
The creation time of the object.
180180
"""
181181

182-
time_deleted: _typing.Optional[str]
182+
time_deleted: str | None
183183
"""
184184
The deletion time of the object.
185185
"""
186186

187-
time_storage_class_updated: _typing.Optional[str]
187+
time_storage_class_updated: str | None
188188
"""
189189
The time at which the object's storage class was last changed.
190190
"""
191191

192-
updated: _typing.Optional[str]
192+
updated: str | None
193193
"""
194194
The modification time of the object metadata.
195195
"""

0 commit comments

Comments
 (0)