Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type annotations in Flask-Cors stubs #12596

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions stubs/Flask-Cors/flask_cors/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from collections.abc import Iterable
from datetime import timedelta
from logging import Logger
from re import Pattern
from typing import Any, Literal, TypedDict, TypeVar, overload
from typing import Any, Final, Literal, TypedDict, TypeVar, overload
from typing_extensions import TypeAlias

import flask
Expand All @@ -26,21 +26,22 @@ class _Options(TypedDict, total=False):
always_send: bool | None

LOG: Logger
ACL_ORIGIN: str
ACL_METHODS: str
ACL_ALLOW_HEADERS: str
ACL_EXPOSE_HEADERS: str
ACL_CREDENTIALS: str
ACL_MAX_AGE: str
ACL_RESPONSE_PRIVATE_NETWORK: str
ACL_REQUEST_HEADER_PRIVATE_NETWORK: str
ACL_REQUEST_METHOD: str
ACL_REQUEST_HEADERS: str
ALL_METHODS: list[str]
CONFIG_OPTIONS: list[str]
FLASK_CORS_EVALUATED: str
RegexObject: type[Pattern[str]]
DEFAULT_OPTIONS: _Options

ACL_ORIGIN: Final[str] = "Access-Control-Allow-Origin"
Copy link
Collaborator

@srittau srittau Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: If you have a default, you don't need to specify the type:

ACL_ORIGIN: Final = "Access-Control-Allow-Origin"

(Here and below.)

We should really have a flake8 warning for that. I filed PyCQA/flake8-pyi#499.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, everything will be fine now!

ACL_METHODS: Final[str] = "Access-Control-Allow-Methods"
ACL_ALLOW_HEADERS: Final[str] = "Access-Control-Allow-Headers"
ACL_EXPOSE_HEADERS: Final[str] = "Access-Control-Expose-Headers"
ACL_CREDENTIALS: Final[str] = "Access-Control-Allow-Credentials"
ACL_MAX_AGE: Final[str] = "Access-Control-Max-Age"
ACL_RESPONSE_PRIVATE_NETWORK: Final[str] = "Access-Control-Allow-Private-Network"
ACL_REQUEST_METHOD: Final[str] = "Access-Control-Request-Method"
ACL_REQUEST_HEADERS: Final[str] = "Access-Control-Request-Headers"
ACL_REQUEST_HEADER_PRIVATE_NETWORK: Final[str] = "Access-Control-Request-Private-Network"
ALL_METHODS: Final[list[str]]
CONFIG_OPTIONS: Final[list[str]]
FLASK_CORS_EVALUATED: Final[str] = "_FLASK_CORS_EVALUATED"
RegexObject: Final[type[Pattern[str]]]
DEFAULT_OPTIONS: Final[_Options]

def parse_resources(resources: dict[str, _Options] | Iterable[str] | str | Pattern[str]) -> list[tuple[str, _Options]]: ...
def get_regexp_pattern(regexp: str | Pattern[str]) -> str: ...
Expand Down