Add initial type hints
This should make it easier for users to correctly use Flask. The hints are from Quart.
This commit is contained in:
parent
f405c6f19e
commit
77237093da
20 changed files with 820 additions and 461 deletions
|
|
@ -27,7 +27,7 @@ except ImportError:
|
|||
try:
|
||||
import ssl
|
||||
except ImportError:
|
||||
ssl = None
|
||||
ssl = None # type: ignore
|
||||
|
||||
|
||||
class NoAppException(click.UsageError):
|
||||
|
|
@ -860,7 +860,7 @@ def run_command(
|
|||
|
||||
@click.command("shell", short_help="Run a shell in the app context.")
|
||||
@with_appcontext
|
||||
def shell_command():
|
||||
def shell_command() -> None:
|
||||
"""Run an interactive Python shell in the context of a given
|
||||
Flask application. The application will populate the default
|
||||
namespace of this shell according to its configuration.
|
||||
|
|
@ -877,7 +877,7 @@ def shell_command():
|
|||
f"App: {app.import_name} [{app.env}]\n"
|
||||
f"Instance: {app.instance_path}"
|
||||
)
|
||||
ctx = {}
|
||||
ctx: dict = {}
|
||||
|
||||
# Support the regular Python interpreter startup script if someone
|
||||
# is using it.
|
||||
|
|
@ -922,7 +922,7 @@ def shell_command():
|
|||
)
|
||||
@click.option("--all-methods", is_flag=True, help="Show HEAD and OPTIONS methods.")
|
||||
@with_appcontext
|
||||
def routes_command(sort, all_methods):
|
||||
def routes_command(sort: str, all_methods: bool) -> None:
|
||||
"""Show all registered routes with endpoints and methods."""
|
||||
|
||||
rules = list(current_app.url_map.iter_rules())
|
||||
|
|
@ -935,9 +935,12 @@ def routes_command(sort, all_methods):
|
|||
if sort in ("endpoint", "rule"):
|
||||
rules = sorted(rules, key=attrgetter(sort))
|
||||
elif sort == "methods":
|
||||
rules = sorted(rules, key=lambda rule: sorted(rule.methods))
|
||||
rules = sorted(rules, key=lambda rule: sorted(rule.methods)) # type: ignore
|
||||
|
||||
rule_methods = [", ".join(sorted(rule.methods - ignored_methods)) for rule in rules]
|
||||
rule_methods = [
|
||||
", ".join(sorted(rule.methods - ignored_methods)) # type: ignore
|
||||
for rule in rules
|
||||
]
|
||||
|
||||
headers = ("Endpoint", "Methods", "Rule")
|
||||
widths = (
|
||||
|
|
@ -975,7 +978,7 @@ debug mode.
|
|||
)
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
# TODO omit sys.argv once https://github.com/pallets/click/issues/536 is fixed
|
||||
cli.main(args=sys.argv[1:])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue