Skip to content

Commit

Permalink
feat: type hinting improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
evansims committed Feb 3, 2025
1 parent a493fb2 commit 894509a
Show file tree
Hide file tree
Showing 140 changed files with 2,159 additions and 1,626 deletions.
2 changes: 0 additions & 2 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ openfga_sdk/telemetry/counters.py
openfga_sdk/telemetry/histograms.py
openfga_sdk/telemetry/metrics.py
openfga_sdk/telemetry/telemetry.py
openfga_sdk/telemetry/utilities.py
openfga_sdk/validation.py
pyproject.toml
requirements.txt
Expand All @@ -285,5 +284,4 @@ test/telemetry/counters_test.py
test/telemetry/histograms_test.py
test/telemetry/metrics_test.py
test/telemetry/telemetry_test.py
test/telemetry/utilities_test.py
test/test_open_fga_api.py
1 change: 1 addition & 0 deletions example/example1/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ python-dateutil >= 2.8.2
urllib3 >= 2.1.0
yarl >= 1.9.4
python-dotenv >= 1, <2

24 changes: 11 additions & 13 deletions openfga_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@

__version__ = "0.9.1"

from openfga_sdk.client.client import OpenFgaClient
from openfga_sdk.client.configuration import ClientConfiguration

from openfga_sdk.api.open_fga_api import OpenFgaApi

from openfga_sdk.api_client import ApiClient
from openfga_sdk.client.client import OpenFgaClient
from openfga_sdk.client.configuration import ClientConfiguration
from openfga_sdk.configuration import Configuration

from openfga_sdk.exceptions import OpenApiException
from openfga_sdk.exceptions import FgaValidationException
from openfga_sdk.exceptions import ApiValueError
from openfga_sdk.exceptions import ApiKeyError
from openfga_sdk.exceptions import ApiAttributeError
from openfga_sdk.exceptions import ApiException

from openfga_sdk.exceptions import (
ApiAttributeError,
ApiException,
ApiKeyError,
ApiValueError,
FgaValidationException,
OpenApiException,
)
from openfga_sdk.models.aborted_message_response import AbortedMessageResponse
from openfga_sdk.models.any import Any
from openfga_sdk.models.assertion import Assertion
Expand Down Expand Up @@ -137,7 +135,6 @@
from openfga_sdk.models.write_request import WriteRequest
from openfga_sdk.models.write_request_deletes import WriteRequestDeletes
from openfga_sdk.models.write_request_writes import WriteRequestWrites

from openfga_sdk.telemetry.configuration import (
TelemetryConfiguration,
TelemetryConfigurations,
Expand All @@ -146,6 +143,7 @@
TelemetryMetricsConfiguration,
)


__all__ = [
"OpenFgaClient",
"ClientConfiguration",
Expand Down
84 changes: 36 additions & 48 deletions openfga_sdk/api/open_fga_api.py

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions openfga_sdk/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import re
import time
import urllib

from multiprocessing.pool import ThreadPool

from dateutil.parser import parse
from dateutil.parser import parse # type: ignore[import-untyped]

import openfga_sdk.models
from openfga_sdk import rest, oauth2

from openfga_sdk import oauth2, rest
from openfga_sdk.configuration import Configuration
from openfga_sdk.exceptions import (
ApiException,
Expand All @@ -36,6 +38,7 @@
from openfga_sdk.telemetry import Telemetry
from openfga_sdk.telemetry.attributes import TelemetryAttribute, TelemetryAttributes


DEFAULT_USER_AGENT = "openfga-sdk python/0.9.1"


Expand Down Expand Up @@ -166,7 +169,8 @@ async def __call_api(
_request_auth=None,
_retry_params=None,
_oauth2_client=None,
_telemetry_attributes: dict[TelemetryAttribute, str | int] = None,
_telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float]
| None = None,
_streaming: bool = False,
):
self.configuration.is_valid()
Expand All @@ -190,10 +194,9 @@ async def __call_api(
path_params = self.parameters_to_tuples(path_params, collection_formats)
for k, v in path_params:
# specified safe chars, encode everything
resource_path = resource_path.replace(
"{%s}" % k,
urllib.parse.quote(str(v), safe=config.safe_chars_for_path_param),
)
_k = urllib.parse.quote(str(k), safe=config.safe_chars_for_path_param)
_v = urllib.parse.quote(str(v), safe=config.safe_chars_for_path_param)
resource_path = resource_path.replace("{" + str(k) + "}", _v)

# query parameters
if query_params:
Expand Down Expand Up @@ -411,7 +414,7 @@ def sanitize_for_serialization(self, obj):
return [self.sanitize_for_serialization(sub_obj) for sub_obj in obj]
elif isinstance(obj, tuple):
return tuple(self.sanitize_for_serialization(sub_obj) for sub_obj in obj)
elif isinstance(obj, (datetime.datetime, datetime.date)):
elif isinstance(obj, datetime.datetime | datetime.date):
return obj.isoformat()

if isinstance(obj, dict):
Expand Down Expand Up @@ -511,7 +514,8 @@ async def call_api(
_request_auth=None,
_retry_params=None,
_oauth2_client=None,
_telemetry_attributes: dict[TelemetryAttribute, str | int] = None,
_telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float]
| None = None,
_streaming: bool = False,
):
"""Makes the HTTP request (synchronous) and returns deserialized data.
Expand Down Expand Up @@ -845,7 +849,7 @@ def __deserialize_model(self, data, klass):
if (
data is not None
and klass.openapi_types is not None
and isinstance(data, (list, dict))
and isinstance(data, list | dict)
):
for attr, attr_type in klass.openapi_types.items():
if klass.attribute_map[attr] in data:
Expand Down
1 change: 1 addition & 0 deletions openfga_sdk/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from openfga_sdk.client.configuration import ClientConfiguration
from openfga_sdk.client.models.check_request import ClientCheckRequest


__all__ = [
"OpenFgaClient",
"ClientConfiguration",
Expand Down
Loading

0 comments on commit 894509a

Please sign in to comment.