Skip to content

Commit aa70926

Browse files
authored
Automatically add future annotations import (#58)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
1 parent 6ca9c3a commit aa70926

48 files changed

Lines changed: 256 additions & 91 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

conformance/test/_util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import asyncio
24
import sys
35

conformance/test/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
from __future__ import annotations
2+
13
import argparse
24
import asyncio
35
import ssl
46
import sys
57
import time
68
import traceback
7-
from collections.abc import AsyncIterator, Iterator
89
from tempfile import NamedTemporaryFile
9-
from typing import Literal, TypeVar
10+
from typing import TYPE_CHECKING, Literal, TypeVar
1011

1112
import httpx
1213
from _util import create_standard_streams
@@ -29,14 +30,18 @@
2930
UnaryRequest,
3031
UnimplementedRequest,
3132
)
32-
from google.protobuf.any_pb2 import Any
3333
from google.protobuf.message import Message
3434

3535
from connectrpc.client import ResponseMetadata
3636
from connectrpc.code import Code
3737
from connectrpc.errors import ConnectError
3838
from connectrpc.request import Headers
3939

40+
if TYPE_CHECKING:
41+
from collections.abc import AsyncIterator, Iterator
42+
43+
from google.protobuf.any_pb2 import Any
44+
4045

4146
def _convert_code(error: Code) -> ConformanceCode:
4247
match error:

conformance/test/gen/connectrpc/conformance/v1/service_connect.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# Generated by https://github.com/connectrpc/connect-python. DO NOT EDIT!
22
# source: connectrpc/conformance/v1/service.proto
3+
from __future__ import annotations
34

4-
from collections.abc import AsyncGenerator, AsyncIterator, Iterable, Iterator, Mapping
5-
from typing import Protocol
5+
from typing import TYPE_CHECKING, Protocol
66

77
from connectrpc.client import ConnectClient, ConnectClientSync
88
from connectrpc.code import Code
99
from connectrpc.errors import ConnectError
10-
from connectrpc.interceptor import Interceptor, InterceptorSync
1110
from connectrpc.method import IdempotencyLevel, MethodInfo
12-
from connectrpc.request import Headers, RequestContext
1311
from connectrpc.server import (
1412
ConnectASGIApplication,
1513
ConnectWSGIApplication,
@@ -19,6 +17,18 @@
1917

2018
from . import service_pb2 as connectrpc_dot_conformance_dot_v1_dot_service__pb2
2119

20+
if TYPE_CHECKING:
21+
from collections.abc import (
22+
AsyncGenerator,
23+
AsyncIterator,
24+
Iterable,
25+
Iterator,
26+
Mapping,
27+
)
28+
29+
from connectrpc.interceptor import Interceptor, InterceptorSync
30+
from connectrpc.request import Headers, RequestContext
31+
2232

2333
class ConformanceService(Protocol):
2434
async def unary(

conformance/test/server.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import argparse
24
import asyncio
35
import os
@@ -7,7 +9,6 @@
79
import ssl
810
import sys
911
import time
10-
from collections.abc import AsyncIterator, Iterator
1112
from contextlib import ExitStack, closing
1213
from tempfile import NamedTemporaryFile
1314
from typing import TYPE_CHECKING, Literal, TypeVar, get_args
@@ -43,14 +44,17 @@
4344

4445
from connectrpc.code import Code
4546
from connectrpc.errors import ConnectError
46-
from connectrpc.request import RequestContext
4747

4848
if TYPE_CHECKING:
49+
from collections.abc import AsyncIterator, Iterator
50+
4951
from google.protobuf.message import Message
5052

53+
from connectrpc.request import RequestContext
54+
5155

5256
# TODO: Use google.protobuf.any.pack on upgrade to protobuf==6.
53-
def pack(msg: "Message") -> Any:
57+
def pack(msg: Message) -> Any:
5458
any_msg = Any()
5559
any_msg.Pack(msg)
5660
return any_msg

conformance/test/test_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import subprocess
24
import sys
35
from pathlib import Path

conformance/test/test_server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os
24
import subprocess
35
import sys

example/example/_eliza.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
from __future__ import annotations
2+
13
import random
24
import re
3-
from collections.abc import Sequence
5+
from typing import TYPE_CHECKING
6+
7+
if TYPE_CHECKING:
8+
from collections.abc import Sequence
49

510
# Ported from https://github.com/connectrpc/examples-go
611
# Originally from https://github.com/mattshiel/eliza-go

example/example/eliza_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import asyncio
24

35
from example.eliza_connect import ElizaServiceClient

example/example/eliza_client_sync.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from example.eliza_connect import ElizaServiceClientSync
24
from example.eliza_pb2 import IntroduceRequest, SayRequest
35

example/example/eliza_connect.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# Generated by https://github.com/connectrpc/connect-python. DO NOT EDIT!
22
# source: example/eliza.proto
3+
from __future__ import annotations
34

4-
from collections.abc import AsyncGenerator, AsyncIterator, Iterable, Iterator, Mapping
5-
from typing import Protocol
5+
from typing import TYPE_CHECKING, Protocol
66

77
from connectrpc.client import ConnectClient, ConnectClientSync
88
from connectrpc.code import Code
99
from connectrpc.errors import ConnectError
10-
from connectrpc.interceptor import Interceptor, InterceptorSync
1110
from connectrpc.method import IdempotencyLevel, MethodInfo
12-
from connectrpc.request import Headers, RequestContext
1311
from connectrpc.server import (
1412
ConnectASGIApplication,
1513
ConnectWSGIApplication,
@@ -19,6 +17,18 @@
1917

2018
import example.eliza_pb2 as example_dot_eliza__pb2
2119

20+
if TYPE_CHECKING:
21+
from collections.abc import (
22+
AsyncGenerator,
23+
AsyncIterator,
24+
Iterable,
25+
Iterator,
26+
Mapping,
27+
)
28+
29+
from connectrpc.interceptor import Interceptor, InterceptorSync
30+
from connectrpc.request import Headers, RequestContext
31+
2232

2333
class ElizaService(Protocol):
2434
async def say(

0 commit comments

Comments
 (0)