Skip to content

Commit

Permalink
feat(python-sdk): type hinting improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
evansims committed Jan 30, 2025
1 parent 3a75ff5 commit ade989f
Show file tree
Hide file tree
Showing 42 changed files with 1,495 additions and 993 deletions.
8 changes: 0 additions & 8 deletions config/clients/python/config.overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,6 @@
"destinationFilename": "openfga_sdk/telemetry/telemetry.py",
"templateType": "SupportingFiles"
},
"src/telemetry/utilities.py.mustache": {
"destinationFilename": "openfga_sdk/telemetry/utilities.py",
"templateType": "SupportingFiles"
},
"src/__init__.py.mustache": {
"destinationFilename": "openfga_sdk/__init__.py",
"templateType": "SupportingFiles"
Expand Down Expand Up @@ -320,10 +316,6 @@
"destinationFilename": "test/telemetry/telemetry_test.py",
"templateType": "SupportingFiles"
},
"test/telemetry/utilities_test.py.mustache": {
"destinationFilename": "test/telemetry/utilities_test.py",
"templateType": "SupportingFiles"
},
"test/__init__.py.mustache": {
"destinationFilename": "test/__init__.py",
"templateType": "SupportingFiles"
Expand Down
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

9 changes: 3 additions & 6 deletions config/clients/python/template/model.mustache
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{{>partial_header}}

try:
from inspect import getfullargspec
except ImportError:
from inspect import getargspec as getfullargspec
from inspect import getfullargspec
import pprint

from {{packageName}}.configuration import Configuration
Expand Down Expand Up @@ -37,13 +34,13 @@ class {{classname}}:
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
openapi_types = {
openapi_types: dict[str, str] = {
{{#vars}}
'{{name}}': '{{{dataType}}}'{{^-last}},{{/-last}}
{{/vars}}
}

attribute_map = {
attribute_map: dict[str, str] = {
{{#vars}}
'{{name}}': '{{baseName}}'{{^-last}},{{/-last}}
{{/vars}}
Expand Down
17 changes: 13 additions & 4 deletions config/clients/python/template/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ indent-width = 4

target-version = "py310"

[lint]
[tool.ruff.lint]
select = ["E4", "E7", "E9", "F"]
ignore = []

Expand All @@ -42,20 +42,29 @@ unfixable = []

dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[format]
[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"

[tool.pytest.ini_options]
testpaths = [
"tests",
"test",
"integration",
]

addopts = "--cov=openfga_sdk --cov-report term-missing --cov-report xml --cov-report html"

asyncio_mode = "strict"
asyncio_default_fixture_loop_scope = "function"
asyncio_default_test_loop_scope = "function"

[tool.mypy]
python_version = "3.10"
packages = "openfga_sdk"
exclude = [
"openfa_sdk/models",
]
#warn_return_any = "True"
#warn_unused_configs = "True"
#disallow_untyped_defs = "True"
1 change: 1 addition & 0 deletions config/clients/python/template/requirements.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ setuptools >= 69.1.1
build >= 1.2.1, < 2
urllib3 >= 1.25.11, < 3
opentelemetry-api >= 1.25.0, < 2
python-dateutil >= 2.9.0, < 3
2 changes: 1 addition & 1 deletion config/clients/python/template/src/api.py.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class {{classname}}:
response_types_map = {}
{{/returnType}}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "{{operationId}}",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down
6 changes: 3 additions & 3 deletions config/clients/python/template/src/api_client.py.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import tornado.gen
{{/tornado}}
from multiprocessing.pool import ThreadPool

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

import {{modelPackage}}
from {{packageName}} import rest, oauth2
Expand Down Expand Up @@ -175,7 +175,7 @@ class ApiClient:
_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,
):

Expand Down Expand Up @@ -514,7 +514,7 @@ class ApiClient:
_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
Loading

0 comments on commit ade989f

Please sign in to comment.