From 19da5ff860e0352d628ae44520c546ba3f11c0c2 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 8 Jan 2020 17:58:31 +0100 Subject: [PATCH 1/3] Enable --disallow-subclassing-any Closes: #1446 --- tests/mypy_test.py | 1 + third_party/2and3/google/protobuf/internal/containers.pyi | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/mypy_test.py b/tests/mypy_test.py index 48ad62e98a2e..4fae05b3bc18 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -135,6 +135,7 @@ def main(): flags.append('--show-traceback') flags.append('--no-implicit-optional') flags.append('--disallow-any-generics') + flags.append('--disallow-subclassing-any') if args.warn_unused_ignores: flags.append('--warn-unused-ignores') if args.platform: diff --git a/third_party/2and3/google/protobuf/internal/containers.pyi b/third_party/2and3/google/protobuf/internal/containers.pyi index fc97c7330ce3..222bc7c6612a 100644 --- a/third_party/2and3/google/protobuf/internal/containers.pyi +++ b/third_party/2and3/google/protobuf/internal/containers.pyi @@ -50,7 +50,8 @@ class RepeatedCompositeFieldContainer(BaseContainer[_T]): def __eq__(self, other: object) -> bool: ... # Classes not yet typed -class Mapping(Any): ... +class Mapping(object): ... + def __getattr__(self, name: str) -> Any: ... # incomplete class MutableMapping(Mapping): ... class ScalarMap(MutableMapping): ... class MessageMap(MutableMapping): ... From 3e553e0917e59aa8e39f9b914abf0354e4dbe7b4 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 8 Jan 2020 18:21:53 +0100 Subject: [PATCH 2/3] Fix --- third_party/2and3/google/protobuf/internal/containers.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/2and3/google/protobuf/internal/containers.pyi b/third_party/2and3/google/protobuf/internal/containers.pyi index 222bc7c6612a..2b0a5f1e196a 100644 --- a/third_party/2and3/google/protobuf/internal/containers.pyi +++ b/third_party/2and3/google/protobuf/internal/containers.pyi @@ -50,7 +50,7 @@ class RepeatedCompositeFieldContainer(BaseContainer[_T]): def __eq__(self, other: object) -> bool: ... # Classes not yet typed -class Mapping(object): ... +class Mapping(object): def __getattr__(self, name: str) -> Any: ... # incomplete class MutableMapping(Mapping): ... class ScalarMap(MutableMapping): ... From 6e274fbace3a21dfb59205da2c77b7a13b9d2c62 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 8 Jan 2020 19:21:07 +0100 Subject: [PATCH 3/3] Work around missing stubs --- third_party/2/fb303/FacebookService.pyi | 2 +- third_party/2/scribe/scribe.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/2/fb303/FacebookService.pyi b/third_party/2/fb303/FacebookService.pyi index ead5d24fe7a3..763c3c83aa1e 100644 --- a/third_party/2/fb303/FacebookService.pyi +++ b/third_party/2/fb303/FacebookService.pyi @@ -58,7 +58,7 @@ class Client(Iface): def shutdown(self): ... def send_shutdown(self): ... -class Processor(Iface, TProcessor): +class Processor(Iface, TProcessor): # type: ignore def __init__(self, handler) -> None: ... def process(self, iprot, oprot): ... def process_getName(self, seqid, iprot, oprot): ... diff --git a/third_party/2/scribe/scribe.pyi b/third_party/2/scribe/scribe.pyi index 3530bf80a809..c170447e14c8 100644 --- a/third_party/2/scribe/scribe.pyi +++ b/third_party/2/scribe/scribe.pyi @@ -13,7 +13,7 @@ class Client(fb303.FacebookService.Client, Iface): def send_Log(self, messages): ... def recv_Log(self): ... -class Processor(fb303.FacebookService.Processor, Iface, TProcessor): +class Processor(fb303.FacebookService.Processor, Iface, TProcessor): # type: ignore def __init__(self, handler) -> None: ... def process(self, iprot, oprot): ... def process_Log(self, seqid, iprot, oprot): ...