Skip to content

Commit 2a0c741

Browse files
authored
chore: remove Optional typings (#148)
2 parents e49a77a + 02fc990 commit 2a0c741

6 files changed

Lines changed: 65 additions & 64 deletions

File tree

openfga_sdk/configuration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import logging
1616
import sys
1717
import urllib
18-
from typing import Optional
1918

2019
import urllib3
2120

@@ -193,7 +192,7 @@ def __init__(
193192
server_operation_variables=None,
194193
ssl_ca_cert=None,
195194
api_url=None, # TODO: restructure when removing api_scheme/api_host
196-
telemetry: Optional[
195+
telemetry: (
197196
dict[
198197
TelemetryConfigurationType | str,
199198
TelemetryMetricsConfiguration
@@ -205,7 +204,8 @@ def __init__(
205204
]
206205
| None,
207206
]
208-
] = None,
207+
| None
208+
) = None,
209209
):
210210
"""Constructor"""
211211
self._url = api_url

openfga_sdk/telemetry/attributes.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import time
22
import urllib
3-
from typing import NamedTuple, Optional
3+
from typing import NamedTuple
44

55
from aiohttp import ClientResponse
66
from urllib3 import HTTPResponse
@@ -89,7 +89,7 @@ class TelemetryAttributes:
8989

9090
@staticmethod
9191
def get(
92-
name: Optional[str] = None,
92+
name: str | None = None,
9393
) -> list[TelemetryAttribute] | TelemetryAttribute | None:
9494
if name is None:
9595
return TelemetryAttributes._attributes
@@ -234,11 +234,11 @@ def fromRequest(
234234

235235
@staticmethod
236236
def fromResponse(
237-
response: Optional[
238-
HTTPResponse | RESTResponse | ClientResponse | ApiException
239-
] = None,
240-
credentials: Optional[Credentials] = None,
241-
attributes: Optional[dict[TelemetryAttribute, str | int]] = None,
237+
response: (
238+
HTTPResponse | RESTResponse | ClientResponse | ApiException | None
239+
) = None,
240+
credentials: Credentials | None = None,
241+
attributes: dict[TelemetryAttribute, str | int] | None = None,
242242
) -> dict[TelemetryAttribute, str | int]:
243243
response_model_id = None
244244
response_query_duration = None
@@ -295,8 +295,8 @@ def fromResponse(
295295
@staticmethod
296296
def coalesceAttributeValue(
297297
attribute: TelemetryAttribute,
298-
value: Optional[int | float] = None,
299-
attributes: Optional[dict[TelemetryAttribute, str | int]] = None,
298+
value: int | float | None = None,
299+
attributes: dict[TelemetryAttribute, str | int] | None = None,
300300
) -> int | float | None:
301301
if value is None:
302302
if attribute in attributes:

openfga_sdk/telemetry/configuration.py

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import NamedTuple, Optional
1+
from typing import NamedTuple
22

33
from openfga_sdk.telemetry.attributes import TelemetryAttribute, TelemetryAttributes
44
from openfga_sdk.telemetry.counters import TelemetryCounter, TelemetryCounters
@@ -16,22 +16,22 @@ class TelemetryMetricConfiguration:
1616

1717
def __init__(
1818
self,
19-
config: Optional[dict[TelemetryAttribute, bool]] = None,
20-
fga_client_request_client_id: Optional[bool] = None,
21-
fga_client_request_method: Optional[bool] = None,
22-
fga_client_request_model_id: Optional[bool] = None,
23-
fga_client_request_store_id: Optional[bool] = None,
24-
fga_client_response_model_id: Optional[bool] = None,
25-
fga_client_user: Optional[bool] = None,
26-
http_client_request_duration: Optional[bool] = None,
27-
http_host: Optional[bool] = None,
28-
http_request_method: Optional[bool] = None,
29-
http_request_resend_count: Optional[bool] = None,
30-
http_response_status_code: Optional[bool] = None,
31-
http_server_request_duration: Optional[bool] = None,
32-
url_scheme: Optional[bool] = None,
33-
url_full: Optional[bool] = None,
34-
user_agent_original: Optional[bool] = None,
19+
config: dict[TelemetryAttribute, bool] | None = None,
20+
fga_client_request_client_id: bool | None = None,
21+
fga_client_request_method: bool | None = None,
22+
fga_client_request_model_id: bool | None = None,
23+
fga_client_request_store_id: bool | None = None,
24+
fga_client_response_model_id: bool | None = None,
25+
fga_client_user: bool | None = None,
26+
http_client_request_duration: bool | None = None,
27+
http_host: bool | None = None,
28+
http_request_method: bool | None = None,
29+
http_request_resend_count: bool | None = None,
30+
http_response_status_code: bool | None = None,
31+
http_server_request_duration: bool | None = None,
32+
url_scheme: bool | None = None,
33+
url_full: bool | None = None,
34+
user_agent_original: bool | None = None,
3535
):
3636
"""
3737
Initialize a new instance of the `TelemetryMetricConfiguration` class.
@@ -468,8 +468,8 @@ def clear(self) -> None:
468468

469469
def configure(
470470
self,
471-
config: Optional[dict[TelemetryAttribute | str, bool]] = None,
472-
clear: Optional[bool] = False,
471+
config: dict[TelemetryAttribute | str, bool] | None = None,
472+
clear: bool | None = False,
473473
) -> None:
474474
"""
475475
Configure the telemetry metric.
@@ -509,7 +509,7 @@ def configure(
509509
self._valid = None
510510

511511
def getAttributes(
512-
self, filter_enabled: Optional[bool] = True
512+
self, filter_enabled: bool | None = True
513513
) -> dict[TelemetryAttribute, bool]:
514514
"""
515515
Returns a list of supported attributes. If `filter_enabled` is `True`, only enabled attributes are returned.
@@ -530,7 +530,7 @@ def getAttributes(
530530

531531
return attributes
532532

533-
def isEnabled(self, attribute: Optional[TelemetryAttribute] = None) -> bool:
533+
def isEnabled(self, attribute: TelemetryAttribute | None = None) -> bool:
534534
"""
535535
Check if this metric is enabled for telemetry, based on whether any attributes are enabled.
536536
@@ -547,7 +547,7 @@ def isEnabled(self, attribute: Optional[TelemetryAttribute] = None) -> bool:
547547

548548
return False
549549

550-
def isValid(self, raise_exception: Optional[bool] = False) -> bool:
550+
def isValid(self, raise_exception: bool = False) -> bool:
551551
"""
552552
Validate the telemetry metric configuration.
553553
@@ -604,16 +604,17 @@ class TelemetryMetricsConfiguration:
604604

605605
def __init__(
606606
self,
607-
config: Optional[
607+
config: (
608608
dict[
609609
TelemetryHistogram | TelemetryCounter,
610610
TelemetryMetricConfiguration | None,
611611
]
612-
] = None,
613-
fga_client_credentials_request: Optional[TelemetryMetricConfiguration] = None,
614-
fga_client_request_duration: Optional[TelemetryMetricConfiguration] = None,
615-
fga_client_query_duration: Optional[TelemetryMetricConfiguration] = None,
616-
fga_client_request: Optional[TelemetryMetricConfiguration] = None,
612+
| None
613+
) = None,
614+
fga_client_credentials_request: TelemetryMetricConfiguration | None = None,
615+
fga_client_request_duration: TelemetryMetricConfiguration | None = None,
616+
fga_client_query_duration: TelemetryMetricConfiguration | None = None,
617+
fga_client_request: TelemetryMetricConfiguration | None = None,
617618
):
618619
"""
619620
Initialize a new instance of the `TelemetryMetricsConfiguration` class.
@@ -749,13 +750,14 @@ def clear(self) -> None:
749750

750751
def configure(
751752
self,
752-
config: Optional[
753+
config: (
753754
dict[
754755
TelemetryHistogram | TelemetryCounter | str,
755756
TelemetryMetricConfiguration | dict[TelemetryAttribute, bool] | None,
756757
]
757-
] = None,
758-
clear: Optional[bool] = False,
758+
| None
759+
) = None,
760+
clear: bool = False,
759761
) -> None:
760762
"""
761763
Configure metrics reporting for telemetry.
@@ -801,7 +803,7 @@ def configure(
801803
self._valid = None
802804

803805
def getMetrics(
804-
self, filter_enabled: Optional[bool] = True
806+
self, filter_enabled: bool = True
805807
) -> dict[
806808
TelemetryHistogram | TelemetryCounter, TelemetryMetricConfiguration | None
807809
]:
@@ -825,7 +827,7 @@ def getMetrics(
825827
return metrics
826828

827829
def isEnabled(
828-
self, metric: Optional[TelemetryCounter | TelemetryHistogram] = None
830+
self, metric: TelemetryCounter | TelemetryHistogram | None = None
829831
) -> bool:
830832
"""
831833
Check if a metric is enabled for telemetry.
@@ -847,7 +849,7 @@ def isEnabled(
847849

848850
return False
849851

850-
def isValid(self, raise_exception: Optional[bool] = False) -> bool:
852+
def isValid(self, raise_exception: bool = False) -> bool:
851853
"""
852854
Validate the telemetry metrics configuration.
853855
@@ -903,7 +905,7 @@ class TelemetryConfigurations:
903905

904906
@staticmethod
905907
def get(
906-
name: Optional[str] = None,
908+
name: str | None = None,
907909
) -> list[TelemetryConfigurationType] | TelemetryConfigurationType | None:
908910
if name is None:
909911
return TelemetryConfigurations._configurations
@@ -921,8 +923,8 @@ class TelemetryConfiguration:
921923

922924
def __init__(
923925
self,
924-
config: Optional[dict[str, TelemetryMetricsConfiguration | None]] = None,
925-
metrics: Optional[TelemetryMetricsConfiguration] = None,
926+
config: dict[str, TelemetryMetricsConfiguration | None] | None = None,
927+
metrics: TelemetryMetricsConfiguration | None = None,
926928
):
927929
"""
928930
Initialize a new instance of the `TelemetryConfiguration` class.
@@ -974,7 +976,7 @@ def clear(self) -> None:
974976

975977
def configure(
976978
self,
977-
config: Optional[
979+
config: (
978980
dict[
979981
TelemetryConfigurationType | str,
980982
TelemetryMetricsConfiguration
@@ -986,8 +988,9 @@ def configure(
986988
]
987989
| None,
988990
]
989-
] = None,
990-
clear: Optional[bool] = False,
991+
| None
992+
) = None,
993+
clear: bool = False,
991994
) -> None:
992995
"""
993996
Configure telemetry reporting.
@@ -1029,7 +1032,7 @@ def configure(
10291032
self._valid = None
10301033

10311034
def getConfigurations(
1032-
self, filter_enabled: Optional[bool] = True
1035+
self, filter_enabled: bool = True
10331036
) -> dict[TelemetryConfigurationType, TelemetryMetricsConfiguration | None]:
10341037
"""
10351038
Returns a list of supported reporting contexts. If `filter_enabled` is `True`, only enabled contexts are returned.
@@ -1051,7 +1054,7 @@ def getConfigurations(
10511054
return contexts
10521055

10531056
def isEnabled(
1054-
self, configuration: Optional[TelemetryConfigurationType] = None
1057+
self, configuration: TelemetryConfigurationType | None = None
10551058
) -> bool:
10561059
"""
10571060
Check if telemetry is enabled.
@@ -1071,7 +1074,7 @@ def isEnabled(
10711074

10721075
return False
10731076

1074-
def isValid(self, raise_exception: Optional[bool] = False) -> bool:
1077+
def isValid(self, raise_exception: bool = False) -> bool:
10751078
"""
10761079
Validate the telemetry configuration.
10771080

openfga_sdk/telemetry/counters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import NamedTuple, Optional
1+
from typing import NamedTuple
22

33

44
class TelemetryCounter(NamedTuple):
@@ -25,7 +25,7 @@ class TelemetryCounters:
2525

2626
@staticmethod
2727
def get(
28-
name: Optional[str] = None,
28+
name: str | None = None,
2929
) -> list[TelemetryCounter] | TelemetryCounter | None:
3030
if name is None:
3131
return TelemetryCounters._counters

openfga_sdk/telemetry/histograms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import NamedTuple, Optional
1+
from typing import NamedTuple
22

33

44
class TelemetryHistogram(NamedTuple):
@@ -24,7 +24,7 @@ class TelemetryHistograms:
2424

2525
@staticmethod
2626
def get(
27-
name: Optional[str] = None,
27+
name: str | None = None,
2828
) -> list[TelemetryHistogram] | TelemetryHistogram | None:
2929
if name is None:
3030
return TelemetryHistograms._histograms

openfga_sdk/telemetry/metrics.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Optional
2-
31
from opentelemetry.metrics import Counter, Histogram, Meter, get_meter
42

53
from openfga_sdk.telemetry.attributes import (
@@ -21,9 +19,9 @@ class TelemetryMetrics:
2119

2220
def __init__(
2321
self,
24-
meter: Optional[Meter] = None,
25-
counters: Optional[dict[str, Counter]] = None,
26-
histograms: Optional[dict[str, Histogram]] = None,
22+
meter: Meter | None = None,
23+
counters: dict[str, Counter] | None = None,
24+
histograms: dict[str, Histogram] | None = None,
2725
):
2826
self._meter = meter
2927
self._counters = counters or {}

0 commit comments

Comments
 (0)