Skip to content

Commit df58fdf

Browse files
fix: Enable pytype on Pub/Sub Lite repo and fix all errors (#214)
* chore: Enable pytype on Pub/Sub Lite repo and fix all errors * chore: fix GapicConnection typing * chore: no empty string notimplementederror
1 parent f441d31 commit df58fdf

31 files changed

+127
-85
lines changed

google/cloud/pubsublite/admin_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from google.api_core.client_options import ClientOptions
1919
from google.api_core.operation import Operation
2020
from google.auth.credentials import Credentials
21-
from google.protobuf.field_mask_pb2 import FieldMask
21+
from google.protobuf.field_mask_pb2 import FieldMask # pytype: disable=pyi-error
2222

2323
from google.cloud.pubsublite.admin_client_interface import AdminClientInterface
2424
from google.cloud.pubsublite.internal.constructable_from_service_account import (

google/cloud/pubsublite/admin_client_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
)
2828
from google.cloud.pubsublite.types.paths import ReservationPath
2929
from google.cloud.pubsublite_v1 import Topic, Subscription, Reservation
30-
from google.protobuf.field_mask_pb2 import FieldMask
30+
from google.protobuf.field_mask_pb2 import FieldMask # pytype: disable=pyi-error
3131

3232

3333
class AdminClientInterface(ABC):

google/cloud/pubsublite/cloudpubsub/internal/ack_set_tracker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from abc import abstractmethod
15+
from abc import abstractmethod, ABCMeta
1616
from typing import AsyncContextManager
1717

1818

19-
class AckSetTracker(AsyncContextManager):
19+
class AckSetTracker(AsyncContextManager, metaclass=ABCMeta):
2020
"""
2121
An AckSetTracker tracks disjoint acknowledged messages and commits them when a contiguous prefix of tracked offsets
2222
is aggregated.

google/cloud/pubsublite/cloudpubsub/internal/make_subscriber.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ def _make_dynamic_assigner(
8888
credentials: Optional[Credentials],
8989
base_metadata: Optional[Mapping[str, str]],
9090
) -> Assigner:
91+
if base_metadata is None:
92+
base_metadata = {}
93+
9194
def assignment_connection_factory(
9295
requests: AsyncIterator[PartitionAssignmentRequest],
9396
):

google/cloud/pubsublite/cloudpubsub/internal/single_partition_subscriber.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def str(self) -> str:
5151
return json.dumps({"generation": self.generation, "offset": self.offset})
5252

5353
@staticmethod
54-
def parse(payload: str) -> "_AckId":
54+
def parse(payload: str) -> "_AckId": # pytype: disable=invalid-annotation
5555
loaded = json.loads(payload)
5656
return _AckId(
5757
generation=int(loaded["generation"]), offset=int(loaded["offset"]),

google/cloud/pubsublite/cloudpubsub/internal/single_publisher.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from abc import abstractmethod
15+
from abc import abstractmethod, ABCMeta
1616
from typing import AsyncContextManager, Mapping, ContextManager
1717
from concurrent import futures
1818

1919

20-
class AsyncSinglePublisher(AsyncContextManager):
20+
class AsyncSinglePublisher(AsyncContextManager, metaclass=ABCMeta):
2121
"""
2222
An AsyncPublisher publishes messages similar to Google Pub/Sub, but must be used in an
2323
async context. Any publish failures are permanent.
@@ -43,9 +43,10 @@ async def publish(
4343
Raises:
4444
GoogleApiCallError: On a permanent failure.
4545
"""
46+
raise NotImplementedError()
4647

4748

48-
class SinglePublisher(ContextManager):
49+
class SinglePublisher(ContextManager, metaclass=ABCMeta):
4950
"""
5051
A Publisher publishes messages similar to Google Pub/Sub. Any publish failures are permanent.
5152
@@ -70,3 +71,4 @@ def publish(
7071
Raises:
7172
GoogleApiCallError: On a permanent failure.
7273
"""
74+
raise NotImplementedError()

google/cloud/pubsublite/cloudpubsub/internal/single_subscriber.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from abc import abstractmethod
15+
from abc import abstractmethod, ABCMeta
1616
from typing import AsyncContextManager, Callable, Set, Optional
1717

1818
from google.cloud.pubsub_v1.subscriber.message import Message
@@ -24,7 +24,7 @@
2424
)
2525

2626

27-
class AsyncSingleSubscriber(AsyncContextManager):
27+
class AsyncSingleSubscriber(AsyncContextManager, metaclass=ABCMeta):
2828
"""
2929
A Cloud Pub/Sub asynchronous subscriber.
3030

google/cloud/pubsublite/cloudpubsub/message_transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import datetime
1616

1717
from google.api_core.exceptions import InvalidArgument
18-
from google.protobuf.timestamp_pb2 import Timestamp
18+
from google.protobuf.timestamp_pb2 import Timestamp # pytype: disable=pyi-error
1919
from google.pubsub_v1 import PubsubMessage
2020

2121
from google.cloud.pubsublite.cloudpubsub import MessageTransformer

google/cloud/pubsublite/cloudpubsub/publisher_client_interface.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from abc import abstractmethod
15+
from abc import abstractmethod, ABCMeta
1616
from concurrent.futures import Future
1717
from typing import ContextManager, Mapping, Union, AsyncContextManager
1818

1919
from google.cloud.pubsublite.types import TopicPath
2020

2121

22-
class AsyncPublisherClientInterface(AsyncContextManager):
22+
class AsyncPublisherClientInterface(AsyncContextManager, metaclass=ABCMeta):
2323
"""
2424
An AsyncPublisherClientInterface publishes messages similar to Google Pub/Sub, but must be used in an
2525
async context. Any publish failures are unlikely to succeed if retried.
@@ -50,9 +50,10 @@ async def publish(
5050
Raises:
5151
GoogleApiCallError: On a permanent failure.
5252
"""
53+
raise NotImplementedError()
5354

5455

55-
class PublisherClientInterface(ContextManager):
56+
class PublisherClientInterface(ContextManager, metaclass=ABCMeta):
5657
"""
5758
A PublisherClientInterface publishes messages similar to Google Pub/Sub.
5859
Any publish failures are unlikely to succeed if retried.
@@ -84,3 +85,4 @@ def publish(
8485
Raises:
8586
GoogleApiCallError: On a permanent failure.
8687
"""
88+
raise NotImplementedError()

google/cloud/pubsublite/cloudpubsub/subscriber_client_interface.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from abc import abstractmethod
15+
from abc import abstractmethod, ABCMeta
1616
from typing import (
1717
ContextManager,
1818
Union,
@@ -33,7 +33,7 @@
3333
)
3434

3535

36-
class AsyncSubscriberClientInterface(AsyncContextManager):
36+
class AsyncSubscriberClientInterface(AsyncContextManager, metaclass=ABCMeta):
3737
"""
3838
An AsyncSubscriberClientInterface reads messages similar to Google Pub/Sub, but must be used in an
3939
async context.
@@ -64,12 +64,13 @@ async def subscribe(
6464
Raises:
6565
GoogleApiCallError: On a permanent failure.
6666
"""
67+
raise NotImplementedError()
6768

6869

6970
MessageCallback = Callable[[Message], None]
7071

7172

72-
class SubscriberClientInterface(ContextManager):
73+
class SubscriberClientInterface(ContextManager, metaclass=ABCMeta):
7374
"""
7475
A SubscriberClientInterface reads messages similar to Google Pub/Sub.
7576
Any subscribe failures are unlikely to succeed if retried.
@@ -103,3 +104,4 @@ def subscribe(
103104
Raises:
104105
GoogleApiCallError: On a permanent failure.
105106
"""
107+
raise NotImplementedError()

0 commit comments

Comments
 (0)