From 978bc1461001589d9f5539eb9f4eb4aa011f057a Mon Sep 17 00:00:00 2001 From: Michael Chase <3686226+reallistic@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:43:08 -0400 Subject: [PATCH] fix styles for newest version of mypy --- ariadne/contrib/tracing/copy_args.py | 3 ++- ariadne/contrib/tracing/utils.py | 3 ++- ariadne/load_schema.py | 3 ++- ariadne/wsgi.py | 7 +++++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ariadne/contrib/tracing/copy_args.py b/ariadne/contrib/tracing/copy_args.py index 474ce51d1..3c295a4a0 100644 --- a/ariadne/contrib/tracing/copy_args.py +++ b/ariadne/contrib/tracing/copy_args.py @@ -22,8 +22,9 @@ def copy_args_for_tracing(value: Any) -> Any: def repr_upload_file(upload_file: Union[UploadFile, File]) -> str: + filename: Union[str, None] if isinstance(upload_file, File): - filename = upload_file.file_name + filename = upload_file.file_name.decode() if upload_file.file_name else None else: filename = upload_file.filename diff --git a/ariadne/contrib/tracing/utils.py b/ariadne/contrib/tracing/utils.py index ad79c9454..d92dcb4d9 100644 --- a/ariadne/contrib/tracing/utils.py +++ b/ariadne/contrib/tracing/utils.py @@ -25,8 +25,9 @@ def copy_args_for_tracing(value: Any) -> Any: def repr_upload_file(upload_file: Union[UploadFile, File]) -> str: + filename: Union[str, None] if isinstance(upload_file, File): - filename = upload_file.file_name + filename = upload_file.file_name.decode() if upload_file.file_name else None else: filename = upload_file.filename diff --git a/ariadne/load_schema.py b/ariadne/load_schema.py index 43fdfd8b6..dac3bc8b5 100644 --- a/ariadne/load_schema.py +++ b/ariadne/load_schema.py @@ -1,4 +1,5 @@ import os +from pathlib import Path from typing import Generator, Union from graphql import parse @@ -27,7 +28,7 @@ def load_schema_from_path(path: Union[str, os.PathLike]) -> str: if os.path.isdir(path): schema_list = [read_graphql_file(f) for f in sorted(walk_graphql_files(path))] return "\n".join(schema_list) - return read_graphql_file(os.path.abspath(path)) + return read_graphql_file(Path(path).resolve()) def walk_graphql_files(path: Union[str, os.PathLike]) -> Generator[str, None, None]: diff --git a/ariadne/wsgi.py b/ariadne/wsgi.py index 8a185d797..ec652b0fd 100644 --- a/ariadne/wsgi.py +++ b/ariadne/wsgi.py @@ -40,7 +40,7 @@ from multipart import parse_form except ImportError: - def parse_form(*_args, **_kwargs): + def parse_form(*_args, **_kwargs): # type: ignore raise NotImplementedError( "WSGI file uploads requires 'python-multipart' library." ) @@ -668,8 +668,11 @@ def parse_multipart_request(environ: dict) -> "FormData": headers = {"Content-Type": content_type} form_data = FormData(content_type) + # Silence mypy error for this incorrect type. + # parse_fprm defines the type as dict[str, bytes] but works with + # dict[str, Optional[str | bytes]] and will throw ValueError if Content-Type is None. parse_form( - headers, + headers, # type: ignore environ["wsgi.input"], form_data.on_field, form_data.on_file,