• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 _argument_parser.py."""
16
17
18from typing import Text, TypeVar, Generic, Iterable, Type, List, Optional, Sequence, Any
19
20import enum
21
22_T = TypeVar('_T')
23_ET = TypeVar('_ET', bound=enum.Enum)
24
25
26class ArgumentSerializer(Generic[_T]):
27  def serialize(self, value: _T) -> Text: ...
28
29
30# The metaclass of ArgumentParser is not reflected here, because it does not
31# affect the provided API.
32class ArgumentParser(Generic[_T]):
33
34  syntactic_help: Text
35
36  def parse(self, argument: Text) -> Optional[_T]: ...
37
38  def flag_type(self) -> Text: ...
39
40
41# Using bound=numbers.Number results in an error: b/153268436
42_N = TypeVar('_N', int, float)
43
44
45class NumericParser(ArgumentParser[_N]):
46
47  def is_outside_bounds(self, val: _N) -> bool: ...
48
49  def parse(self, argument: Text) -> _N: ...
50
51  def convert(self, argument: Text) -> _N: ...
52
53
54class FloatParser(NumericParser[float]):
55
56  def __init__(self, lower_bound:Optional[float]=None,
57               upper_bound:Optional[float]=None) -> None:
58    ...
59
60
61class IntegerParser(NumericParser[int]):
62
63  def __init__(self, lower_bound:Optional[int]=None,
64               upper_bound:Optional[int]=None) -> None:
65    ...
66
67
68class BooleanParser(ArgumentParser[bool]):
69  ...
70
71
72class EnumParser(ArgumentParser[Text]):
73  def __init__(self, enum_values: Sequence[Text], case_sensitive: bool=...) -> None:
74    ...
75
76
77
78class EnumClassParser(ArgumentParser[_ET]):
79
80  def __init__(self, enum_class: Type[_ET], case_sensitive: bool=...) -> None:
81    ...
82
83  @property
84  def member_names(self) -> Sequence[Text]: ...
85
86
87class BaseListParser(ArgumentParser[List[Text]]):
88  def __init__(self, token: Text, name:Text) -> None: ...
89
90  # Unlike baseclass BaseListParser never returns None.
91  def parse(self, argument: Text) -> List[Text]: ...
92
93
94
95class ListParser(BaseListParser):
96  def __init__(self) -> None:
97    ...
98
99
100
101class WhitespaceSeparatedListParser(BaseListParser):
102  def __init__(self, comma_compat: bool=False) -> None:
103    ...
104
105
106
107class ListSerializer(ArgumentSerializer[List[Text]]):
108  list_sep = ... # type: Text
109
110  def __init__(self, list_sep: Text) -> None:
111    ...
112
113
114class EnumClassListSerializer(ArgumentSerializer[List[Text]]):
115  def __init__(self, list_sep: Text, **kwargs: Any) -> None:
116    ...
117
118
119class CsvListSerializer(ArgumentSerializer[List[Any]]):
120
121  def __init__(self, list_sep: Text) -> None:
122    ...
123
124
125class EnumClassSerializer(ArgumentSerializer[_ET]):
126  def __init__(self, lowercase: bool) -> None:
127    ...
128