Skip to content

Commit f6b4cdf

Browse files
committed
🎨 refactor composite message type
1 parent 46ae53a commit f6b4cdf

24 files changed

+547
-374
lines changed

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
[run]
22
source = grpcalchemy
3+
omit =
4+
grpcalchemy/types.py

.github/workflows/python-package-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
runs-on: windows-latest
4848
strategy:
4949
matrix:
50-
python-version: [3.6, 3.7, 3.8]
50+
python-version: [3.6, 3.7, 3.8, 3.9]
5151

5252
steps:
5353
- uses: actions/checkout@v2

HISTORY.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ History
55
0.7.*(2021-03-20)
66
--------------------
77

8+
* Remove Default Feature in Message
9+
* Refactor Composite Message Type
810
* Support gRPC with xDS
911
* Add `PROTO_AUTO_GENERATED` setting to make runtime proto generation optional
1012

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# relative to the documentation root, use os.path.abspath to make it
1616
# absolute, like shown here.
1717
#
18-
18+
import datetime
1919
import os
2020
import sys
2121
sys.path.insert(0, os.path.abspath('..'))
@@ -44,8 +44,8 @@
4444

4545
# General information about the project.
4646
project = "gRPCAlchemy"
47-
copyright = "2018, GuangTian Li"
48-
author = "GuangTian Li"
47+
copyright = f"{datetime.datetime.now().year}, GuangTianLi"
48+
author = "GuangTianLi"
4949

5050
# The version info for the project you're documenting, acts as replacement
5151
# for |version| and |release|, also used in various other places throughout

docs/usage.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ within the post. Let's take a look at the code of our modified :class:`Post` cla
9999
.. code-block:: python
100100
101101
from typing import List
102-
from grpcalchemy.orm import Message
102+
from grpcalchemy.orm import Message, Repeated
103103
class Post(Message):
104104
title: str
105105
author: User
106-
tags: List[str]
106+
tags: Repeated[str]
107107
108108
The :class:`~grpcalchemy.orm.ListField` object that is used to define a Post's tags
109109
takes a field object as its first argument --- this means that you can have
@@ -130,12 +130,12 @@ We can then define a list of comment documents in our post message:
130130
.. code-block:: python
131131
132132
from typing import List
133-
from grpcalchemy.orm import Message
133+
from grpcalchemy.orm import Message, Repeated
134134
class Post(Message):
135135
title: str
136136
author: User
137-
tags: List[str]
138-
comments: List[Comment]
137+
tags: Repeated[str]
138+
comments: Repeated[Comment]
139139
140140
Defining our gRPC Method
141141
===================================
@@ -167,7 +167,7 @@ Using Iterator to define Stream gRPC Method:
167167
pass
168168
return HelloMessage(text=f'Hello {r.text}')
169169
170-
@StreamStream
170+
@grpcmethod
171171
def StreamStream(self, request: Iterator[HelloMessage], context: Context) -> Iterator[HelloMessage]:
172172
for r in request:
173173
yield HelloMessage(text=f'Hello {r.text}')

grpcalchemy/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
__email__ = "[email protected]"
1010
__version__ = "0.7.2"
1111

12-
__all__ = ["Blueprint", "Context", "grpcmethod", "DefaultConfig", "Server"]
12+
__all__ = ["Blueprint", "Context", "grpcmethod", "DefaultConfig", "Server", "Streaming"]
1313

14-
from .blueprint import Blueprint, Context, grpcmethod
14+
from .blueprint import Blueprint, Context, grpcmethod, Streaming
1515
from .config import DefaultConfig
1616
from .server import Server

grpcalchemy/blueprint.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from .meta import ServiceMeta, __meta__
2323
from .orm import Message
24+
from .types import Streaming
2425

2526
if TYPE_CHECKING: # pragma: no cover
2627
from .server import Server
@@ -280,13 +281,13 @@ def _validate_rpc_method(
280281

281282
request_origin = getattr(request_type, "__origin__", None)
282283
if request_origin:
283-
if issubclass(request_origin, Iterable):
284+
if issubclass(request_origin, Streaming):
284285
request_type = request_type.__args__[0]
285286
request_streaming = True
286287

287288
response_origin = getattr(response_type, "__origin__", None)
288289
if response_origin:
289-
if issubclass(response_origin, Iterable):
290+
if issubclass(response_origin, Streaming):
290291
response_type = response_type.__args__[0]
291292
response_streaming = True
292293
if all(

grpcalchemy/config.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,3 @@ class DefaultConfig(BaseConfig):
5151
#: If set to true, retrieves server configuration via xDS. This is an
5252
#: EXPERIMENTAL option. Only for grpcio >= 1.36.0
5353
GRPC_XDS_SUPPORT = False
54-
55-
#: If set to true, retrieves server configuration via xDS. This is an
56-
#: EXPERIMENTAL option. Only for grpcio >= 1.36.0
57-
GRPC_XDS_SUPPORT = False

0 commit comments

Comments
 (0)