1# Copyright 2020 The Abseil Authors. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15"""Contains type annotations for Flag class.""" 16 17import copy 18import functools 19 20from absl.flags import _argument_parser 21import enum 22 23from typing import Callable, Text, TypeVar, Generic, Iterable, Type, List, Optional, Any, Union, Sequence 24 25_T = TypeVar('_T') 26_ET = TypeVar('_ET', bound=enum.Enum) 27 28 29class Flag(Generic[_T]): 30 31 name = ... # type: Text 32 default = ... # type: Any 33 default_unparsed = ... # type: Any 34 default_as_str = ... # type: Optional[Text] 35 help = ... # type: Text 36 short_name = ... # type: Text 37 boolean = ... # type: bool 38 present = ... # type: bool 39 parser = ... # type: _argument_parser.ArgumentParser[_T] 40 serializer = ... # type: _argument_parser.ArgumentSerializer[_T] 41 allow_override = ... # type: bool 42 allow_override_cpp = ... # type: bool 43 allow_hide_cpp = ... # type: bool 44 using_default_value = ... # type: bool 45 allow_overwrite = ... # type: bool 46 allow_using_method_names = ... # type: bool 47 validators = ... # type: List[Callable[[Any], bool]] 48 49 def __init__(self, 50 parser: _argument_parser.ArgumentParser[_T], 51 serializer: Optional[_argument_parser.ArgumentSerializer[_T]], 52 name: Text, 53 default: Any, 54 help_string: Optional[Text], 55 short_name: Optional[Text] = ..., 56 boolean: bool = ..., 57 allow_override: bool = ..., 58 allow_override_cpp: bool = ..., 59 allow_hide_cpp: bool = ..., 60 allow_overwrite: bool = ..., 61 allow_using_method_names: bool = ...) -> None: 62 ... 63 64 65 @property 66 def value(self) -> Optional[_T]: ... 67 68 def parse(self, argument: Union[_T, Text, None]) -> None: ... 69 70 def unparse(self) -> None: ... 71 72 def _parse(self, argument: Any) -> Any: ... 73 74 def __deepcopy__(self, memo: dict) -> Flag: ... 75 76 def _get_parsed_value_as_string(self, value: Optional[_T]) -> Optional[Text]: 77 ... 78 79 def serialize(self) -> Text: ... 80 81 def flag_type(self) -> Text: ... 82 83 84class BooleanFlag(Flag[bool]): 85 def __init__(self, 86 name: Text, 87 default: Any, 88 help: Optional[Text], 89 short_name: Optional[Text]=None, 90 **args: Any) -> None: 91 ... 92 93 94 95class EnumFlag(Flag[Text]): 96 def __init__(self, 97 name: Text, 98 default: Any, 99 help: Optional[Text], 100 enum_values: Sequence[Text], 101 short_name: Optional[Text] = ..., 102 case_sensitive: bool = ..., 103 **args: Any): 104 ... 105 106 107 108class EnumClassFlag(Flag[_ET]): 109 110 def __init__(self, 111 name: Text, 112 default: Any, 113 help: Optional[Text], 114 enum_class: Type[_ET], 115 short_name: Optional[Text]=None, 116 **args: Any): 117 ... 118 119 120 121class MultiFlag(Flag[List[_T]]): 122 ... 123 124 125class MultiEnumClassFlag(MultiFlag[_ET]): 126 def __init__(self, 127 name: Text, 128 default: Any, 129 help_string: Optional[Text], 130 enum_class: Type[_ET], 131 **args: Any): 132 ... 133 134 135