diff --git a/templates/python/package/client.py.twig b/templates/python/package/client.py.twig index 71babb46c..057693f1f 100644 --- a/templates/python/package/client.py.twig +++ b/templates/python/package/client.py.twig @@ -1,8 +1,8 @@ -import io import requests import os from .input_file import InputFile from .exception import {{spec.title | caseUcfirst}}Exception +from typing import Optional class Client: def __init__(self): @@ -21,20 +21,20 @@ class Client: {% endfor %} } - def set_self_signed(self, status=True): + def set_self_signed(self, status: bool = True): self._self_signed = status return self - def set_endpoint(self, endpoint): + def set_endpoint(self, endpoint: str): self._endpoint = endpoint return self - def add_header(self, key, value): + def add_header(self, key: str, value: str): self._global_headers[key.lower()] = value return self {% for header in spec.global.headers %} - def set_{{header.key | caseSnake}}(self, value): + def set_{{header.key | caseSnake}}(self, value: str): {% if header.description %} """{{header.description}}""" @@ -43,7 +43,7 @@ class Client: return self {% endfor %} - def call(self, method, path='', headers=None, params=None): + def call(self, method: str, path: str = '', headers: Optional[dict] = None, params: Optional[dict] = None): if headers is None: headers = {} @@ -105,12 +105,12 @@ class Client: def chunked_upload( self, - path, - headers = None, - params = None, - param_name = '', + path: str, + headers: Optional[dict] = None, + params: Optional[dict] = None, + param_name: str = '', on_progress = None, - upload_id = '' + upload_id: str = '' ): input_file = params[param_name] @@ -186,7 +186,7 @@ class Client: return result - def flatten(self, data, prefix='', stringify=False): + def flatten(self, data: dict, prefix: str = '', stringify: bool = False): output = {} i = 0 diff --git a/templates/python/package/exception.py.twig b/templates/python/package/exception.py.twig index 6e5d4c8ff..3383d21d6 100644 --- a/templates/python/package/exception.py.twig +++ b/templates/python/package/exception.py.twig @@ -1,7 +1,9 @@ +from typing import Optional + class {{spec.title | caseUcfirst}}Exception(Exception): - def __init__(self, message, code = 0, type = None, response = None): + def __init__(self, message: str, code: int = 0, type: Optional[str] = None, response: Optional[dict] = None): self.message = message self.code = code self.type = type self.response = response - super().__init__(self.message) \ No newline at end of file + super().__init__(self.message) diff --git a/templates/python/package/id.py.twig b/templates/python/package/id.py.twig index a9ed5f326..6c9c7db92 100644 --- a/templates/python/package/id.py.twig +++ b/templates/python/package/id.py.twig @@ -5,4 +5,4 @@ class ID: @staticmethod def unique(): - return 'unique()' \ No newline at end of file + return 'unique()' diff --git a/templates/python/package/input_file.py.twig b/templates/python/package/input_file.py.twig index 9f11b0c2a..d1e0c7f2f 100644 --- a/templates/python/package/input_file.py.twig +++ b/templates/python/package/input_file.py.twig @@ -1,9 +1,10 @@ import os import mimetypes +from typing import Optional class InputFile: @classmethod - def from_path(cls, path): + def from_path(cls, path: str) -> 'InputFile': instance = cls() instance.path = path instance.filename = os.path.basename(path) @@ -12,10 +13,10 @@ class InputFile: return instance @classmethod - def from_bytes(cls, bytes, filename = None, mime_type = None): + def from_bytes(cls, bytes, filename: Optional[str] = None, mime_type: Optional[str] = None) -> 'InputFile': instance = cls() instance.data = bytes instance.filename = filename instance.mime_type = mime_type instance.source_type = 'bytes' - return instance \ No newline at end of file + return instance diff --git a/templates/python/package/permission.py.twig b/templates/python/package/permission.py.twig index 7178b8c42..ffbad7a23 100644 --- a/templates/python/package/permission.py.twig +++ b/templates/python/package/permission.py.twig @@ -1,21 +1,21 @@ class Permission: @staticmethod - def read(role): + def read(role) -> str: return f'read("{role}")' @staticmethod - def write(role): + def write(role) -> str: return f'write("{role}")' @staticmethod - def create(role): + def create(role) -> str: return f'create("{role}")' @staticmethod - def update(role): + def update(role) -> str: return f'update("{role}")' @staticmethod - def delete(role): + def delete(role) -> str: return f'delete("{role}")' diff --git a/templates/python/package/query.py.twig b/templates/python/package/query.py.twig index da636720e..d92930477 100644 --- a/templates/python/package/query.py.twig +++ b/templates/python/package/query.py.twig @@ -1,92 +1,92 @@ class Query: @staticmethod - def equal(attribute, value): + def equal(attribute, value) -> str: return Query.add_query(attribute, "equal", value) @staticmethod - def not_equal(attribute, value): + def not_equal(attribute, value) -> str: return Query.add_query(attribute, "notEqual", value) @staticmethod - def less_than(attribute, value): + def less_than(attribute, value) -> str: return Query.add_query(attribute, "lessThan", value) @staticmethod - def less_than_equal(attribute, value): + def less_than_equal(attribute, value) -> str: return Query.add_query(attribute, "lessThanEqual", value) @staticmethod - def greater_than(attribute, value): + def greater_than(attribute, value) -> str: return Query.add_query(attribute, "greaterThan", value) @staticmethod - def greater_than_equal(attribute, value): + def greater_than_equal(attribute, value) -> str: return Query.add_query(attribute, "greaterThanEqual", value) @staticmethod - def is_null(attribute): + def is_null(attribute) -> str: return f'isNull("{attribute}")' @staticmethod - def is_not_null(attribute): + def is_not_null(attribute) -> str: return f'isNotNull("{attribute}")' @staticmethod - def between(attribute, start, end): + def between(attribute, start, end) -> str: return Query.add_query(attribute, "between", [start, end]) @staticmethod - def starts_with(attribute, value): + def starts_with(attribute, value) -> str: return Query.add_query(attribute, "startsWith", value) @staticmethod - def ends_with(attribute, value): + def ends_with(attribute, value) -> str: return Query.add_query(attribute, "endsWith", value) @staticmethod - def select(attributes): + def select(attributes) -> str: return f'select([{",".join(map(Query.parseValues, attributes))}])' @staticmethod - def search(attribute, value): + def search(attribute, value) -> str: return Query.add_query(attribute, "search", value) @staticmethod - def order_asc(attribute): + def order_asc(attribute) -> str: return f'orderAsc("{attribute}")' @staticmethod - def order_desc(attribute): + def order_desc(attribute) -> str: return f'orderDesc("{attribute}")' @staticmethod - def cursor_before(id): + def cursor_before(id) -> str: return f'cursorBefore("{id}")' @staticmethod - def cursor_after(id): + def cursor_after(id) -> str: return f'cursorAfter("{id}")' @staticmethod - def limit(limit): + def limit(limit) -> str: return f'limit({limit})' @staticmethod - def offset(offset): + def offset(offset) -> str: return f'offset({offset})' @staticmethod - def add_query(attribute, method, value): + def add_query(attribute, method, value) -> str: if type(value) == list: return f'{method}("{attribute}", [{",".join(map(Query.parseValues, value))}])' else: return f'{method}("{attribute}", [{Query.parseValues(value)}])' @staticmethod - def parseValues(value): + def parseValues(value) -> str: if type(value) == str: return f'"{value}"' elif type(value) == bool: return str(value).lower() else: - return str(value) \ No newline at end of file + return str(value) diff --git a/templates/python/package/role.py.twig b/templates/python/package/role.py.twig index c79482670..ae3b7db50 100644 --- a/templates/python/package/role.py.twig +++ b/templates/python/package/role.py.twig @@ -1,30 +1,30 @@ class Role: @staticmethod - def any(): + def any() -> str: return 'any' @staticmethod - def user(id, status = ""): + def user(id, status: str = "") -> str: if status: return f'user:{id}/{status}' return f'user:{id}' @staticmethod - def users(status = ""): + def users(status: str = "") -> str: if status: return f'users/{status}' return 'users' @staticmethod - def guests(): + def guests() -> str: return 'guests' @staticmethod - def team(id, role = ""): + def team(id, role: str = "") -> str: if role: return f'team:{id}/{role}' return f'team:{id}' @staticmethod - def member(id): - return f'member:{id}' \ No newline at end of file + def member(id) -> str: + return f'member:{id}'