10000 Specify some types in flask stubs. · python/typeshed@0b77ce1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b77ce1

Browse files
committed
Specify some types in flask stubs.
1 parent 9ced8e9 commit 0b77ce1

File tree

16 files changed

+141
-91
lines changed

16 files changed

+141
-91
lines changed

third_party/2and3/flask/__init__.pyi

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,44 @@
22
#
33
# NOTE: This dynamically typed stub was automatically generated by stubgen.
44

5-
from .app import Flask, Request, Response
6-
from .blueprints import Blueprint
7-
from .config import Config
8-
from .ctx import after_this_request, copy_current_request_context, has_app_context, has_request_context
9-
from .globals import _app_ctx_stack, _request_ctx_stack, current_app, g, request, session
10-
from .helpers import flash, get_flashed_messages, get_template_attribute, make_response, safe_join, send_file, send_from_directory, stream_with_context, url_for
11-
from .signals import appcontext_popped, appcontext_pushed, appcontext_tearing_down, before_render_template, got_request_exception, message_flashed, request_finished, request_started, request_tearing_down, signals_available, template_rendered
12-
from .templating import render_template, render_template_string
13-
from typing import Any
5+
from .app import Flask as Flask
6+
from .blueprints import Blueprint as Blueprint
7+
from .config import Config as Config
8+
from .ctx import after_this_request as after_this_request
9+
from .ctx import copy_current_request_context as copy_current_request_context
10+
from .ctx import has_app_context as has_app_context
11+
from .ctx import has_request_context as has_request_context
12+
from .globals import current_app as current_app
13+
from .globals import g as g
14+
from .globals import request as request
15+
from .globals import session as session
16+
from .helpers import flash as flash
17+
from .helpers import get_flashed_messages as get_flashed_messages
18+
from .helpers import get_template_attribute as get_template_attribute
19+
from .helpers import make_response as make_response
20+
from .helpers import safe_join as safe_join
21+
from .helpers import send_file as send_file
22+
from .helpers import send_from_directory as send_from_directory
23+
from .helpers import stream_with_context as stream_with_context
24+
from .helpers import url_for as url_for
25+
from .json import jsonify as jsonify
26+
from .signals import appcontext_popped as appcontext_popped
27+
from .signals import appcontext_pushed as appcontext_pushed
28+
from .signals import appcontext_tearing_down as appcontext_tearing_down
29+
from .signals import before_render_template as before_render_template
30+
from .signals import got_request_exception as got_request_exception
31+
from .signals import message_flashed as message_flashed
32+
from .signals import request_finished as request_finished
33+
from .signals import request_started as request_started
34+
from .signals import request_tearing_down as request_tearing_down
35+
from .signals import signals_available as signals_available
36+
from .signals import template_rendered as template_rendered
37+
from .templating import render_template as render_template
38+
from .templating import render_template_string as render_template_string
39+
from .wrappers import Request as Request
40+
from .wrappers import Response as Response
1441

15-
jsonify: Any
16-
json_available: bool
42+
from werkzeug.exceptions import abort as abort
43+
from werkzeug.utils import redirect as redirect
44+
from jinja2 import Markup as Markup
45+
from jinja2 import escape as escape

third_party/2and3/flask/app.pyi

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,29 @@
22
#
33
# NOTE: This dynamically typed stub was automatically generated by stubgen.
44

5-
from ._compat import integer_types, reraise, string_types, text_type
5+
from .blueprints import Blueprint
66
from .config import Config, ConfigAttribute
77
from .ctx import AppContext, RequestContext, _AppCtxGlobals
88
from .globals import _request_ctx_stack, g, request, session
9-
from .helpers import _PackageBoundObject, _endpoint_from_view_func, find_package, get_debug_flag, get_env, get_flashed_messages, get_load_dotenv, locked_cached_property, url_for
9+
from .helpers import _PackageBoundObject, find_package, get_debug_flag, get_env, get_flashed_messages, get_load_dotenv, locked_cached_property, url_for
1010
from .logging import create_logger
1111
from .sessions import SecureCookieSessionInterface
1212
from .signals import appcontext_tearing_down, got_request_exception, request_finished, request_started, request_tearing_down
13-
from .templating import DispatchingJinjaLoader, Environment, _default_template_ctx_processor
13+
from .templating import DispatchingJinjaLoader, Environment
1414
from .wrappers import Request, Response
15-
from typing import Any, Optional
15+
from .testing import FlaskClient
16+
from typing import Any, Callable, ContextManager, Dict, List, Optional, Type, TypeVar, Union
1617

1718
def setupmethod(f: Any): ...
1819

