Skip to content

Commit

Permalink
Update stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
Virashu committed Jul 25, 2024
1 parent f0aacf3 commit 728a6ca
Show file tree
Hide file tree
Showing 27 changed files with 80 additions and 1,288 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

runtime/**
!runtime/.gitkeep
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ analyzeUnannotatedFunctions = true
reportImplicitOverride = true
reportDeprecated = true
reportAny = false

stubPath = "./typings"
4 changes: 0 additions & 4 deletions typings/flask_wtf/_compat.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
"""
This type stub file was generated by pyright.
"""

class FlaskWTFDeprecationWarning(DeprecationWarning): ...
31 changes: 20 additions & 11 deletions typings/flask_wtf/csrf.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from typing import Any, TypeVar, Union, override
from flask import Blueprint, Flask
from werkzeug.exceptions import BadRequest
from wtforms.csrf.core import CSRF
from wtforms import Field
from wtforms.csrf.core import CSRF, CSRFTokenField
from wtforms.form import BaseForm

__all__ = ("generate_csrf", "validate_csrf", "CSRFProtect")
logger = ...

def generate_csrf(secret_key=..., token_key=...) -> Any:
def generate_csrf(secret_key: str = ..., token_key: str = ...) -> Any:
"""Generate a CSRF token. The token is cached for a request, so multiple
calls to this function will generate the same token.
Expand All @@ -18,7 +22,9 @@ def generate_csrf(secret_key=..., token_key=...) -> Any:
"""
...

def validate_csrf(data, secret_key=..., time_limit=..., token_key=...) -> None:
def validate_csrf(
data: str, secret_key: str = ..., time_limit: int = ..., token_key: str = ...
) -> None:
"""Check if the given data is a valid CSRF token. This compares the given
signed token to the one stored in the session.
Expand All @@ -39,9 +45,12 @@ def validate_csrf(data, secret_key=..., time_limit=..., token_key=...) -> None:
...

class _FlaskFormCSRF(CSRF):
def setup_form(self, form) -> list[tuple[str, UnboundField[Any]]]: ...
def generate_csrf_token(self, csrf_token_field) -> Any: ...
def validate_csrf_token(self, form, field) -> None: ...
@override
def generate_csrf_token(self, csrf_token_field: CSRFTokenField) -> Any: ...
@override
def validate_csrf_token(self, form: BaseForm, field: Field) -> None: ...

_T = TypeVar("_T", bound=Union[Blueprint, str, Any])

class CSRFProtect:
"""Enable CSRF protection globally for a Flask app.
Expand All @@ -58,10 +67,10 @@ class CSRFProtect:
See the :ref:`csrf` documentation.
"""

def __init__(self, app=...) -> None: ...
def init_app(self, app) -> None: ...
def __init__(self, app: Flask | None = ...) -> None: ...
def init_app(self, app: Flask) -> None: ...
def protect(self) -> None: ...
def exempt(self, view) -> Blueprint | str:
def exempt(self, view: _T) -> _T:
"""Mark a view or blueprint to be excluded from CSRF protection.
::
Expand All @@ -87,6 +96,6 @@ class CSRFError(BadRequest):
:meth:`flask.Flask.errorhandler`.
"""

description = ...
description: str

def same_origin(current_uri, compare_uri): ...
def same_origin(current_uri: str, compare_uri: str) -> bool: ...
58 changes: 38 additions & 20 deletions typings/flask_wtf/file.pyi
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
"""
This type stub file was generated by pyright.
"""

from wtforms import FileField as _FileField, MultipleFileField as _MultipleFileField
from _typeshed import Incomplete
from typing import Any, Iterable, TypeAlias, override

__all__ = (
"FileField",
"MultipleFileField",
"FileRequired",
"FileAllowed",
"FileSize",
"file_required",
"file_allowed",
"file_size",
)

from werkzeug.datastructures import FileStorage
from wtforms import (
Field,
FileField as _FileField,
MultipleFileField as _MultipleFileField,
)
from wtforms.form import BaseForm
from wtforms.validators import DataRequired

class FileField(_FileField):
"""Werkzeug-aware subclass of :class:`wtforms.fields.FileField`."""

def process_formdata(self, valuelist): # -> None:
...
@override
def process_formdata(self, valuelist: Iterable[FileStorage | Any]) -> None: ...

class MultipleFileField(_MultipleFileField):
"""Werkzeug-aware subclass of :class:`wtforms.fields.MultipleFileField`.
.. versionadded:: 1.2.0
"""

def process_formdata(self, valuelist): # -> None:
...
@override
def process_formdata(self, valuelist: Iterable[FileStorage | Any]) -> None: ...

class FileRequired(DataRequired):
"""Validates that the uploaded files(s) is a Werkzeug
Expand All @@ -29,10 +45,10 @@ class FileRequired(DataRequired):
You can also use the synonym ``file_required``.
"""

def __call__(self, form, field): # -> None:
...
@override
def __call__(self, form: BaseForm, field: Field) -> None: ...

file_required = FileRequired
file_required: TypeAlias = FileRequired

class FileAllowed:
"""Validates that the uploaded file(s) is allowed by a given list of
Expand All @@ -45,11 +61,12 @@ class FileAllowed:
You can also use the synonym ``file_allowed``.
"""

def __init__(self, upload_set, message=...) -> None: ...
def __call__(self, form, field): # -> None:
...
def __init__(
self, upload_set: Iterable[Incomplete] | Incomplete, message: str | None = None
) -> None: ...
def __call__(self, form: BaseForm, field: Field) -> None: ...

file_allowed = FileAllowed
file_allowed: TypeAlias = FileAllowed

class FileSize:
"""Validates that the uploaded file(s) is within a minimum and maximum
Expand All @@ -62,8 +79,9 @@ class FileSize:
You can also use the synonym ``file_size``.
"""

def __init__(self, max_size, min_size=..., message=...) -> None: ...
def __call__(self, form, field): # -> None:
...
def __init__(
self, max_size: int, min_size: int = 0, message: str | None = None
) -> None: ...
def __call__(self, form: BaseForm, field: Field) -> None: ...

file_size = FileSize
file_size: TypeAlias = FileSize
31 changes: 16 additions & 15 deletions typings/flask_wtf/form.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
This type stub file was generated by pyright.
"""

from typing import Callable, Sequence, Any
from typing import Any, Callable, Sequence

from flask.sessions import SessionMixin
from markupsafe import Markup
from werkzeug.datastructures import CombinedMultiDict, ImmutableMultiDict
from werkzeug.datastructures import CombinedMultiDict, ImmutableMultiDict, MultiDict
from werkzeug.utils import cached_property
from wtforms import Form
from wtforms.form import BaseForm
from wtforms.meta import DefaultMeta
from .csrf import _FlaskFormCSRF

SUBMIT_METHODS = ...
_Auto = ...
from .csrf import _FlaskFormCSRF # type: ignore

SUBMIT_METHODS: set[str] = ...
_Auto: object = ...

class FlaskForm(Form):
"""Flask-specific subclass of WTForms :class:`~wtforms.form.Form`.
Expand All @@ -23,28 +27,25 @@ class FlaskForm(Form):

class Meta(DefaultMeta):
csrf_class = _FlaskFormCSRF
csrf_context = ...
csrf_context: SessionMixin = ...
@cached_property
def csrf(self): ...
def csrf(self) -> bool: ... # type: ignore
@cached_property
def csrf_secret(self): ...
def csrf_secret(self) -> str: ... # type: ignore
@cached_property
def csrf_field_name(self): ...
def csrf_field_name(self) -> str: ... # type: ignore
@cached_property
def csrf_time_limit(self): ...
def csrf_time_limit(self) -> int: ... # type: ignore
def wrap_formdata(
self, form, formdata
self, form: BaseForm, formdata: MultiDict[Any, Any] | None
) -> (
CombinedMultiDict[Any, Any]
| ImmutableMultiDict[str, str]
| ImmutableMultiDict[Any, Any]
| None
): ...
def get_translations(
self, form
) -> _SupportsGettextAndNgettext | Translations | None: ...

def __init__(self, formdata=..., **kwargs) -> None: ...
def __init__(self, formdata=..., **kwargs: Any) -> None: ...
def is_submitted(self) -> bool:
"""Consider the form submitted if there is an active request and
the method is ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
Expand Down
12 changes: 3 additions & 9 deletions typings/flask_wtf/i18n.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
"""
This type stub file was generated by pyright.
"""

__all__ = ("Translations", "translations")

class Translations:
def gettext(self, string): # -> Any:
...
def ngettext(self, singular, plural, n): # -> Any:
...
def gettext(self, string: str) -> str: ...
def ngettext(self, singular: str, plural: str, n: int) -> str: ...

translations = ...
translations: Translations
4 changes: 1 addition & 3 deletions typings/flask_wtf/recaptcha/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
This type stub file was generated by pyright.
"""
__all__ = ("RecaptchaField", "Recaptcha", "RecaptchaWidget")

from .fields import RecaptchaField
from .validators import Recaptcha
Expand Down
4 changes: 0 additions & 4 deletions typings/flask_wtf/recaptcha/fields.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
"""
This type stub file was generated by pyright.
"""

from wtforms.fields import Field

__all__ = ["RecaptchaField"]
Expand Down
4 changes: 0 additions & 4 deletions typings/flask_wtf/recaptcha/validators.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
"""
This type stub file was generated by pyright.
"""

RECAPTCHA_VERIFY_SERVER_DEFAULT = ...
RECAPTCHA_ERROR_CODES = ...
__all__ = ["Recaptcha"]
Expand Down
8 changes: 0 additions & 8 deletions typings/wtforms/__init__.pyi

This file was deleted.

3 changes: 0 additions & 3 deletions typings/wtforms/csrf/__init__.pyi

This file was deleted.

12 changes: 0 additions & 12 deletions typings/wtforms/fields/__init__.pyi

This file was deleted.

83 changes: 0 additions & 83 deletions typings/wtforms/fields/choices.pyi

This file was deleted.

Loading

0 comments on commit 728a6ca

Please sign in to comment.