Skip to content

Commit

Permalink
use explicit optional type on arguments with default None value
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Höfling <[email protected]>
  • Loading branch information
hoefling committed Jan 27, 2020
1 parent 3bc1096 commit 2707140
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
22 changes: 11 additions & 11 deletions src/graphql/graphql.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from asyncio import ensure_future
from inspect import isawaitable
from typing import Any, Awaitable, Dict, Union, Type, cast
from typing import Any, Awaitable, Dict, Optional, Union, Type, cast

from .error import GraphQLError
from .execution import execute, ExecutionResult, ExecutionContext, Middleware
Expand All @@ -21,11 +21,11 @@ async def graphql(
source: Union[str, Source],
root_value: Any = None,
context_value: Any = None,
variable_values: Dict[str, Any] = None,
operation_name: str = None,
field_resolver: GraphQLFieldResolver = None,
type_resolver: GraphQLTypeResolver = None,
middleware: Middleware = None,
variable_values: Optional[Dict[str, Any]] = None,
operation_name: Optional[str] = None,
field_resolver: Optional[GraphQLFieldResolver] = None,
type_resolver: Optional[GraphQLTypeResolver] = None,
middleware: Optional[Middleware] = None,
execution_context_class: Type[ExecutionContext] = ExecutionContext,
) -> ExecutionResult:
"""Execute a GraphQL operation asynchronously.
Expand Down Expand Up @@ -95,11 +95,11 @@ def graphql_sync(
source: Union[str, Source],
root_value: Any = None,
context_value: Any = None,
variable_values: Dict[str, Any] = None,
operation_name: str = None,
field_resolver: GraphQLFieldResolver = None,
type_resolver: GraphQLTypeResolver = None,
middleware: Middleware = None,
variable_values: Optional[Dict[str, Any]] = None,
operation_name: Optional[str] = None,
field_resolver: Optional[GraphQLFieldResolver] = None,
type_resolver: Optional[GraphQLTypeResolver] = None,
middleware: Optional[Middleware] = None,
execution_context_class: Type[ExecutionContext] = ExecutionContext,
) -> ExecutionResult:
"""Execute a GraphQL operation synchronously.
Expand Down
25 changes: 17 additions & 8 deletions src/graphql/subscription/subscribe.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
from inspect import isawaitable
from typing import Any, AsyncIterable, AsyncIterator, Awaitable, Dict, Union, cast
from typing import (
Any,
AsyncIterable,
AsyncIterator,
Awaitable,
Dict,
Optional,
Union,
cast,
)

from ..error import GraphQLError, located_error
from ..execution.execute import (
Expand All @@ -23,10 +32,10 @@ async def subscribe(
document: DocumentNode,
root_value: Any = None,
context_value: Any = None,
variable_values: Dict[str, Any] = None,
operation_name: str = None,
field_resolver: GraphQLFieldResolver = None,
subscribe_field_resolver: GraphQLFieldResolver = None,
variable_values: Optional[Dict[str, Any]] = None,
operation_name: Optional[str] = None,
field_resolver: Optional[GraphQLFieldResolver] = None,
subscribe_field_resolver: Optional[GraphQLFieldResolver] = None,
) -> Union[AsyncIterator[ExecutionResult], ExecutionResult]:
"""Create a GraphQL subscription.
Expand Down Expand Up @@ -91,9 +100,9 @@ async def create_source_event_stream(
document: DocumentNode,
root_value: Any = None,
context_value: Any = None,
variable_values: Dict[str, Any] = None,
operation_name: str = None,
field_resolver: GraphQLFieldResolver = None,
variable_values: Optional[Dict[str, Any]] = None,
operation_name: Optional[str] = None,
field_resolver: Optional[GraphQLFieldResolver] = None,
) -> Union[AsyncIterable[Any], ExecutionResult]:
"""Create source even stream
Expand Down
12 changes: 6 additions & 6 deletions src/graphql/validation/validate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Collection, List
from typing import Collection, List, Optional

from ..error import GraphQLError
from ..language import DocumentNode, ParallelVisitor, visit
Expand All @@ -19,9 +19,9 @@ class ValidationAbortedError(RuntimeError):
def validate(
schema: GraphQLSchema,
document_ast: DocumentNode,
rules: Collection[RuleType] = None,
type_info: TypeInfo = None,
max_errors: int = None,
rules: Optional[Collection[RuleType]] = None,
type_info: Optional[TypeInfo] = None,
max_errors: Optional[int] = None,
) -> List[GraphQLError]:
"""Implements the "Validation" section of the spec.
Expand Down Expand Up @@ -82,8 +82,8 @@ def on_error(error: GraphQLError) -> None:

def validate_sdl(
document_ast: DocumentNode,
schema_to_extend: GraphQLSchema = None,
rules: Collection[RuleType] = None,
schema_to_extend: Optional[GraphQLSchema] = None,
rules: Optional[Collection[RuleType]] = None,
) -> List[GraphQLError]:
"""Validate an SDL document.
Expand Down

0 comments on commit 2707140

Please sign in to comment.