20+
_T = TypeVar('_T')
21+
1922
class Flask(_PackageBoundObject):
20-
request_class: Any = ...
21-
response_class: Any = ...
22-
jinja_environment: Any = ...
23-
app_ctx_globals_class: Any = ...
24-
config_class: Any = ...
23+
request_class: type = ...
24+
response_class: type = ...
25+
jinja_environment: type = ...
26+
app_ctx_globals_class: type = ...
27+
config_class: type = ...
2528
testing: Any = ...
2629
secret_key: Any = ...
2730
session_cookie_name: Any = ...
@@ -32,25 +35,25 @@ class Flask(_PackageBoundObject):
3235
json_decoder: Any = ...
3336
jinja_options: Any = ...
3437
default_config: Any = ...
35-
url_rule_class: Any = ...
36-
test_client_class: Any = ...
37-
test_cli_runner_class: Any = ...
38+
url_rule_class: type = ...
39+
test_client_class: type = ...
40+
test_cli_runner_class: type = ...
3841
session_interface: Any = ...
39-
import_name: Any = ...
40-
template_folder: Any = ...
42+
import_name: str = ...
43+
template_folder: str = ...
4144
root_path: Any = ...
4245
static_url_path: Any = ...
43-
static_folder: Any = ...
46+
static_folder: str = ...
4447
instance_path: Any = ...
45-
config: Any = ...
48+
config: Dict[str, Any] = ...
4649
view_functions: Any = ...
4750
error_handler_spec: Any = ...
4851
url_build_error_handlers: Any = ...
49-
before_request_funcs: Any = ...
50-
before_first_request_funcs: Any = ...
51-
after_request_funcs: Any = ...
52-
teardown_request_funcs: Any = ...
53-
teardown_appcontext_funcs: Any = ...
52+
before_request_funcs: Dict[Optional[str], List[Callable[[], Any]]] = ...
53+
before_first_request_funcs: List[Callable[[], None]] = ...
54+
after_request_funcs: Dict[Optional[str], List[Callable[[Response], Response]]] = ...
55+
teardown_request_funcs: Dict[Optional[str], List[Callable[[Optional[Exception]], Any]]] = ...
56+
teardown_appcontext_funcs: List[Callable[[Optional[Exception]], Any]] = ...
5457
url_value_preprocessors: Any = ...
5558
url_default_functions: Any = ...
5659
template_context_processors: Any = ...
@@ -60,8 +63,8 @@ class Flask(_PackageBoundObject):
6063
url_map: Any = ...
6164
subdomain_matching: Any = ...
6265
cli: Any = ...
63-
def __init__(self, import_name: Any, static_url_path: Optional[Any] = ..., static_folder: str = ..., static_host: Optional[Any] = ..., host_matching: bool = ..., subdomain_matching: bool = ..., template_folder: str = ..., instance_path: Optional[Any] = ..., instance_relative_config: bool = ..., root_path: Optional[Any] = ...) -> None: ...
64-
def name(self): ...
66+
def __init__(self, import_name: str, static_url_path: Optional[str] = ..., static_folder: str = ..., static_host: Optional[str] = ..., host_matching: bool = ..., subdomain_matching: bool = ..., template_folder: str = ..., instance_path: Optional[str] = ..., instance_relative_config: bool = ..., root_path: Optional[str] = ...) -> None: ...
67+
def name(self) -> str: ...
6568
@property
6669
def propagate_exceptions(self): ...
6770
@property
@@ -81,30 +84,30 @@ class Flask(_PackageBoundObject):
8184
def make_shell_context(self): ...
8285
env: Any = ...
8386
debug: Any = ...
84-
def run(self, host: Optional[Any] = ..., port: Optional[Any] = ..., debug: Optional[Any] = ..., load_dotenv: bool = ..., **options: Any): ...
85-
def test_client(self, use_cookies: bool = ..., **kwargs: Any): ...
87+
def run(self, host: Optional[str] = ..., port: Optional[int] = ..., debug: Optional[bool] = ..., load_dotenv: bool = ..., **options: Any) -> None: ...
88+
def test_client(self, use_cookies: bool = ..., **kwargs: Any) -> testing.FlaskClient: ...
8689
def test_cli_runner(self, **kwargs: Any): ...
8790
def open_session(self, request: Any): ...
8891
def save_session(self, session: Any, response: Any): ...
8992
def make_null_session(self): ...
90-
def register_blueprint(self, blueprint: Any, **options: Any) -> None: ...
93+
def register_blueprint(self, blueprint: Blueprint, **options: Any) -> None: ...
9194
def iter_blueprints(self): ...
92-
def add_url_rule(self, rule: Any, endpoint: Optional[Any] = ..., view_func: Optional[Any] = ..., provide_automatic_options: Optional[Any] = ..., **options: Any) -> None: ...
93-
def route(self, rule: Any, **options: Any): ...
94-
def endpoint(self, endpoint: Any): ...
95-
def errorhandler(self, code_or_exception: Any): ...
96-
def register_error_handler(self, code_or_exception: Any, f: Any) -> None: ...
95+
def add_url_rule(self, rule: str, endpoint: Optional[str] = ..., view_func: Callable[..., Any] = ..., provide_automatic_options: Optional[bool] = ..., **options: Any) -> None: ...
96+
def route(self, rule: str, **options: Any) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
97+
def endpoint(self, endpoint: str) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
98+
def errorhandler(self, code_or_exception: Union[int, Type[Exception]]) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
99+
def register_error_handler(self, code_or_exception: Union[int, Type[Exception]], f: Callable[..., Any]) -> None: ...
97100
def template_filter(self, name: Optional[Any] = ...): ...
98101
def add_template_filter(self, f: Any, name: Optional[Any] = ...) -> None: ...
99102
def template_test(self, name: Optional[Any] = ...): ...
100103
def add_template_test(self, f: Any, name: Optional[Any] = ...) -> None: ...
101104
def template_global(self, name: Optional[Any] = ...): ...
102105
def add_template_global(self, f: Any, name: Optional[Any] = ...) -> None: ...
103-
def before_request(self, f: Any): ...
104-
def before_first_request(self, f: Any): ...
105-
def after_request(self, f: Any): ...
106-
def teardown_request(self, f: Any): ...
107-
def teardown_appcontext(self, f: Any): ...
106+
def before_request(self, f: Callable[[], _T]) -> Callable[[], _T]: ...
107+
def before_first_request(self, f: Callable[[], _T]) -> Callable[[], _T]: ...
108+
def after_request(self, f: Callable[[Response], Response]) -> Callable[[Response], Response]: ...
109+
def teardown_request(self, f: Callable[[Optional[Exception]], _T]) -> Callable[[Optional[Exception]], _T]: ...
110+
def teardown_appcontext(self, f: Callable[[Optional[Exception]], _T]) -> Callable[[Optional[Exception]], _T]: ...
108111
def context_processor(self, f: Any): ...
109112
def shell_context_processor(self, f: Any): ...
110113
def url_value_preprocessor(self, f: Any): ...
@@ -131,6 +134,6 @@ class Flask(_PackageBoundObject):
131134
def do_teardown_appcontext(self, exc: Any = ...) -> None: ...
132135
def app_context(self): ...
133136
def request_context(self, environ: Any): ...
134-
def test_request_context(self, *args: Any, **kwargs: Any): ...
137+
def test_request_context(self, *args: Any, **kwargs: Any) -> ContextManager[RequestContext]: ...
135138
def wsgi_app(self, environ: Any, start_response: Any): ...
136139
def __call__(self, environ: Any, start_response: Any): ...

