Skip to content

Commit 30133bb

Browse files
authored
Add stubs for flask-cors (#6939)
1 parent 4e97b06 commit 30133bb

File tree

7 files changed

+139
-0
lines changed

7 files changed

+139
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Caused by https://github.com/python/mypy/pull/12040
2+
flask_cors.core.DEFAULT_OPTIONS

stubs/Flask-Cors/METADATA.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version = "3.0.*"
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from logging import Logger
2+
3+
from .decorator import cross_origin as cross_origin
4+
from .extension import CORS as CORS
5+
from .version import __version__ as __version__
6+
7+
rootlogger: Logger

stubs/Flask-Cors/flask_cors/core.pyi

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from datetime import timedelta
2+
from logging import Logger
3+
from typing import Any, Iterable, Pattern, TypeVar, overload
4+
from typing_extensions import TypedDict
5+
6+
_IterableT = TypeVar("_IterableT", bound=Iterable[Any])
7+
_T = TypeVar("_T")
8+
_App = Any # flask is not part of typeshed
9+
_Response = Any # flask is not part of typeshed
10+
_MultiDict = Any # werkzeug is not part of typeshed
11+
_Options = TypedDict(
12+
"_Options",
13+
{
14+
"resources": dict[str, dict[str, Any]] | list[str] | str | None,
15+
"origins": str | list[str] | None,
16+
"methods": str | list[str] | None,
17+
"expose_headers": str | list[str] | None,
18+
"allow_headers": str | list[str] | None,
19+
"supports_credentials": bool | None,
20+
"max_age": timedelta | int | str | None,
21+
"send_wildcard": bool | None,
22+
"vary_header": bool | None,
23+
"automatic_options": bool | None,
24+
"intercept_exceptions": bool | None,
25+
"always_send": bool | None,
26+
},
27+
total=False,
28+
)
29+
30+
LOG: Logger
31+
ACL_ORIGIN: str
32+
ACL_METHODS: str
33+
ACL_ALLOW_HEADERS: str
34+
ACL_EXPOSE_HEADERS: str
35+
ACL_CREDENTIALS: str
36+
ACL_MAX_AGE: str
37+
ACL_REQUEST_METHOD: str
38+
ACL_REQUEST_HEADERS: str
39+
ALL_METHODS: list[str]
40+
CONFIG_OPTIONS: list[str]
41+
FLASK_CORS_EVALUATED: str
42+
RegexObject = Pattern[str]
43+
DEFAULT_OPTIONS: _Options
44+
45+
def parse_resources(resources: dict[str, _Options] | Iterable[str] | str | Pattern[str]) -> list[tuple[str, _Options]]: ...
46+
def get_regexp_pattern(regexp: str | Pattern[str]) -> str: ...
47+
def get_cors_origins(options: _Options, request_origin: str | None) -> list[str] | None: ...
48+
def get_allow_headers(options: _Options, acl_request_headers: str | None) -> str | None: ...
49+
def get_cors_headers(options: _Options, request_headers: dict[str, Any], request_method: str) -> _MultiDict: ...
50+
def set_cors_headers(resp: _Response, options: _Options) -> _Response: ...
51+
def probably_regex(maybe_regex: str | Pattern[str]) -> bool: ...
52+
def re_fix(reg: str) -> str: ...
53+
def try_match_any(inst: str, patterns: Iterable[str | Pattern[str]]) -> bool: ...
54+
def try_match(request_origin: str, maybe_regex: str | Pattern[str]) -> bool: ...
55+
def get_cors_options(appInstance: _App | None, *dicts: _Options) -> _Options: ...
56+
def get_app_kwarg_dict(appInstance: _App | None = ...) -> _Options: ...
57+
def flexible_str(obj: object) -> str | None: ...
58+
def serialize_option(options_dict: _Options, key: str, upper: bool = ...) -> None: ...
59+
@overload
60+
def ensure_iterable(inst: str) -> list[str]: ... # type: ignore
61+
@overload
62+
def ensure_iterable(inst: _IterableT) -> _IterableT: ... # type: ignore
63+
@overload
64+
def ensure_iterable(inst: _T) -> list[_T]: ...
65+
def sanitize_regex_param(param: str | list[str]) -> list[str]: ...
66+
def serialize_options(opts: _Options) -> _Options: ...
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from datetime import timedelta
2+
from logging import Logger
3+
from typing import Any, Callable
4+
from typing_extensions import ParamSpec
5+
6+
_P = ParamSpec("_P")
7+
8+
LOG: Logger
9+
10+
def cross_origin(
11+
*args: Any,
12+
origins: str | list[str] | None,
13+
methods: str | list[str] | None,
14+
expose_headers: str | list[str] | None,
15+
allow_headers: str | list[str] | None,
16+
supports_credentials: bool | None,
17+
max_age: timedelta | int | str | None,
18+
send_wildcard: bool | None,
19+
vary_header: bool | None,
20+
automatic_options: bool | None,
21+
) -> Callable[[Callable[_P, Any]], Callable[_P, Any]]: ...
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from datetime import timedelta
2+
from logging import Logger
3+
from typing import Any, Callable, Iterable
4+
5+
_App = Any # flask is not part of typeshed
6+
7+
LOG: Logger
8+
9+
class CORS:
10+
def __init__(
11+
self,
12+
app: Any | None = ...,
13+
*,
14+
resources: dict[str, dict[str, Any]] | list[str] | str | None = ...,
15+
origins: str | list[str] | None = ...,
16+
methods: str | list[str] | None = ...,
17+
expose_headers: str | list[str] | None = ...,
18+
allow_headers: str | list[str] | None = ...,
19+
supports_credentials: bool | None = ...,
20+
max_age: timedelta | int | str | None = ...,
21+
send_wildcard: bool | None = ...,
22+
vary_header: bool | None = ...,
23+
**kwargs: Any,
24+
) -> None: ...
25+
def init_app(
26+
self,
27+
app: _App,
28+
*,
29+
resources: dict[str, dict[str, Any]] | list[str] | str = ...,
30+
origins: str | list[str] = ...,
31+
methods: str | list[str] = ...,
32+
expose_headers: str | list[str] = ...,
33+
allow_headers: str | list[str] = ...,
34+
supports_credentials: bool = ...,
35+
max_age: timedelta | int | str | None = ...,
36+
send_wildcard: bool = ...,
37+
vary_header: bool = ...,
38+
**kwargs: Any,
39+
) -> None: ...
40+
41+
def make_after_request_function(resources: Iterable[tuple[str, dict[str, Any]]]) -> Callable[..., Any]: ...
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__: str

0 commit comments

Comments
 (0)