Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve docstrings for python #1055

Merged
merged 7 commits into from
Mar 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions templates/python/package/services/service.py.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ..service import Service
from typing import List
from typing import List, Dict, Any
from ..exception import AppwriteException
{% set added = [] %}
{% for method in service.methods %}
Expand All @@ -24,12 +24,38 @@ from ..enums.{{ name | caseSnake }} import {{ name | caseUcfirst }};

class {{ service.name | caseUcfirst }}(Service):

def __init__(self, client):
def __init__(self, client) -> None:
super({{ service.name | caseUcfirst }}, self).__init__(client)
{% for method in service.methods %}

def {{ method.name | caseSnake }}(self{% if method.parameters.all|length > 0 %}, {% endif %}{% for parameter in method.parameters.all %}{{ parameter.name | escapeKeyword | caseSnake }}: {{ parameter | getPropertyType(method) | raw }}{% if not parameter.required %} = None{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, on_progress = None{% endif %}):
"""{{method.title}}"""
def {{ method.name | caseSnake }}(self{% if method.parameters.all|length > 0 %}, {% endif %}{% for parameter in method.parameters.all %}{{ parameter.name | escapeKeyword | caseSnake }}: {{ parameter | getPropertyType(method) | raw }}{% if not parameter.required %} = None{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, on_progress = None{% endif %}) -> {% if method.type == 'webAuth' %}str{% else %}Dict[str, Any]{% endif %}:
"""
{% autoescape false %}{{ method.description | replace({"\n": "\n "}) }}{% endautoescape %}
{% if method.parameters.all|length > 0 or 'multipart/form-data' in method.consumes %}

Parameters
----------
{% for parameter in method.parameters.all %}{{ parameter.name | escapeKeyword | caseSnake }} : {{ parameter | getPropertyType(method) | raw }}
{% autoescape false %}{{ parameter.description | replace({"\n": "\n "}) }}{% endautoescape %}

{% endfor %}{% if 'multipart/form-data' in method.consumes %}
on_progress : callable, optional
Optional callback for upload progress
{% endif %}{% endif %}

Returns
-------
{% if method.type == 'webAuth' %}str
Authentication response as a string
{% else %}Dict[str, Any]
API response as a dictionary
{% endif %}

Raises
------
AppwriteException
If API request fails
"""

api_path = '{{ method.path }}'
{{ include('python/base/params.twig') }}
Expand Down