diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2a5b1ba2..172fc3bf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,4 +26,4 @@ repos: rev: 3.7.7 hooks: - id: flake8 - exclude: (^docs/.*$|^scripts/generate_ast.py$|test_.*$) + exclude: test_.*$ diff --git a/docs/conf.py b/docs/conf.py index d5c9947c..0e34c364 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -14,7 +14,6 @@ import sys import os -import shlex # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the diff --git a/graphql/backend/__init__.py b/graphql/backend/__init__.py index 9cd0e198..faeb0033 100644 --- a/graphql/backend/__init__.py +++ b/graphql/backend/__init__.py @@ -9,9 +9,6 @@ from .decider import GraphQLDeciderBackend from .cache import GraphQLCachedBackend -# Necessary for static type checking -if False: # flake8: noqa - from typing import Union _default_backend = None diff --git a/graphql/backend/cache.py b/graphql/backend/cache.py index 00680644..f35a45ca 100644 --- a/graphql/backend/cache.py +++ b/graphql/backend/cache.py @@ -7,7 +7,7 @@ # Necessary for static type checking if False: # flake8: noqa - from typing import Any, Dict, Optional, Union, Tuple, Hashable + from typing import Dict, Optional, Hashable from .base import GraphQLDocument _cached_schemas = {} # type: Dict[GraphQLSchema, str] diff --git a/graphql/backend/decider.py b/graphql/backend/decider.py index 3abb3ce5..5fdd39bb 100644 --- a/graphql/backend/decider.py +++ b/graphql/backend/decider.py @@ -11,7 +11,7 @@ # Necessary for static type checking if False: # flake8: noqa - from typing import List, Union, Any, Optional, Hashable, Dict, Tuple, Type + from typing import List, Union, Optional, Hashable, Dict, Tuple, Type from ..type.schema import GraphQLSchema diff --git a/graphql/error/format_error.py b/graphql/error/format_error.py index a854095b..e88b1e0e 100644 --- a/graphql/error/format_error.py +++ b/graphql/error/format_error.py @@ -2,7 +2,7 @@ # Necessary for static type checking if False: # flake8: noqa - from typing import Any, Dict, Union + from typing import Any, Dict def format_error(error): diff --git a/graphql/execution/executors/utils.py b/graphql/execution/executors/utils.py index 1ba3aaa6..869a81cc 100644 --- a/graphql/execution/executors/utils.py +++ b/graphql/execution/executors/utils.py @@ -4,7 +4,7 @@ if False: # flake8: noqa from ..base import ResolveInfo from promise import Promise - from typing import Callable, Dict, Tuple, Union, Any + from typing import Callable, Dict, Tuple, Any def process( diff --git a/graphql/execution/middleware.py b/graphql/execution/middleware.py index be61abda..dd00fd44 100644 --- a/graphql/execution/middleware.py +++ b/graphql/execution/middleware.py @@ -2,12 +2,11 @@ from functools import partial from itertools import chain -from promise import Promise, promisify +from promise import promisify # Necessary for static type checking if False: # flake8: noqa - from .base import ResolveInfo - from typing import Any, Callable, Iterator, Tuple, Union, List, Dict, Iterable + from typing import Any, Callable, Iterator, Tuple, Dict, Iterable MIDDLEWARE_RESOLVER_FUNCTION = "resolve" diff --git a/graphql/language/ast.py b/graphql/language/ast.py index f7f407ea..0c40d440 100644 --- a/graphql/language/ast.py +++ b/graphql/language/ast.py @@ -1,7 +1,7 @@ # Necessary for static type checking if False: # flake8: noqa from .parser import Loc - from typing import Any, Optional, Union, List, Tuple, Iterable + from typing import Any, Optional, Union, List, Iterable # This is autogenerated code. DO NOT change this manually. # Run scripts/generate_ast.py to generate this file. diff --git a/graphql/language/printer.py b/graphql/language/printer.py index d2f27ef8..e540bce5 100644 --- a/graphql/language/printer.py +++ b/graphql/language/printer.py @@ -4,45 +4,8 @@ # Necessary for static type checking if False: # flake8: noqa - from typing import Any, List, Optional, Union - from graphql.language.ast import ( - Node, - Name, - Variable, - Document, - OperationDefinition, - VariableDefinition, - SelectionSet, - Field, - Argument, - FragmentSpread, - InlineFragment, - FragmentDefinition, - IntValue, - StringValue, - BooleanValue, - EnumValue, - ListValue, - ObjectValue, - ObjectField, - Directive, - NamedType, - ListType, - NonNullType, - SchemaDefinition, - OperationTypeDefinition, - ScalarTypeDefinition, - ObjectTypeDefinition, - FieldDefinition, - InputValueDefinition, - InterfaceTypeDefinition, - UnionTypeDefinition, - EnumTypeDefinition, - EnumValueDefinition, - InputObjectTypeDefinition, - TypeExtensionDefinition, - DirectiveDefinition, - ) + from typing import Any, List, Optional + from graphql.language.ast import Node __all__ = ["print_ast"] diff --git a/graphql/language/visitor.py b/graphql/language/visitor.py index 66dded46..42b1a2c9 100644 --- a/graphql/language/visitor.py +++ b/graphql/language/visitor.py @@ -9,9 +9,6 @@ if False: # flake8: noqa from typing import Any, List, Optional, Union, Tuple, Dict from ..utils.type_info import TypeInfo - from ..validation.validation import UsageVisitor - from .ast import Node, Document, OperationDefinition - from .printer import PrintingVisitor class _Falsey(object): @@ -44,7 +41,7 @@ def __init__(self, in_array, index, keys, edits, prev): def visit(root, visitor, key_map=None): - # type: (Union[Node, List[Node]], Visitor, Optional[Dict[Node, Tuple]]) -> Any + # type: (Union[ast.Node, List[ast.Node]], Visitor, Optional[Dict[ast.Node, Tuple]]) -> Any visitor_keys = key_map or QUERY_DOCUMENT_KEYS stack = None # type: Optional[Stack] @@ -52,9 +49,9 @@ def visit(root, visitor, key_map=None): keys = [root] index = -1 edits = [] # type: List[Tuple[Union[str, int], Any]] - parent = None # type: Optional[Node] + parent = None # type: Optional[ast.Node] path = [] # type: List - ancestors = [] # type: List[Node] + ancestors = [] # type: List[ast.Node] new_root = root leave = visitor.leave enter = visitor.enter @@ -214,7 +211,7 @@ def __init__(self, visitors): self.visitors = visitors self.skipping = [None] * len( visitors - ) # type: List[Union[Node, _Break, _Falsey, None]] + ) # type: List[Union[ast.Node, _Break, _Falsey, None]] return None def enter( diff --git a/graphql/pyutils/contain_subset.py b/graphql/pyutils/contain_subset.py index 3b34c621..7c41ea55 100644 --- a/graphql/pyutils/contain_subset.py +++ b/graphql/pyutils/contain_subset.py @@ -1,6 +1,6 @@ # Necessary for static type checking if False: # flake8: noqa - from typing import Any, Dict + from typing import Any obj = (dict, list, tuple) diff --git a/graphql/pyutils/default_ordered_dict.py b/graphql/pyutils/default_ordered_dict.py index 61f8d67c..718b324b 100644 --- a/graphql/pyutils/default_ordered_dict.py +++ b/graphql/pyutils/default_ordered_dict.py @@ -3,7 +3,7 @@ # Necessary for static type checking if False: # flake8: noqa - from typing import Any, List + from typing import Any class DefaultOrderedDict(OrderedDict): diff --git a/graphql/type/schema.py b/graphql/type/schema.py index 618a2418..697a8ae9 100644 --- a/graphql/type/schema.py +++ b/graphql/type/schema.py @@ -16,7 +16,7 @@ GraphQLUnionType, GraphQLType, ) - from typing import Dict, Union, Any, List, Optional + from typing import Dict, Union, List, Optional class GraphQLSchema(object): diff --git a/graphql/type/typemap.py b/graphql/type/typemap.py index 62c017f9..427417ca 100644 --- a/graphql/type/typemap.py +++ b/graphql/type/typemap.py @@ -18,7 +18,7 @@ # Necessary for static type checking if False: # flake8: noqa from ..type.definition import GraphQLNamedType - from typing import Any, List, Optional, Union, Dict, Set, Mapping, DefaultDict + from typing import List, Union, Dict, Set, DefaultDict class GraphQLTypeMap(OrderedDict): diff --git a/graphql/utils/schema_printer.py b/graphql/utils/schema_printer.py index 30a28abd..f3193330 100644 --- a/graphql/utils/schema_printer.py +++ b/graphql/utils/schema_printer.py @@ -17,7 +17,6 @@ GraphQLArgument, GraphQLType, GraphQLField, - GraphQLInputObjectField, GraphQLEnumValue, ) from ..type.schema import GraphQLSchema diff --git a/graphql/utils/type_from_ast.py b/graphql/utils/type_from_ast.py index 1694cfd4..6868c138 100644 --- a/graphql/utils/type_from_ast.py +++ b/graphql/utils/type_from_ast.py @@ -6,7 +6,7 @@ from ..language.ast import ListType, NamedType, NonNullType from ..type.definition import GraphQLNamedType from ..type.schema import GraphQLSchema - from typing import Any, Union + from typing import Union def type_from_ast(schema, type_node): diff --git a/graphql/utils/value_from_ast.py b/graphql/utils/value_from_ast.py index ff012896..7ad52bca 100644 --- a/graphql/utils/value_from_ast.py +++ b/graphql/utils/value_from_ast.py @@ -11,7 +11,7 @@ if False: # flake8: noqa from ..language.ast import Node from ..type.definition import GraphQLType - from typing import Any, Dict, Union, Optional, List + from typing import Dict, Union, Optional, List def value_from_ast(value_ast, type, variables=None): diff --git a/graphql/validation/rules/overlapping_fields_can_be_merged.py b/graphql/validation/rules/overlapping_fields_can_be_merged.py index a46b66f1..f8b01e20 100644 --- a/graphql/validation/rules/overlapping_fields_can_be_merged.py +++ b/graphql/validation/rules/overlapping_fields_can_be_merged.py @@ -28,7 +28,7 @@ InlineFragment, SelectionSet, ) - from ...type.definition import GraphQLUnionType, GraphQLField, GraphQLScalarType + from ...type.definition import GraphQLField, GraphQLScalarType from typing import List, Union, Any, Optional, Dict, Tuple diff --git a/graphql/validation/validation.py b/graphql/validation/validation.py index ba8f28db..1c3948fd 100644 --- a/graphql/validation/validation.py +++ b/graphql/validation/validation.py @@ -11,11 +11,8 @@ from ..error import GraphQLError from .rules.base import ValidationRule from ..type.definition import ( - GraphQLList, GraphQLObjectType, - GraphQLScalarType, GraphQLInterfaceType, - GraphQLUnionType, GraphQLField, GraphQLArgument, GraphQLType, diff --git a/scripts/generate_ast.py b/scripts/generate_ast.py index 06e098a2..2e62a286 100644 --- a/scripts/generate_ast.py +++ b/scripts/generate_ast.py @@ -1,3 +1,5 @@ +from casing import snake + if __name__ == "__main__": import os.path import sys @@ -14,8 +16,6 @@ sys.exit(process.wait()) -from casing import snake - # Fix inconsistencies between libgraphqlparser and graphql-js REMAP_TYPES = {"ArrayValue": "ListValue"} diff --git a/tox.ini b/tox.ini index 242e45a4..4d39ef9b 100644 --- a/tox.ini +++ b/tox.ini @@ -37,4 +37,4 @@ commands = sphinx-build -W -b html -d {envtmpdir}/doctrees . {envtmpdir}/html [flake8] # Must match black formatter default line length max-line-length = 88 -ignore = F401,E203,E501,W503,W504 +ignore = E203,E501,W503,W504