Skip to content

Commit

Permalink
Merge pull request #27 from dapper91/dev
Browse files Browse the repository at this point in the history
- pydantic schema generation bug fixed
- method registry merge implementation changed
  • Loading branch information
dapper91 authored Aug 10, 2021
2 parents 048938d + 8679b22 commit d0e7504
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

1.2.3 (2021-08-10)
------------------

- pydantic schema generation bug fixed
- method registry merge implementation changed


1.2.2 (2021-07-28)
------------------

Expand Down
7 changes: 7 additions & 0 deletions docs/source/_static/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.py.class {
padding: 1.5em 0em 1.5em;
}

.py.method, .py.property, .py.exception, .py.function {
padding: 0.5em 0em 0.5em;
}
17 changes: 16 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.

import enum
import os
import sys

sys.path.insert(0, os.path.abspath('..'))

import pjrpc # noqa
Expand Down Expand Up @@ -66,6 +68,8 @@
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

html_css_files = ['css/custom.css']

# The master toctree document.
master_doc = 'index'

Expand All @@ -76,5 +80,16 @@
}

autodoc_mock_imports = ['attrs']
autodoc_typehints = 'none'
autodoc_typehints = 'description'
autodoc_member_order = 'bysource'


def maybe_skip_member(app, what, name, obj, skip, options):
if isinstance(obj, enum.Enum):
return False

return None


def setup(app):
app.connect('autodoc-skip-member', maybe_skip_member)
4 changes: 2 additions & 2 deletions examples/aiohttp_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ async def add_user_v2(request: web.Request, user: dict):

app_v1 = aiohttp.Application()
app_v1.dispatcher.add_methods(methods_v1)
app.add_subapp('/api/v1', app_v1)
app.add_subapp('/api/v1', app_v1.app)


app_v2 = aiohttp.Application()
app_v2.dispatcher.add_methods(methods_v2)
app.add_subapp('/api/v2', app_v2)
app.add_subapp('/api/v2', app_v2.app)

if __name__ == "__main__":
web.run_app(app, host='localhost', port=8080)
2 changes: 1 addition & 1 deletion pjrpc/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__description__ = 'Extensible JSON-RPC library'
__url__ = 'https://github.com/dapper91/pjrpc'

__version__ = '1.2.2'
__version__ = '1.2.3'

__author__ = 'Dmitry Pershin'
__email__ = '[email protected]'
Expand Down
4 changes: 2 additions & 2 deletions pjrpc/server/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ def merge(self, other: 'MethodRegistry') -> None:
"""

for name, method in other.items():
if other._prefix:
name = utils.remove_prefix(name, f'{other._prefix}.')
if self._prefix:
name = f'{self._prefix}.{name}'

Expand Down Expand Up @@ -254,6 +252,8 @@ class Dispatcher:
:param json_dumper: response json dumper
:param json_encoder: response json encoder
:param json_decoder: request json decoder
:param middlewares: request middlewares
:param error_handlers: request error handlers
"""

def __init__(
Expand Down
6 changes: 3 additions & 3 deletions pjrpc/server/validators/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ def build_validation_schema(self, signature: inspect.Signature) -> Dict[str, Any
for param in signature.parameters.values():
if param.kind is inspect.Parameter.VAR_KEYWORD:
field_definitions[param.name] = (
Optional[Dict[str, param.annotation]] if param.annotation is not inspect.Parameter.empty else ...,
Optional[Dict[str, param.annotation]] if param.annotation is not inspect.Parameter.empty else Any,
param.default if param.default is not inspect.Parameter.empty else None,
)
elif param.kind is inspect.Parameter.VAR_POSITIONAL:
field_definitions[param.name] = (
Optional[List[param.annotation]] if param.annotation is not inspect.Parameter.empty else ...,
Optional[List[param.annotation]] if param.annotation is not inspect.Parameter.empty else Any,
param.default if param.default is not inspect.Parameter.empty else None,
)
else:
field_definitions[param.name] = (
param.annotation if param.annotation is not inspect.Parameter.empty else ...,
param.annotation if param.annotation is not inspect.Parameter.empty else Any,
param.default if param.default is not inspect.Parameter.empty else ...,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/server/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_method():

assert list(registry2.items()) == [
('prefix2.method2', Method(test_method, 'prefix2.method2', 'ctx2')),
('prefix2.method1', Method(test_method, 'prefix2.method1', 'ctx1')),
('prefix2.prefix1.method1', Method(test_method, 'prefix2.prefix1.method1', 'ctx1')),
]


Expand Down
2 changes: 2 additions & 0 deletions tests/server/test_pydantic_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
('param1: int = 1', {}),
('param1: int, param2: int = 2', {'param1': 1}),
('param1: int, *, param2: int = 2', {'param1': 1}),
('param1, param2: int', [1, 2]),
('param1, param2: int', ['param1', 2]),
], indirect=['dyn_method'],
)
def test_validation_success(dyn_method, params):
Expand Down

0 comments on commit d0e7504

Please sign in to comment.