fix pyright type errors
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by bre-17387639 · committed by David Lord · parent 5e8cb74 · Browse files · 10 files·+22 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+22 added−19 removed
- other:+22 added−19 removed
Provenance
- Commit
9e831e9- Tree
eb6e484- Author
bre-17387639 <425026+bre-17387639@users.noreply.github.com>- Committer
David Lord <davidism@gmail.com>- Parent
5e8cb74
10 files changed+22 added−19 removed
modified:src/flask/sansio/app.py+1 added-1 removed
626 unmodified lines627 )628 methods = {item.upper() for item in methods}629 630 # Methods that should always be added631- required_methods = set(getattr(view_func, "required_methods", ()))631+ required_methods: set[str] = set(getattr(view_func, "required_methods", ()))632 633 # starting with Flask 0.8 the view_func object can disable and634 # force-enable the automatic options handling.635 if provide_automatic_options is None:329 unmodified linesmodified:src/flask/app.py+5 added-3 removed
57 unmodified lines58 from _typeshed.wsgi import WSGIEnvironment59 60 from .testing import FlaskClient61 from .testing import FlaskCliRunner62+ from .typing import HeadersValue63 64 T_shell_context_processor = t.TypeVar(65 "T_shell_context_processor", bound=ft.ShellContextProcessorCallable66 )282 unmodified lines349 350 path = os.path.join(self.root_path, resource)351 352 if mode == "rb":352- return open(path, mode)353+ return open(path, mode) # pyright: ignore354 355 return open(path, mode, encoding=encoding)356 357 def open_instance_resource(805 unmodified lines1163 Previously a tuple was interpreted as the arguments for the1164 response object.1165 """1166 1166- status = headers = None1167+ status: int | None = None1168+ headers: HeadersValue | None = None1169 1170 # unpack tuple returns1171 if isinstance(rv, tuple):1172 len_rv = len(rv)3 unmodified lines1176 rv, status, headers = rv # type: ignore[misc]1177 # decide if a 2-tuple has status or headers1178 elif len_rv == 2:1179 if isinstance(rv[1], (Headers, dict, tuple, list)):1178- rv, headers = rv1180+ rv, headers = rv # pyright: ignore1181 else:1182 rv, status = rv # type: ignore[assignment,misc]1183 # other sized tuples are not allowed1184 else:333 unmodified linesmodified:src/flask/blueprints.py+1 added-1 removed
121 unmodified lines122 123 path = os.path.join(self.root_path, resource)124 125 if mode == "rb":126- return open(path, mode)126+ return open(path, mode) # pyright: ignore127 128 return open(path, mode, encoding=encoding)modified:src/flask/cli.py+5 added-5 removed
321 unmodified lines322 be returned.323 """324 if self._loaded_app is not None:325 return self._loaded_app326-326+ app: Flask | None = None327 if self.create_app is not None:328- app: Flask | None = self.create_app()328+ app = self.create_app()329 else:330 if self.app_import_path:331 path, name = (332 re.split(r":(?![\\/])", self.app_import_path, maxsplit=1) + [None]215 unmodified lines548 load_dotenv: bool = True,549 set_debug_flag: bool = True,550 **extra: t.Any,551 ) -> None:552- params = list(extra.pop("params", None) or ())552+ params: list[click.Parameter] = list(extra.pop("params", None) or ())553 # Processing is done with option callbacks instead of a group554 # callback. This allows users to make a custom group callback555 # without losing the behavior. --env-file must come first so556 # that it is eagerly evaluated before --app.29 unmodified lines586 else:587 # Use a backport on Python < 3.10. We technically have588 # importlib.metadata on 3.8+, but the API changed in 3.10,589 # so use the backport for consistency.590- import importlib_metadata as metadata590+ import importlib_metadata as metadata # pyright: ignore591 592 for ep in metadata.entry_points(group="flask.commands"):593 self.add_command(ep.load(), ep.name)594 338 unmodified lines933 The reloader and debugger are enabled by default with the '--debug'934 option.935 """936 try:937- app: WSGIApplication = info.load_app()937+ app: WSGIApplication = info.load_app() # pyright: ignore938 except Exception as e:939 if is_running_from_reloader():940 # When reloading, print out the error immediately, but raise941 # it later so the debugger or server can handle it.168 unmodified linesmodified:src/flask/helpers.py+1 added-1 removed
597 unmodified lines598 if loader is None:599 return os.getcwd()600 601 if hasattr(loader, "get_filename"):602- filepath = loader.get_filename(import_name)602+ filepath = loader.get_filename(import_name) # pyright: ignore603 else:604 # Fall back to imports.605 __import__(import_name)606 mod = sys.modules[import_name]27 unmodified linesmodified:src/flask/testing.py+1 added-2 removed
77 unmodified lines78 )79 path = url.path80 81 if url.query:82- sep = b"?" if isinstance(url.query, bytes) else "?"83- path += sep + url.query82+ path = f"{path}?{url.query}"83 84 self.app = app85 super().__init__(path, base_url, *args, **kwargs)86 211 unmodified linesmodified:src/flask/views.py+2 added-2 removed
59 unmodified lines60 #: to top, so the first decorator in the list would be the bottom61 #: decorator.62 #:63 #: .. versionadded:: 0.864- decorators: t.ClassVar[list[t.Callable[[F], F]]] = []64+ decorators: t.ClassVar[list[t.Callable[..., t.Any]]] = []65 66 #: Create a new instance of this view class for every request by67 #: default. If a view subclass sets this to ``False``, the same68 #: instance is used for every request.40 unmodified lines109 )110 return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return]111 112 else:113- self = cls(*class_args, **class_kwargs)113+ self = cls(*class_args, **class_kwargs) # pyright: ignore114 115 def view(**kwargs: t.Any) -> ft.ResponseReturnValue:116 return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return]117 74 unmodified linesmodified:src/flask/wrappers.py+2 added-2 removed
127 unmodified lines128 129 def on_json_loading_failed(self, e: ValueError | None) -> t.Any:130 try:131 return super().on_json_loading_failed(e)132- except BadRequest as e:132+ except BadRequest as ebr:133 if current_app and current_app.debug:134 raise135 136- raise BadRequest() from e136+ raise BadRequest() from ebr137 138 139 class Response(ResponseBase):140 """The response object that is used by default in Flask. Works like the34 unmodified linesmodified:pyproject.toml+1 added-1 removed
93 unmodified lines94 ignore_missing_imports = true95 96 [tool.pyright]97 pythonVersion = "3.8"98-include = ["src/flask", "tests"]98+include = ["src/flask", "tests/typing"]99 typeCheckingMode = "basic"100 101 [tool.ruff]102 src = ["src"]22 unmodified linesmodified:tox.ini+3 added-1 removed
26 unmodified lines27 commands = pre-commit run --all-files28 29 [testenv:typing]30 deps = -r requirements/typing.txt31-commands = mypy31+commands =32+ mypy33+ pyright34 35 [testenv:docs]36 deps = -r requirements/docs.txt37 commands = sphinx-build -E -W -b dirhtml docs docs/_build/dirhtml23 unmodified lines