third_party/2and3/flask/blueprints.pyi

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
#
33
# NOTE: This dynamically typed stub was automatically generated by stubgen.
44

5-
from .helpers import _PackageBoundObject, _endpoint_from_view_func
6-
from typing import Any, Optional
5+
from .helpers import _PackageBoundObject
6+
from typing import Any, Callable, Optional, Type, TypeVar, Union
7+
8+
_T = TypeVar('_T')
79

810
class BlueprintSetupState:
911
app: Any = ...
@@ -14,30 +16,30 @@ class BlueprintSetupState:
1416
url_prefix: Any = ...
1517
url_defaults: Any = ...
1618
def __init__(self, blueprint: Any, app: Any, options: Any, first_registration: Any) -> None: ...
17-
def add_url_rule(self, rule: Any, endpoint: Optional[Any] = ..., view_func: Optional[Any] = ..., **options: Any) -> None: ...
19+
def add_url_rule(self, rule: str, endpoint: Optional[str] = ..., view_func: Callable[..., Any] = ..., **options: Any) -> None: ...
1820

1921
class Blueprint(_PackageBoundObject):
2022
warn_on_modifications: bool = ...
2123
json_encoder: Any = ...
2224
json_decoder: Any = ...
23-
import_name: Any = ...
24-
template_folder: Any = ...
25-
root_path: Any = ...
26-
name: Any = ...
27-
url_prefix: Any = ...
28-
subdomain: Any = ...
29-
static_folder: Any = ...
30-
static_url_path: Any = ...
25+
import_name: str = ...
26+
template_folder: Optional[str] = ...
27+
root_path: Optional[str] = ...
28+
name: str = ...
29+
url_prefix: Optional[str] = ...
30+
subdomain: Optional[str] = ...
31+
static_folder: Optional[str] = ...
32+
static_url_path: Optional[str] = ...
3133
deferred_functions: Any = ...
3234
url_values_defaults: Any = ...
33-
def __init__(self, name: Any, import_name: Any, static_folder: Optional[Any] = ..., static_url_path: Optional[Any] = ..., template_folder: Optional[Any] = ..., url_prefix: Optional[Any] = ..., subdomain: Optional[Any] = ..., url_defaults: Optional[Any] = ..., root_path: Optional[Any] = ...) -> None: ...
35+
def __init__(self, name: str, import_name: str, static_folder: Optional[str] = ..., static_url_path: Optional[str] = ..., template_folder: Optional[str] = ..., url_prefix: Optional[str] = ..., subdomain: Optional[str] = ..., url_defaults: Optional[Any] = ..., root_path: Optional[str] = ...) -> None: ...
3436
def record(self, func: Any) -> None: ...
3537
def record_once(self, func: Any): ...
3638
def make_setup_state(self, app: Any, options: Any, first_registration: bool = ...): ...
3739
def register(self, app: Any, options: Any, first_registration: bool = ...) -> None: ...
38-
def route(self, rule: Any, **options: Any): ...
39-
def add_url_rule(self, rule: Any, endpoint: Optional[Any] = ..., view_func: Optional[Any] = ..., **options: Any): ...
40-
def endpoint(self, endpoint: Any): ...
40+
def route(self, rule: str, **options: Any) -> Callable[[Callable[..., Any]], Callable[..., Any]]: ...
41+
def add_url_rule(self, rule: str, endpoint: Optional[str] = ..., view_func: Callable[..., Any] = ..., **options: Any) -> None: ...
42+
def endpoint(self, endpoint: str) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
4143
def app_template_filter(self, name: Optional[Any] = ...): ...
4244
def add_app_template_filter(self, f: Any, name: Optional[Any] = ...) -> None: ...
4345
def app_template_test(self, name: Optional[Any] = ...): ...
@@ -58,5 +60,5 @@ class Blueprint(_PackageBoundObject):
5860
def url_defaults(self, f: Any): ...
5961
def app_url_value_preprocessor(self, f: Any): ...
6062
def app_url_defaults(self, f: Any): ...
61-
def errorhandler(self, code_or_exception: Any): ...
62-
def register_error_handler(self, code_or_exception: Any, f: Any): ...
63+
def errorhandler(self, code_or_exception: Union[int, Type[Exception]]) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
64+
def register_error_handler(self, code_or_exception: Union[int, Type[Exception]], f: Callable[..., Any]) -> None: ...

