Merge pull request #222 from yilei/push_up_to_523499057
Push up to 523499057
diff --git a/absl/flags/_flag.pyi b/absl/flags/_flag.pyi
index da0638a..8f840be 100644
--- a/absl/flags/_flag.pyi
+++ b/absl/flags/_flag.pyi
@@ -18,6 +18,7 @@
import functools
from absl.flags import _argument_parser
+from absl.flags import _validators_classes
import enum
from typing import Callable, Text, TypeVar, Generic, Iterable, Type, List, Optional, Any, Union, Sequence
@@ -28,29 +29,29 @@
class Flag(Generic[_T]):
- name = ... # type: Text
- default = ... # type: Any
- default_unparsed = ... # type: Any
- default_as_str = ... # type: Optional[Text]
- help = ... # type: Text
- short_name = ... # type: Text
- boolean = ... # type: bool
- present = ... # type: bool
- parser = ... # type: _argument_parser.ArgumentParser[_T]
- serializer = ... # type: _argument_parser.ArgumentSerializer[_T]
- allow_override = ... # type: bool
- allow_override_cpp = ... # type: bool
- allow_hide_cpp = ... # type: bool
- using_default_value = ... # type: bool
- allow_overwrite = ... # type: bool
- allow_using_method_names = ... # type: bool
- validators = ... # type: List[Callable[[Any], bool]]
+ name: Text
+ default: Optional[_T]
+ default_unparsed: Union[Optional[_T], Text]
+ default_as_str: Optional[Text]
+ help: Text
+ short_name: Text
+ boolean: bool
+ present: bool
+ parser: _argument_parser.ArgumentParser[_T]
+ serializer: _argument_parser.ArgumentSerializer[_T]
+ allow_override: bool
+ allow_override_cpp: bool
+ allow_hide_cpp: bool
+ using_default_value: bool
+ allow_overwrite: bool
+ allow_using_method_names: bool
+ validators: List[_validators_classes.Validator]
def __init__(self,
parser: _argument_parser.ArgumentParser[_T],
serializer: Optional[_argument_parser.ArgumentSerializer[_T]],
name: Text,
- default: Any,
+ default: Union[Optional[_T], Text],
help_string: Optional[Text],
short_name: Optional[Text] = ...,
boolean: bool = ...,
@@ -86,7 +87,7 @@
class BooleanFlag(Flag[bool]):
def __init__(self,
name: Text,
- default: Any,
+ default: Union[Optional[bool], Text],
help: Optional[Text],
short_name: Optional[Text]=None,
**args: Any) -> None:
@@ -97,7 +98,7 @@
class EnumFlag(Flag[Text]):
def __init__(self,
name: Text,
- default: Any,
+ default: Union[Optional[Text], Text],
help: Optional[Text],
enum_values: Sequence[Text],
short_name: Optional[Text] = ...,
@@ -111,7 +112,7 @@
def __init__(self,
name: Text,
- default: Any,
+ default: Union[Optional[_ET], Text],
help: Optional[Text],
enum_class: Type[_ET],
short_name: Optional[Text]=None,
@@ -127,7 +128,7 @@
class MultiEnumClassFlag(MultiFlag[_ET]):
def __init__(self,
name: Text,
- default: Any,
+ default: Union[Optional[List[_ET]], Text],
help_string: Optional[Text],
enum_class: Type[_ET],
**args: Any):
diff --git a/absl/flags/_flagvalues.pyi b/absl/flags/_flagvalues.pyi
index e25c6dd..d8e3935 100644
--- a/absl/flags/_flagvalues.pyi
+++ b/absl/flags/_flagvalues.pyi
@@ -72,7 +72,7 @@
self, module_name: Text, flag: _flag.Flag) -> None: ...
def register_flag_by_module_id(
- self, module_id: Text, flag: _flag.Flag) -> None: ...
+ self, module_id: int, flag: _flag.Flag) -> None: ...
def register_key_flag_for_module(
self, module_name: Text, flag: _flag.Flag) -> None: ...
diff --git a/absl/flags/_helpers.py b/absl/flags/_helpers.py
index ea02f2d..cbb98a7 100644
--- a/absl/flags/_helpers.py
+++ b/absl/flags/_helpers.py
@@ -156,7 +156,7 @@
if not sys.stdout.isatty() or termios is None or fcntl is None:
return _DEFAULT_HELP_WIDTH
try:
- data = fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, '1234')
+ data = fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, b'1234')
columns = struct.unpack('hh', data)[1]
# Emacs mode returns 0.
# Here we assume that any value below 40 is unreasonable.
diff --git a/absl/flags/_helpers.pyi b/absl/flags/_helpers.pyi
new file mode 100644
index 0000000..fe3b9f5
--- /dev/null
+++ b/absl/flags/_helpers.pyi
@@ -0,0 +1,81 @@
+# Copyright 2017 The Abseil Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from xml.dom import minidom
+import types
+from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Set
+
+disclaim_module_ids: Set[int]
+FLAGS_MODULE: types.ModuleType
+# NOTE: This cannot be annotated as its actual FlagValues type since this would
+# create a circular dependency.
+SPECIAL_FLAGS: Any
+
+
+class _ModuleObjectAndName(NamedTuple):
+ module: types.ModuleType
+ module_name: str
+
+
+def get_module_object_and_name(
+ globals_dict: Dict[str, Any]
+) -> _ModuleObjectAndName:
+ ...
+
+
+def get_calling_module_object_and_name() -> _ModuleObjectAndName:
+ ...
+
+
+def get_calling_module() -> str:
+ ...
+
+
+def create_xml_dom_element(
+ doc: minidom.Document, name: str, value: Any
+) -> minidom.Element:
+ ...
+
+
+def get_help_width() -> int:
+ ...
+
+
+def get_flag_suggestions(
+ attempt: Optional[str], longopt_list: List[str]
+) -> List[str]:
+ ...
+
+
+def text_wrap(
+ text: str,
+ length: Optional[int] = ...,
+ indent: str = ...,
+ firstline_indent: Optional[str] = ...,
+) -> str:
+ ...
+
+
+def flag_dict_to_args(
+ flag_map: Dict[str, str], multi_flags: Optional[Set[str]] = ...
+) -> Iterable[str]:
+ ...
+
+
+def trim_docstring(docstring: str) -> str:
+ ...
+
+
+def doc_to_help(doc: str) -> str:
+ ...
diff --git a/absl/logging/__init__.py b/absl/logging/__init__.py
index b379d30..494d782 100644
--- a/absl/logging/__init__.py
+++ b/absl/logging/__init__.py
@@ -1179,11 +1179,13 @@
def get_absl_logger():
"""Returns the absl logger instance."""
+ assert _absl_logger is not None
return _absl_logger
def get_absl_handler():
"""Returns the absl handler instance."""
+ assert _absl_handler is not None
return _absl_handler
diff --git a/absl/testing/absltest.py b/absl/testing/absltest.py
index 7cb9cfe..b977109 100644
--- a/absl/testing/absltest.py
+++ b/absl/testing/absltest.py
@@ -815,6 +815,7 @@
) -> None:
"""Adds `function` as cleanup when the test case succeeds."""
outcome = self._outcome
+ assert outcome is not None
previous_failure_count = (
len(outcome.result.failures)
+ len(outcome.result.errors)
@@ -834,6 +835,7 @@
"""Returns whether test is passed. Expected to be called during cleanup."""
outcome = self._outcome
if sys.version_info[:2] >= (3, 11):
+ assert outcome is not None
current_failure_count = (
len(outcome.result.failures)
+ len(outcome.result.errors)
@@ -2301,7 +2303,7 @@
for name in dir(testCaseClass):
if _is_suspicious_attribute(testCaseClass, name):
raise TypeError(TestLoader._ERROR_MSG % name)
- names = super(TestLoader, self).getTestCaseNames(testCaseClass)
+ names = list(super(TestLoader, self).getTestCaseNames(testCaseClass))
if self._randomize_ordering_seed is not None:
logging.info(
'Randomizing test order with seed: %d', self._randomize_ordering_seed)