Skip to content

Commit d404454

Browse files
authored
Merge pull request #98 from dapper91/dev
- client headers passing bug fixed.
2 parents 21edb43 + cbe54a0 commit d404454

File tree

12 files changed

+44
-104
lines changed

12 files changed

+44
-104
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ default_stages:
44

55
repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v4.4.0
7+
rev: v4.5.0
88
hooks:
99
- id: check-yaml
1010
- id: check-toml
@@ -25,21 +25,21 @@ repos:
2525
args:
2626
- --fix=no
2727
- repo: https://github.com/asottile/add-trailing-comma
28-
rev: v3.0.0
28+
rev: v3.1.0
2929
hooks:
3030
- id: add-trailing-comma
3131
stages:
3232
- commit
3333
- repo: https://github.com/pre-commit/mirrors-autopep8
34-
rev: v2.0.2
34+
rev: v2.0.4
3535
hooks:
3636
- id: autopep8
3737
stages:
3838
- commit
3939
args:
4040
- --diff
4141
- repo: https://github.com/pycqa/flake8
42-
rev: 6.0.0
42+
rev: 6.1.0
4343
hooks:
4444
- id: flake8
4545
- repo: https://github.com/pycqa/isort
@@ -63,11 +63,16 @@ repos:
6363
- --multi-line=9
6464
- --project=pjrpc
6565
- repo: https://github.com/pre-commit/mirrors-mypy
66-
rev: v1.4.1
66+
rev: v1.7.1
6767
hooks:
6868
- id: mypy
6969
stages:
7070
- commit
7171
name: mypy
7272
pass_filenames: false
7373
args: ["--package", "pjrpc"]
74+
additional_dependencies:
75+
- aiohttp>=3.7
76+
- httpx>=0.23.0
77+
- pydantic>=2.0
78+
- types-requests>=2.0

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
1.8.1 (2023-11-28)
5+
------------------
6+
7+
- client headers passing bug fixed.
8+
9+
410
1.8.0 (2023-09-26)
511
------------------
612

examples/aio_pika_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def add_user(message: aio_pika.IncomingMessage, user_info: UserInfo) -> AddedUse
5151

5252

5353
executor = integration.Executor(
54-
broker_url=URL('amqp://guest:guest@localhost:5672/v1'), queue_name='jsonrpc'
54+
broker_url=URL('amqp://guest:guest@localhost:5672/v1'), queue_name='jsonrpc',
5555
)
5656
executor.dispatcher.add_methods(methods)
5757

pjrpc/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__description__ = 'Extensible JSON-RPC library'
33
__url__ = 'https://github.com/dapper91/pjrpc'
44

5-
__version__ = '1.8.0'
5+
__version__ = '1.8.1'
66

77
__author__ = 'Dmitry Pershin'
88
__email__ = '[email protected]'

pjrpc/client/backend/aiohttp.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ async def _request(self, request_text: str, is_notification: bool = False, **kwa
3434
:returns: response text
3535
"""
3636

37-
kwargs = {
38-
'headers': {'Content-Type': pjrpc.common.DEFAULT_CONTENT_TYPE},
39-
**kwargs,
40-
}
37+
headers = kwargs.setdefault('headers', {})
38+
headers['Content-Type'] = pjrpc.common.DEFAULT_CONTENT_TYPE
4139

4240
resp = await self._session.post(self._endpoint, data=request_text, **kwargs)
4341
resp.raise_for_status()

pjrpc/client/backend/httpx.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List, Optional
1+
from typing import Any, List, Optional
22

33
import httpx
44

@@ -29,10 +29,8 @@ def _request(self, request_text: str, is_notification: bool = False, **kwargs: A
2929
:returns: response text
3030
"""
3131

32-
kwargs: Dict[str, Any] = {
33-
'headers': {'Content-Type': pjrpc.common.DEFAULT_CONTENT_TYPE},
34-
**kwargs,
35-
}
32+
headers = kwargs.setdefault('headers', {})
33+
headers['Content-Type'] = pjrpc.common.DEFAULT_CONTENT_TYPE
3634

3735
resp = self._client.post(self._endpoint, content=request_text, **kwargs)
3836
resp.raise_for_status()
@@ -84,10 +82,8 @@ async def _request(self, request_text: str, is_notification: bool = False, **kwa
8482
:returns: response text
8583
"""
8684

87-
kwargs: Dict[str, Any] = {
88-
'headers': {'Content-Type': pjrpc.common.DEFAULT_CONTENT_TYPE},
89-
**kwargs,
90-
}
85+
headers = kwargs.setdefault('headers', {})
86+
headers['Content-Type'] = pjrpc.common.DEFAULT_CONTENT_TYPE
9187

9288
resp = await self._client.post(self._endpoint, content=request_text, **kwargs)
9389
resp.raise_for_status()

pjrpc/client/backend/requests.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ def _request(self, request_text: str, is_notification: bool = False, **kwargs: A
2929
:returns: response text
3030
"""
3131

32-
kwargs = {
33-
'headers': {'Content-Type': pjrpc.common.DEFAULT_CONTENT_TYPE},
34-
**kwargs,
35-
}
32+
headers = kwargs.setdefault('headers', {})
33+
headers['Content-Type'] = pjrpc.common.DEFAULT_CONTENT_TYPE
3634

3735
resp = self._session.post(self._endpoint, data=request_text, **kwargs)
3836
resp.raise_for_status()

pjrpc/common/common.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import json
2-
import sys
3-
from typing import Any, Dict, TypeVar, Union
4-
5-
if sys.version_info >= (3, 8):
6-
from typing import Literal
7-
FalseType = Literal[False]
8-
else:
9-
FalseType = bool
2+
from typing import Any, Dict, Literal, TypeVar, Union
103

114
import pjrpc
125
from pjrpc.common.typedefs import Json # noqa: for back compatibility
@@ -18,7 +11,7 @@ class UnsetType:
1811
Used to distinct unset (missing) values from ``None`` ones.
1912
"""
2013

21-
def __bool__(self) -> FalseType:
14+
def __bool__(self) -> Literal[False]:
2215
return False
2316

2417
def __repr__(self) -> str:

pjrpc/server/dispatcher.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,12 @@ async def dispatch(self, request_text: str, context: Optional[Any] = None) -> Op
537537
else:
538538
if isinstance(request, BatchRequest):
539539
response = self._batch_response(
540-
*filter(
541-
lambda resp: resp is not UNSET, await asyncio.gather(
542-
*(self._handle_request(request, context) for request in request),
543-
),
540+
*(
541+
resp
542+
for resp in await asyncio.gather(*(self._handle_request(req, context) for req in request))
543+
if resp
544544
),
545545
)
546-
547546
else:
548547
response = await self._handle_request(request, context)
549548

pjrpc/server/validators/pydantic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, coerce: bool = True, **config_args: Any):
2424
config_args.setdefault('extra', 'forbid')
2525

2626
# https://pydantic-docs.helpmanual.io/usage/model_config/
27-
self._model_config = pydantic.ConfigDict(**config_args)
27+
self._model_config = pydantic.ConfigDict(**config_args) # type: ignore[typeddict-item]
2828

2929
def validate_method(
3030
self, method: Callable[..., Any], params: Optional['JsonRpcParams'], exclude: Iterable[str] = (), **kwargs: Any,

0 commit comments

Comments
 (0)