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

wip: Add support to typing.Annotated #633

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ test: clean
@python -m pip install --upgrade tox
@python -m tox -p all

test-cov-unit:
@REPORT="\nUnit Tests:\n"; \
for TEST_FILE in $(shell find tests/unit -name "test_*.py"); do \
TEST_NAME=$$(basename $${TEST_FILE} .py); \
PY_MODULE=$$(echo flask_jsonrpc.$${TEST_FILE} | sed 's|/|.|g' | sed 's|.py$$||' | sed 's|test_||' | sed 's|tests.unit.||' | sed 's|.openrpc.app|.openrpc|' | sed 's|.browse.app|.browse|' | sed 's|.async_app|.app|'); \
pytest --cov-reset --cov=$${PY_MODULE} $${TEST_FILE} -vv; \
if [ $$? -ne 0 ]; then \
REPORT+=" + Unit Tests $${TEST_FILE} for $${PY_MODULE} failed (pytest --cov-reset --cov-report=html --cov=$${PY_MODULE} $${TEST_FILE} -vv)\n"; \
fi; \
done; \
echo $${REPORT}


test-examples: clean
@python -m pip install --upgrade tox
@find examples/ -name "tox.ini" -print0 | xargs -0 -t -I % -P 4 tox -p all -c %
Expand Down
2 changes: 1 addition & 1 deletion examples/javascript/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = {file = "LICENSE.txt"}
authors = [{name = "Nycholas Oliveira", email = "[email protected]"}]
maintainers = [{name = "Cenobit Technologies Inc.", email = "[email protected]"}]
requires-python = ">=3.9"
dependencies = ["Flask-JSONRPC@git+https://github.com/cenobites/flask-jsonrpc"]
dependencies = ["Flask-JSONRPC"]

[project.optional-dependencies]
async = ["Flask[async]>=3.0.0,<4.0"]
Expand Down
36 changes: 30 additions & 6 deletions examples/javascript/tests/api/test_hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,45 @@ def test_rpc_describe(client: 'FlaskClient') -> None:
assert data['id'] == 1
assert data['jsonrpc'] == '2.0'
assert data['result']['name'] == 'Flask-JSONRPC'
assert data['result']['version'] == '2.0'
assert data['result']['version'] == '1.0.0'
assert data['result']['servers'] is not None
assert 'url' in data['result']['servers'][0]
assert data['result']['methods'] == {
'Hello.index': {
'options': {'notification': True, 'validate': True},
'name': 'Hello.index',
'notification': True,
'params': [],
'returns': {'type': 'String'},
'returns': {'name': 'default', 'type': 'String'},
'type': 'method',
'validation': True,
},
'Hello.say': {
'options': {'notification': True, 'validate': True},
'name': 'Hello.say',
'notification': True,
'params': [{'name': 'name', 'type': 'String'}],
'returns': {'type': 'String'},
'returns': {'name': 'default', 'type': 'String'},
'type': 'method',
'validation': True,
},
'rpc.describe': {
'name': 'rpc.describe',
'notification': False,
'params': [],
'returns': {
'name': 'default',
'properties': {
'description': {'name': 'description', 'type': 'String'},
'id': {'name': 'id', 'type': 'String'},
'methods': {'name': 'methods', 'type': 'Null'},
'name': {'name': 'name', 'type': 'String'},
'servers': {'name': 'servers', 'type': 'Null'},
'title': {'name': 'title', 'type': 'String'},
'version': {'name': 'version', 'type': 'String'},
},
'type': 'Object',
},
'summary': 'RPC Describe',
'type': 'method',
'validation': True,
},
'rpc.describe': {'options': {}, 'params': [], 'returns': {'type': 'Object'}, 'type': 'method'},
}
24 changes: 22 additions & 2 deletions examples/javascript/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,29 @@ def test_rpc_describe(client: 'FlaskClient') -> None:
assert data['id'] == 1
assert data['jsonrpc'] == '2.0'
assert data['result']['name'] == 'Flask-JSONRPC'
assert data['result']['version'] == '2.0'
assert data['result']['version'] == '1.0.0'
assert data['result']['servers'] is not None
assert 'url' in data['result']['servers'][0]
assert data['result']['methods'] == {
'rpc.describe': {'options': {}, 'params': [], 'returns': {'type': 'Object'}, 'type': 'method'}
'rpc.describe': {
'name': 'rpc.describe',
'notification': False,
'params': [],
'returns': {
'name': 'default',
'properties': {
'description': {'name': 'description', 'type': 'String'},
'id': {'name': 'id', 'type': 'String'},
'methods': {'name': 'methods', 'type': 'Null'},
'name': {'name': 'name', 'type': 'String'},
'servers': {'name': 'servers', 'type': 'Null'},
'title': {'name': 'title', 'type': 'String'},
'version': {'name': 'version', 'type': 'String'},
},
'type': 'Object',
},
'summary': 'RPC Describe',
'type': 'method',
'validation': True,
}
}
1 change: 1 addition & 0 deletions examples/javascript/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ envtmpdir = {toxworkdir}/tmp/{envname}
constrain_package_deps = true
use_frozen_constraints = true
deps =
flask-jsonrpc@file://{toxinidir}/../../
pytest==8.3.3
pytest-cov==5.0.0
pytest-xdist==3.6.1
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal-async/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = {file = "LICENSE.txt"}
authors = [{name = "Nycholas Oliveira", email = "[email protected]"}]
maintainers = [{name = "Cenobit Technologies Inc.", email = "[email protected]"}]
requires-python = ">=3.9"
dependencies = ["Flask-JSONRPC@git+https://github.com/cenobites/flask-jsonrpc", "Flask[async]>=3.0.0,<4.0"]
dependencies = ["Flask-JSONRPC", "Flask[async]>=3.0.0,<4.0"]

