Skip to content

Commit ffc51f0

Browse files
authored
fix: make 'gapic_v1.method.DEFAULT' a typed object (#292)
FBO checkers which need to verify default values for 'retry' / 'timeout'
1 parent d2a729e commit ffc51f0

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

google/api_core/gapic_v1/method.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,26 @@
1818
pagination, and long-running operations to gRPC methods.
1919
"""
2020

21+
import enum
2122
import functools
2223

2324
from google.api_core import grpc_helpers
2425
from google.api_core import timeout
2526
from google.api_core.gapic_v1 import client_info
2627

2728
USE_DEFAULT_METADATA = object()
28-
DEFAULT = object()
29+
30+
31+
class _MethodDefault(enum.Enum):
32+
# Uses enum so that pytype/mypy knows that this is the only possible value.
33+
# https://stackoverflow.com/a/60605919/101923
34+
#
35+
# Literal[_DEFAULT_VALUE] is an alternative, but only added in Python 3.8.
36+
# https://docs.python.org/3/library/typing.html#typing.Literal
37+
_DEFAULT_VALUE = object()
38+
39+
40+
DEFAULT = _MethodDefault._DEFAULT_VALUE
2941
"""Sentinel value indicating that a retry or timeout argument was unspecified,
3042
so the default should be used."""
3143

0 commit comments

Comments
 (0)