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

[pre-commit.ci] pre-commit autoupdate #3796

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.7
rev: v0.11.2
hooks:
- id: ruff-format
exclude: ^tests/\w+/snapshots/
Expand Down
2 changes: 1 addition & 1 deletion strawberry/aiohttp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def get_body(self) -> str:

@property
def method(self) -> HTTPMethod:
return cast(HTTPMethod, self.request.method.upper())
return cast("HTTPMethod", self.request.method.upper())

@property
def headers(self) -> Mapping[str, str]:
Expand Down
4 changes: 2 additions & 2 deletions strawberry/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def resolve(self) -> Union[StrawberryType, type]:
return self.__resolve_cache__

def _resolve(self) -> Union[StrawberryType, type]:
evaled_type = cast(Any, self.evaluate())
evaled_type = cast("Any", self.evaluate())

if is_private(evaled_type):
return evaled_type
Expand Down Expand Up @@ -158,7 +158,7 @@ def _resolve(self) -> Union[StrawberryType, type]:
if self._is_union(evaled_type, args):
return self.create_union(evaled_type, args)
if is_type_var(evaled_type) or evaled_type is Self:
return self.create_type_var(cast(TypeVar, evaled_type))
return self.create_type_var(cast("TypeVar", evaled_type))
if self._is_strawberry_type(evaled_type):
# Simply return objects that are already StrawberryTypes
return evaled_type
Expand Down
2 changes: 1 addition & 1 deletion strawberry/asgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def query_params(self) -> QueryParams:

@property
def method(self) -> HTTPMethod:
return cast(HTTPMethod, self.request.method.upper())
return cast("HTTPMethod", self.request.method.upper())

@property
def headers(self) -> Mapping[str, str]:
Expand Down
2 changes: 1 addition & 1 deletion strawberry/chalice/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def body(self) -> Union[str, bytes]:

@property
def method(self) -> HTTPMethod:
return cast(HTTPMethod, self.request.method.upper())
return cast("HTTPMethod", self.request.method.upper())

