aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTres Seaver <tseaver@palladion.com>2021-11-02 18:12:55 -0400
committerGitHub <noreply@github.com>2021-11-02 17:12:55 -0500
commitffc51f03c7ce5d9f009ba859b8df385d52925578 (patch)
tree6a6a8efb7b34f64cedc00daaa5e729f79376213a
parentd2a729e0c42039bfbcd4b59c3d97d8759a9f0d57 (diff)
downloadpython-api-core-ffc51f03c7ce5d9f009ba859b8df385d52925578.tar.gz
fix: make 'gapic_v1.method.DEFAULT' a typed object (#292)
FBO checkers which need to verify default values for 'retry' / 'timeout'
-rw-r--r--google/api_core/gapic_v1/method.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/google/api_core/gapic_v1/method.py b/google/api_core/gapic_v1/method.py
index 79722c0..73c8d4b 100644
--- a/google/api_core/gapic_v1/method.py
+++ b/google/api_core/gapic_v1/method.py
@@ -18,6 +18,7 @@ This is used by gapic clients to provide common error mapping, retry, timeout,
pagination, and long-running operations to gRPC methods.
"""
+import enum
import functools
from google.api_core import grpc_helpers
@@ -25,7 +26,18 @@ from google.api_core import timeout
from google.api_core.gapic_v1 import client_info
USE_DEFAULT_METADATA = object()
-DEFAULT = object()
+
+
+class _MethodDefault(enum.Enum):
+ # Uses enum so that pytype/mypy knows that this is the only possible value.
+ # https://stackoverflow.com/a/60605919/101923
+ #
+ # Literal[_DEFAULT_VALUE] is an alternative, but only added in Python 3.8.
+ # https://docs.python.org/3/library/typing.html#typing.Literal
+ _DEFAULT_VALUE = object()
+
+
+DEFAULT = _MethodDefault._DEFAULT_VALUE
"""Sentinel value indicating that a retry or timeout argument was unspecified,
so the default should be used."""