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

WIP start typehints #323

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
36 changes: 23 additions & 13 deletions flask_bootstrap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
"""TODO."""

import warnings
from typing import NoReturn, ParamSpec

from flask import current_app, Blueprint, url_for
from markupsafe import Markup
from wtforms import BooleanField, HiddenField

P = ParamSpec('P')

CDN_BASE = 'https://cdn.jsdelivr.net/npm'


def is_hidden_field_filter(field):
"""TODO."""
return isinstance(field, HiddenField)


def raise_helper(message):
def raise_helper(message: str) -> NoReturn:
"""TODO."""
raise RuntimeError(message)


def get_table_titles(data, primary_key, primary_key_title):
def get_table_titles(data: list, primary_key: str, primary_key_title: str) -> list[tuple[str, str]]:
"""Detect and build the table titles tuple from ORM object, currently only support SQLAlchemy.

.. versionadded:: 1.4.0
Expand All @@ -37,14 +44,14 @@ class _Bootstrap:
.. versionadded:: 2.0.0
"""

bootstrap_version = None
jquery_version = None
popper_version = None
bootstrap_css_integrity = None
bootstrap_js_integrity = None
jquery_integrity = None
popper_integrity = None
static_folder = None
bootstrap_version: str | None = None
jquery_version: str | None = None
popper_version: str | None = None
bootstrap_css_integrity: str | None = None
bootstrap_js_integrity: str | None = None
jquery_integrity: str | None = None
popper_integrity: str | None = None
static_folder: str | None = None
bootstrap_css_filename = 'bootstrap.min.css'
bootstrap_js_filename = 'bootstrap.min.js'
jquery_filename = 'jquery.min.js'
Expand All @@ -55,7 +62,7 @@ def __init__(self, app=None):
self.init_app(app)

def init_app(self, app):

"""TODO."""
if not hasattr(app, 'extensions'):
app.extensions = {} # pragma: no cover
app.extensions['bootstrap'] = self
Expand Down Expand Up @@ -269,6 +276,8 @@ def create_app():


class Bootstrap(Bootstrap4):
"""TODO."""

def __init__(self, app=None):
super().__init__(app=app)
warnings.warn(
Expand All @@ -284,6 +293,7 @@ class SwitchField(BooleanField):

.. versionadded:: 2.0.0
"""

def __init__(self, label=None, **kwargs):
def __init__(self, label: str | None = None,
*args: P.args,
**kwargs: P.kwargs) -> None:
super().__init__(label, **kwargs)
Loading