Skip to content

Commit 4990830

Browse files
rchen152srittau
authored andcommitted
Make pytype happy with the third_party click stubs. (#2966)
This also makes the flask stubs that depend on click parseable. * In pytype_test, only parse files with the .pyi extension. (There's a README in third_party/2and3/click/.) * Annotate with ContextManager rather than using the contextmanager decorator. This is shorter, removes a dependency, and gets rid of the slight weirdness of a decorator needing to be evaluated in a stub. * Fix non-stub things.
1 parent 5dda362 commit 4990830

File tree

7 files changed

+17
-85
lines changed

7 files changed

+17
-85
lines changed

tests/pytype_blacklist.txt

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,7 @@ third_party/2and3/attr/converters.pyi
2020
third_party/2and3/attr/filters.pyi
2121
third_party/2and3/attr/validators.pyi
2222
third_party/2and3/boto/utils.pyi
23-
third_party/2and3/click/README.md
24-
third_party/2and3/click/__init__.pyi
25-
third_party/2and3/click/core.pyi
26-
third_party/2and3/click/decorators.pyi
27-
third_party/2and3/click/exceptions.pyi
28-
third_party/2and3/click/formatting.pyi
29-
third_party/2and3/click/globals.pyi
30-
third_party/2and3/click/parser.pyi
31-
third_party/2and3/click/termui.pyi
32-
third_party/2and3/click/testing.pyi
33-
third_party/2and3/click/types.pyi
3423
third_party/2and3/dateutil/rrule.pyi
35-
third_party/2and3/flask/__init__.pyi
36-
third_party/2and3/flask/app.pyi
37-
third_party/2and3/flask/blueprints.pyi
38-
third_party/2and3/flask/cli.pyi
39-
third_party/2and3/flask/ctx.pyi
40-
third_party/2and3/flask/debughelpers.pyi
41-
third_party/2and3/flask/globals.pyi
42-
third_party/2and3/flask/helpers.pyi
43-
third_party/2and3/flask/logging.pyi
44-
third_party/2and3/flask/templating.pyi
45-
third_party/2and3/flask/testing.pyi
46-
third_party/2and3/flask/views.pyi
4724
third_party/2and3/google/protobuf/any_pb2.pyi
4825
third_party/2and3/google/protobuf/any_test_pb2.pyi
4926
third_party/2and3/google/protobuf/api_pb2.pyi

tests/pytype_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def _parse(filename, major_version):
172172

173173
for root, _, filenames in itertools.chain.from_iterable(
174174
os.walk(p) for p in paths):
175-
for f in sorted(filenames):
175+
for f in sorted(f for f in filenames if f.endswith('.pyi')):
176176
f = os.path.join(root, f)
177177
rel = _get_relative(f)
178178
if not skipped.search(rel):

third_party/2and3/click/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# click 6.6, Python 3
22

3-
`__init__.pyi` is literally a copy of click/__init__.py. It's a shortcut module
4-
anyway in the actual sources so it works well without additional changes.
3+
`__init__.pyi` is almost a copy of `click/__init__.py`. It's a shortcut module
4+
anyway in the actual sources so it works well with minimal changes.
55

66
The types are pretty complete but they were created mostly for public API use
77
so some internal modules (`_compat`) or functions (`core._bashcomplete`) are

third_party/2and3/click/__init__.pyi

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -108,49 +108,9 @@ from .formatting import HelpFormatter as HelpFormatter, wrap_text as wrap_text
108108
# Parsing
109109
from .parser import OptionParser as OptionParser
110110

111-
112-
__all__ = [
113-
# Core classes
114-
'Context', 'BaseCommand', 'Command', 'MultiCommand', 'Group',
115-
'CommandCollection', 'Parameter', 'Option', 'Argument',
116-
117-
# Globals
118-
'get_current_context',
119-
120-
# Decorators
121-
'pass_context', 'pass_obj', 'make_pass_decorator', 'command', 'group',
122-
'argument', 'option', 'confirmation_option', 'password_option',
123-
'version_option', 'help_option',
124-
125-
# Types
126-
'ParamType', 'File', 'Path', 'Choice', 'IntRange', 'Tuple', 'STRING',
127-
'INT', 'FLOAT', 'BOOL', 'UUID', 'UNPROCESSED',
128-
129-
# Utilities
130-
'echo', 'get_binary_stream', 'get_text_stream', 'open_file',
131-
'format_filename', 'get_app_dir', 'get_os_args',
132-
133-
# Terminal functions
134-
'prompt', 'confirm', 'get_terminal_size', 'echo_via_pager',
135-
'progressbar', 'clear', 'style', 'unstyle', 'secho', 'edit', 'launch',
136-
'getchar', 'pause',
137-
138-
# Exceptions
139-
'ClickException', 'UsageError', 'BadParameter', 'FileError',
140-
'Abort', 'NoSuchOption', 'BadOptionUsage', 'BadArgumentUsage',
141-
'MissingParameter',
142-
143-
# Formatting
144-
'HelpFormatter', 'wrap_text',
145-
146-
# Parsing
147-
'OptionParser',
148-
]
149-
150-
151111
# Controls if click should emit the warning about the use of unicode
152112
# literals.
153-
disable_unicode_literals_warning = False
113+
disable_unicode_literals_warning: bool
154114

155115

156-
__version__ = '6.6'
116+
__version__: str

third_party/2and3/click/core.pyi

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from contextlib import contextmanager
21
from typing import (
32
Any,
43
Callable,
4+
ContextManager,
55
Dict,
66
Generator,
77
Iterable,
@@ -28,10 +28,9 @@ def invoke_param_callback(
2828
...
2929

3030

31-
@contextmanager
3231
def augment_usage_errors(
3332
ctx: Context, param: Optional[Parameter] = ...
34-
) -> Generator[None, None, None]:
33+
) -> ContextManager[None]:
3534
...
3635

3736

@@ -90,8 +89,7 @@ class Context:
9089
) -> None:
9190
...
9291

93-
@contextmanager
94-
def scope(self, cleanup: bool = ...) -> Generator[Context, None, None]:
92+
def scope(self, cleanup: bool = ...) -> ContextManager[Context]:
9593
...
9694

9795
def make_formatter(self) -> HelpFormatter:

third_party/2and3/click/formatting.pyi

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from contextlib import contextmanager
2-
from typing import Generator, Iterable, List, Optional, Tuple
1+
from typing import ContextManager, Generator, Iterable, List, Optional, Tuple
32

43

54
FORCED_WIDTH: Optional[int]
@@ -73,12 +72,10 @@ class HelpFormatter:
7372
) -> None:
7473
...
7574

76-
@contextmanager
77-
def section(self, name) -> Generator[None, None, None]:
75+
def section(self, name) -> ContextManager[None]:
7876
...
7977

80-
@contextmanager
81-
def indentation(self) -> Generator[None, None, None]:
78+
def indentation(self) -> ContextManager[None]:
8279
...
8380

8481
def getvalue(self) -> str:

third_party/2and3/click/types.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ def convert_type(ty: Optional[_ConvertibleType], default: Optional[Any] = ...) -
261261

262262
# parameter type shortcuts
263263

264-
BOOL = BoolParamType()
265-
FLOAT = FloatParamType()
266-
INT = IntParamType()
267-
STRING = StringParamType()
268-
UNPROCESSED = UnprocessedParamType()
269-
UUID = UUIDParameterType()
264+
BOOL: BoolParamType
265+
FLOAT: FloatParamType
266+
INT: IntParamType
267+
STRING: StringParamType
268+
UNPROCESSED: UnprocessedParamType
269+
UUID: UUIDParameterType

0 commit comments

Comments
 (0)