third_party/2and3/flask/cli.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# NOTE: This dynamically typed stub was automatically generated by stubgen.
44

55
import click
6-
from ._compat import getargspec, iteritems, reraise, text_type
76
from .globals import current_app
87
from .helpers import get_debug_flag, get_env, get_load_dotenv
98
from typing import Any, Optional

third_party/2and3/flask/config.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#
33
# NOTE: This dynamically typed stub was automatically generated by stubgen.
44

5-
from ._compat import iteritems, string_types
65
from typing import Any, Optional
76

87
class ConfigAttribute:

third_party/2and3/flask/ctx.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#
33
# NOTE: This dynamically typed stub was automatically generated by stubgen.
44

5-
from ._compat import BROKEN_PYPY_CTXMGR_EXIT, reraise
65
from .globals import _app_ctx_stack, _request_ctx_stack
76
from .signals import appcontext_popped, appcontext_pushed
87
from typing import Any, Optional

third_party/2and3/flask/debughelpers.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#
33
# NOTE: This dynamically typed stub was automatically generated by stubgen.
44

5-
from ._compat import implements_to_string, text_type
65
from .app import Flask
76
from .blueprints import Blueprint
87
from .globals import _request_ctx_stack

third_party/2and3/flask/globals.pyi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
#
33
# NOTE: This dynamically typed stub was automatically generated by stubgen.
44

5+
from .app import Flask
6+
from .wrappers import Request
57
from typing import Any
8+
from werkzeug.local import LocalStack
69

7-
current_app: Any
8-
request: Any
10+
_request_ctx_stack: LocalStack
11+
_app_ctx_stack: LocalStack
12+
current_app: Flask
13+
request: Request
914
session: Any
1015
g: Any

third_party/2and3/flask/helpers.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#
33
# NOTE: This dynamically typed stub was automatically generated by stubgen.
44

5-
from ._compat import PY2, string_types, text_type
65
from .globals import _app_ctx_stack, _request_ctx_stack, current_app, request, session
76
from .signals import message_flashed
87
from typing import Any, Optional

third_party/2and3/flask/json/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# NOTE: This dynamically typed stub was automatically generated by stubgen.
44

5-
from itsdangerous import json as _json
5+
import json as _json
66
from typing import Any
77

88
class JSONEncoder(_json.JSONEncoder):

0 commit comments

Comments
 (0)
0