@property
def headers(self) -> Mapping[str, str]:
Expand Down
2 changes: 1 addition & 1 deletion strawberry/cli/commands/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def codegen(
console_plugin.before_any_start()

for q in query:
plugins = cast(list[QueryCodegenPlugin], _load_plugins(selected_plugins, q))
plugins = cast("list[QueryCodegenPlugin]", _load_plugins(selected_plugins, q))

code_generator = QueryCodegen(
schema_symbol, plugins=plugins, console_plugin=console_plugin
Expand Down
12 changes: 6 additions & 6 deletions strawberry/codegen/query_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def _populate_fragment_types(self, ast: DocumentNode) -> None:
# The FragmentDefinitionNode has a non-Optional `SelectionSetNode` but
# the Protocol wants an `Optional[SelectionSetNode]` so this doesn't
# quite conform.
cast(HasSelectionSet, fd),
cast("HasSelectionSet", fd),
parent_type=query_type,
class_name=fd.name.value,
graph_ql_object_type_factory=graph_ql_object_type_factory,
Expand Down Expand Up @@ -468,13 +468,13 @@ def _convert_operation(
result_class_name = f"{operation_name}Result"

operation_type = self._collect_types(
cast(HasSelectionSet, operation_definition),
cast("HasSelectionSet", operation_definition),
parent_type=query_type,
class_name=result_class_name,
)

operation_kind = cast(
Literal["query", "mutation", "subscription"],
"Literal['query', 'mutation', 'subscription']",
operation_definition.operation.value,
)

Expand Down Expand Up @@ -801,7 +801,7 @@ def _collect_types(
# `GraphQLField` or `GraphQLFragmentSpread`
# and the suite above will cause this statement to be
# skipped if there are any `GraphQLFragmentSpread`.
current_type.fields = cast(list[GraphQLField], fields)
current_type.fields = cast("list[GraphQLField]", fields)

self._collect_type(current_type)

Expand Down Expand Up @@ -854,7 +854,7 @@ def _collect_types_using_fragments(
assert isinstance(sub_selection, FieldNode)

parent_type = cast(
StrawberryObjectDefinition,
"StrawberryObjectDefinition",
self.schema.get_type_by_name(type_condition_name),
)

Expand Down Expand Up @@ -889,7 +889,7 @@ def _collect_types_using_fragments(
# `GraphQLField` or `GraphQLFragmentSpread`
# and the suite above will cause this statement to be
# skipped if there are any `GraphQLFragmentSpread`.
current_type.fields.extend(cast(list[GraphQLField], fields))
current_type.fields.extend(cast("list[GraphQLField]", fields))

sub_types.append(current_type)

Expand Down
4 changes: 2 additions & 2 deletions strawberry/django/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def body(self) -> Union[str, bytes]:
def method(self) -> HTTPMethod:
assert self.request.method is not None

return cast(HTTPMethod, self.request.method.upper())
return cast("HTTPMethod", self.request.method.upper())

@property
def headers(self) -> Mapping[str, str]:
Expand Down Expand Up @@ -114,7 +114,7 @@ def query_params(self) -> QueryParams:
def method(self) -> HTTPMethod:
assert self.request.method is not None

return cast(HTTPMethod, self.request.method.upper())
return cast("HTTPMethod", self.request.method.upper())

@property
def headers(self) -> Mapping[str, str]:
Expand Down
2 changes: 1 addition & 1 deletion strawberry/exceptions/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
# (we'd need to do type ignore for python 3.8 and above, but mypy
# doesn't seem to be able to handle that and will complain in python 3.7)

cast(Any, original_threading_exception_hook)(args)
cast("Any", original_threading_exception_hook)(args)

Check warning on line 73 in strawberry/exceptions/handler.py

View check run for this annotation

Codecov / codecov/patch

strawberry/exceptions/handler.py#L73

Added line #L73 was not covered by tests

return

Expand Down
2 changes: 1 addition & 1 deletion strawberry/experimental/pydantic/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _convert_from_pydantic_to_strawberry_type(
if hasattr(option_type, "_pydantic_type"):
source_type = option_type._pydantic_type
else:
source_type = cast(type, option_type)
source_type = cast("type", option_type)
if isinstance(data, source_type):
return _convert_from_pydantic_to_strawberry_type(
option_type, data_from_model=data, extra=extra
Expand Down
2 changes: 1 addition & 1 deletion strawberry/experimental/pydantic/error_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def wrap(cls: type) -> type:
]

wrapped: type[WithStrawberryObjectDefinition] = _wrap_dataclass(cls)
extra_fields = cast(list[dataclasses.Field], _get_fields(wrapped, {}))
extra_fields = cast("list[dataclasses.Field]", _get_fields(wrapped, {}))
private_fields = get_private_fields(wrapped)

all_model_fields.extend(
Expand Down
2 changes: 1 addition & 1 deletion strawberry/experimental/pydantic/object_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def wrap(cls: Any) -> builtins.type[StrawberryTypeFromPydantic[PydanticModel]]:

wrapped = _wrap_dataclass(cls)
extra_strawberry_fields = _get_fields(wrapped, {})
extra_fields = cast(list[dataclasses.Field], extra_strawberry_fields)
extra_fields = cast("list[dataclasses.Field]", extra_strawberry_fields)
private_fields = get_private_fields(wrapped)

extra_fields_dict = {field.name: field for field in extra_strawberry_fields}
Expand Down
4 changes: 2 additions & 2 deletions strawberry/ext/mypy_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,15 @@ def strawberry_pydantic_class_callback(ctx: ClassDefContext) -> None:
]
add_method(ctx, "__init__", init_args, NoneType())

model_type = cast(Instance, _get_type_for_expr(model_expression, ctx.api))
model_type = cast("Instance", _get_type_for_expr(model_expression, ctx.api))

# these are the fields that the user added to the strawberry type
new_strawberry_fields: set[str] = set()

# TODO: think about inheritance for strawberry?
for stmt in ctx.cls.defs.body:
if isinstance(stmt, AssignmentStmt):
lhs = cast(NameExpr, stmt.lvalues[0])
lhs = cast("NameExpr", stmt.lvalues[0])
new_strawberry_fields.add(lhs.name)

pydantic_fields: set[PydanticModelField] = set()
Expand Down
2 changes: 1 addition & 1 deletion strawberry/fastapi/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def dependency(
connection: HTTPConnection,
response: Response = None, # type: ignore
) -> MergedContext:
request = cast(Union[Request, WebSocket], connection)
request = cast("Union[Request, WebSocket]", connection)
if isinstance(custom_context, BaseContext):
custom_context.request = request
custom_context.background_tasks = background_tasks
Expand Down
2 changes: 1 addition & 1 deletion strawberry/federation/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def entities_resolver(
type_name = representation.pop("__typename")
type_ = self.schema_converter.type_map[type_name]

definition = cast(StrawberryObjectDefinition, type_.definition)
definition = cast("StrawberryObjectDefinition", type_.definition)

if hasattr(definition.origin, "resolve_reference"):
resolve_reference = definition.origin.resolve_reference
Expand Down
4 changes: 2 additions & 2 deletions strawberry/flask/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def body(self) -> Union[str, bytes]:

@property
def method(self) -> HTTPMethod:
return cast(HTTPMethod, self.request.method.upper())
return cast("HTTPMethod", self.request.method.upper())

@property
def headers(self) -> Mapping[str, str]:
Expand Down Expand Up @@ -139,7 +139,7 @@ def query_params(self) -> QueryParams:

@property
def method(self) -> HTTPMethod:
return cast(HTTPMethod, self.request.method.upper())
return cast("HTTPMethod", self.request.method.upper())

@property
def content_type(self) -> Optional[str]:
Expand Down
2 changes: 1 addition & 1 deletion strawberry/http/async_base_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ async def run(
await websocket.close(4406, "Subprotocol not acceptable")

return websocket_response
request = cast(Request, request)
request = cast("Request", request)

request_adapter = self.request_adapter_class(request)
sub_response = await self.get_sub_response(request)
Expand Down
2 changes: 1 addition & 1 deletion strawberry/litestar/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def query_params(self) -> QueryParams:

@property
def method(self) -> HTTPMethod:
return cast(HTTPMethod, self.request.method.upper())
return cast("HTTPMethod", self.request.method.upper())

@property
def headers(self) -> Mapping[str, str]:
Expand Down
14 changes: 7 additions & 7 deletions strawberry/printer/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def print_schema_directive(
directive: Any, schema: BaseSchema, *, extras: PrintExtras
) -> str:
strawberry_directive = cast(
StrawberrySchemaDirective, directive.__class__.__strawberry_directive__
"StrawberrySchemaDirective", directive.__class__.__strawberry_directive__
)
schema_converter = schema.schema_converter
gql_directive = schema_converter.from_schema_directive(directive.__class__)
Expand All @@ -178,13 +178,13 @@ def print_schema_directive(
f_type = f_type.of_type

if has_object_definition(f_type):
extras.types.add(cast(type, f_type))
extras.types.add(cast("type", f_type))

if hasattr(f_type, "_scalar_definition"):
extras.types.add(cast(type, f_type))
extras.types.add(cast("type", f_type))

if isinstance(f_type, EnumDefinition):
extras.types.add(cast(type, f_type))
extras.types.add(cast("type", f_type))

return f" @{gql_directive.name}{params}"

Expand Down Expand Up @@ -363,7 +363,7 @@ def print_extends(type_: GraphQLObjectType, schema: BaseSchema) -> str:
from strawberry.schema.schema_converter import GraphQLCoreConverter

strawberry_type = cast(
Optional[StrawberryObjectDefinition],
"Optional[StrawberryObjectDefinition]",
type_.extensions
and type_.extensions.get(GraphQLCoreConverter.DEFINITION_BACKREF),
)
Expand All @@ -380,7 +380,7 @@ def print_type_directives(
from strawberry.schema.schema_converter import GraphQLCoreConverter

strawberry_type = cast(
Optional[StrawberryObjectDefinition],
"Optional[StrawberryObjectDefinition]",
type_.extensions
and type_.extensions.get(GraphQLCoreConverter.DEFINITION_BACKREF),
)
Expand Down Expand Up @@ -594,7 +594,7 @@ def is_builtin_directive(directive: GraphQLDirective) -> bool:

def print_schema(schema: BaseSchema) -> str:
graphql_core_schema = cast(
GraphQLSchema,
"GraphQLSchema",
schema._schema, # type: ignore
)
extras = PrintExtras()
Expand Down
2 changes: 1 addition & 1 deletion strawberry/quart/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def query_params(self) -> QueryParams:

@property
def method(self) -> HTTPMethod:
return cast(HTTPMethod, self.request.method.upper())
return cast("HTTPMethod", self.request.method.upper())

@property
def content_type(self) -> Optional[str]:
Expand Down
2 changes: 1 addition & 1 deletion strawberry/relay/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def exception_source(self) -> Optional[ExceptionSource]:
return None # pragma: no cover

source_finder = SourceFinder()
return source_finder.find_function_from_object(cast(Callable, self.function))
return source_finder.find_function_from_object(cast("Callable", self.function))


__all__ = [
Expand Down
14 changes: 7 additions & 7 deletions strawberry/relay/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async def resolve() -> Any:

return resolve()

return cast(Node, strawberry_cast(node_type, resolved_node))
return cast("Node", strawberry_cast(node_type, resolved_node))

return resolver

Expand Down Expand Up @@ -161,7 +161,7 @@ def resolver(
# we could end up resolving to a different type in case more than one
# are registered
def cast_nodes(node_t: type[Node], nodes: Iterable[Any]) -> list[Node]:
return [cast(Node, strawberry_cast(node_t, node)) for node in nodes]
return [cast("Node", strawberry_cast(node_t, node)) for node in nodes]

if awaitable_nodes or asyncgen_nodes:

Expand Down Expand Up @@ -196,7 +196,7 @@ async def resolve(resolved: Any = resolved_nodes) -> list[Node]:

# Resolve any generator to lists
resolved = {
node_t: cast_nodes(node_t, cast(Iterable[Node], nodes))
node_t: cast_nodes(node_t, cast("Iterable[Node]", nodes))
for node_t, nodes in resolved_nodes.items()
}
return [resolved[index_map[gid][0]][index_map[gid][1]] for gid in ids]
Expand Down Expand Up @@ -264,7 +264,7 @@ def apply(self, field: StrawberryField) -> None:
type_origin = get_origin(f_type) if is_generic_alias(f_type) else f_type

if not isinstance(type_origin, type) or not issubclass(type_origin, Connection):
raise RelayWrongAnnotationError(field.name, cast(type, field.origin))
raise RelayWrongAnnotationError(field.name, cast("type", field.origin))

assert field.base_resolver
# TODO: We are not using resolver_type.type because it will call
Expand Down Expand Up @@ -294,7 +294,7 @@ def apply(self, field: StrawberryField) -> None:
):
raise RelayWrongResolverAnnotationError(field.name, field.base_resolver)

self.connection_type = cast(type[Connection[Node]], f_type)
self.connection_type = cast("type[Connection[Node]]", f_type)

def resolve(
self,
Expand All @@ -310,7 +310,7 @@ def resolve(
) -> Any:
assert self.connection_type is not None
return self.connection_type.resolve_connection(
cast(Iterable[Node], next_(source, info, **kwargs)),
cast("Iterable[Node]", next_(source, info, **kwargs)),
info=info,
before=before,
after=after,
Expand Down Expand Up @@ -339,7 +339,7 @@ async def resolve_async(
nodes = await nodes

resolved = self.connection_type.resolve_connection(
cast(Iterable[Node], nodes),
cast("Iterable[Node]", nodes),
info=info,
before=before,
after=after,
Expand Down
Loading
Loading