[project.optional-dependencies]
test = ["pytest"]
Expand Down
3 changes: 1 addition & 2 deletions examples/minimal-async/src/minimal_async/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
# POSSIBILITY OF SUCH DAMAGE.
import typing as t
import asyncio
from numbers import Real

from flask import Flask, request

Expand Down Expand Up @@ -116,7 +115,7 @@ async def fails_with_custom_exception(_string: t.Optional[str] = None) -> t.NoRe


@jsonrpc.method('App.sum')
async def sum_(a: Real, b: Real) -> Real:
async def sum_(a: float, b: float) -> float:
await asyncio.sleep(0)
return a + b

Expand Down
108 changes: 78 additions & 30 deletions examples/minimal-async/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,99 +189,147 @@ def test_rpc_describe(client: 'FlaskClient') -> None:
assert data['id'] == 1
assert data['jsonrpc'] == '2.0'
assert data['result']['name'] == 'Flask-JSONRPC'
assert data['result']['version'] == '2.0'
assert data['result']['version'] == '1.0.0'
assert data['result']['servers'] is not None
assert 'url' in data['result']['servers'][0]
assert data['result']['methods'] == {
'App.argsValidate': {
'options': {'notification': True, 'validate': True},
'name': 'App.argsValidate',
'notification': True,
'params': [
{'name': 'a1', 'type': 'Number'},
{'name': 'a2', 'type': 'String'},
{'name': 'a3', 'type': 'Boolean'},
{'name': 'a4', 'type': 'Array'},
{'name': 'a5', 'type': 'Object'},
],
'returns': {'type': 'String'},
'returns': {'name': 'default', 'type': 'String'},
'type': 'method',
'validation': True,
},
'App.divide': {
'options': {'notification': True, 'validate': True},
'name': 'App.divide',
'notification': True,
'params': [{'name': 'a', 'type': 'Number'}, {'name': 'b', 'type': 'Number'}],
'returns': {'type': 'Number'},
'returns': {'name': 'default', 'type': 'Number'},
'type': 'method',
'validation': True,
},
'App.fails': {
'options': {'notification': True, 'validate': True},
'name': 'App.fails',
'notification': True,
'params': [{'name': '_string', 'type': 'String'}],
'returns': {'type': 'Null'},
'returns': {'name': 'default', 'type': 'Null'},
'type': 'method',
'validation': True,
},
'App.failsWithCustomException': {
'options': {'notification': True, 'validate': True},
'name': 'App.failsWithCustomException',
'notification': True,
'params': [{'name': '_string', 'type': 'String'}],
'returns': {'type': 'Null'},
'returns': {'name': 'default', 'type': 'Null'},
'type': 'method',
'validation': True,
},
'App.greeting': {
'options': {'notification': True, 'validate': True},
'name': 'App.greeting',
'notification': True,
'params': [{'name': 'name', 'type': 'String'}],
'returns': {'type': 'String'},
'returns': {'name': 'default', 'type': 'String'},
'type': 'method',
'validation': True,
},
'App.helloDefaultArgs': {
'options': {'notification': True, 'validate': True},
'name': 'App.helloDefaultArgs',
'notification': True,
'params': [{'name': 'string', 'type': 'String'}],
'returns': {'type': 'String'},
'returns': {'name': 'default', 'type': 'String'},
'type': 'method',
'validation': True,
},
'App.index': {
'options': {'notification': True, 'validate': True},
'name': 'App.index',
'notification': True,
'params': [],
'returns': {'type': 'String'},
'returns': {'name': 'default', 'type': 'String'},
'type': 'method',
'validation': True,
},
'App.multiDecorators': {
'options': {'notification': True, 'validate': True},
'name': 'App.multiDecorators',
'notification': True,
'params': [],
'returns': {'type': 'Object'},
'returns': {'name': 'default', 'type': 'Object'},
'type': 'method',
'validation': True,
},
'App.multiply': {
'options': {'notification': True, 'validate': True},
'name': 'App.multiply',
'notification': True,
'params': [{'name': 'a', 'type': 'Number'}, {'name': 'b', 'type': 'Number'}],
'returns': {'type': 'Number'},
'returns': {'name': 'default', 'type': 'Number'},
'type': 'method',
'validation': True,
},
'App.notNotify': {
'options': {'notification': False, 'validate': True},
'name': 'App.notNotify',
'notification': False,
'params': [{'name': 'string', 'type': 'String'}],
'returns': {'type': 'String'},
'returns': {'name': 'default', 'type': 'String'},
'type': 'method',
'validation': True,
},
'App.notify': {
'options': {'notification': True, 'validate': True},
'name': 'App.notify',
'notification': True,
'params': [{'name': '_string', 'type': 'String'}],
'returns': {'type': 'Null'},
'returns': {'name': 'default', 'type': 'Null'},
'type': 'method',
'validation': True,
},
'App.oneDecorator': {
'options': {'notification': True, 'validate': True},
'name': 'App.oneDecorator',
'notification': True,
'params': [],
'returns': {'type': 'Object'},
'returns': {'name': 'default', 'type': 'Object'},
'type': 'method',
'validation': True,
},
'App.subtract': {
'options': {'notification': True, 'validate': True},
'name': 'App.subtract',
'notification': True,
'params': [{'name': 'a', 'type': 'Number'}, {'name': 'b', 'type': 'Number'}],
'returns': {'type': 'Number'},
'returns': {'name': 'default', 'type': 'Number'},
'type': 'method',
'validation': True,
},
'App.sum': {
'options': {'notification': True, 'validate': True},
'name': 'App.sum',
'notification': True,
'params': [{'name': 'a', 'type': 'Number'}, {'name': 'b', 'type': 'Number'}],
'returns': {'type': 'Number'},
'returns': {'name': 'default', 'type': 'Number'},
'type': 'method',
'validation': True,
},
'rpc.describe': {
'name': 'rpc.describe',
'notification': False,
'params': [],
'returns': {
'name': 'default',
'properties': {
'description': {'name': 'description', 'type': 'String'},
'id': {'name': 'id', 'type': 'String'},
'methods': {'name': 'methods', 'type': 'Null'},
'name': {'name': 'name', 'type': 'String'},
'servers': {'name': 'servers', 'type': 'Null'},
'title': {'name': 'title', 'type': 'String'},
'version': {'name': 'version', 'type': 'String'},
},
'type': 'Object',
},
'summary': 'RPC Describe',
'type': 'method',
'validation': True,
},
'rpc.describe': {'options': {}, 'params': [], 'returns': {'type': 'Object'}, 'type': 'method'},
}
1 change: 1 addition & 0 deletions examples/minimal-async/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ envtmpdir = {toxworkdir}/tmp/{envname}
constrain_package_deps = true
use_frozen_constraints = true
deps =
flask-jsonrpc@file://{toxinidir}/../../
pytest==8.3.3
pytest-cov==5.0.0
pytest-xdist==3.6.1
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = {file = "LICENSE.txt"}
authors = [{name = "Nycholas Oliveira", email = "[email protected]"}]
maintainers = [{name = "Cenobit Technologies Inc.", email = "[email protected]"}]
requires-python = ">=3.9"
dependencies = ["Flask-JSONRPC@git+https://github.com/cenobites/flask-jsonrpc"]
dependencies = ["Flask-JSONRPC"]

[project.optional-dependencies]
async = ["Flask[async]>=3.0.0,<4.0"]
Expand Down
3 changes: 1 addition & 2 deletions examples/minimal/src/minimal/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import typing as t
from numbers import Real

from flask import Flask, request

Expand Down Expand Up @@ -105,7 +104,7 @@ def fails_with_custom_exception(_string: t.Optional[str] = None) -> t.NoReturn:


@jsonrpc.method('App.sum')
def sum_(a: Real, b: Real) -> Real:
def sum_(a: float, b: float) -> float:
return a + b


Expand Down
Loading
Loading