Skip to content

Commit

Permalink
Update docstrings to be python3 compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
ColCarroll committed Sep 18, 2017
1 parent c11223b commit 0619dca
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 42 deletions.
12 changes: 6 additions & 6 deletions graphql_compiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def graphql_to_match(schema, graphql_query, parameters):
Args:
schema: GraphQL schema object describing the schema of the graph to be queried
graphql_string: the GraphQL query to compile to MATCH, as a basestring
graphql_string: the GraphQL query to compile to MATCH, as a string
parameters: dict, mapping argument name to its value, for every parameter the query expects.
Returns:
a CompilationResult object, containing:
- query: basestring, the resulting compiled and parameterized query string
- language: basestring, specifying the language to which the query was compiled
- query: string, the resulting compiled and parameterized query string
- language: string, specifying the language to which the query was compiled
- output_metadata: dict, output name -> OutputMetadata namedtuple object
- input_metadata: dict, name of input variables -> inferred GraphQL type, based on use
"""
Expand All @@ -38,7 +38,7 @@ def graphql_to_gremlin(schema, graphql_query, parameters, type_equivalence_hints
Args:
schema: GraphQL schema object describing the schema of the graph to be queried
graphql_string: the GraphQL query to compile to Gremlin, as a basestring
graphql_string: the GraphQL query to compile to Gremlin, as a string
parameters: dict, mapping argument name to its value, for every parameter the query expects.
type_equivalence_hints: optional dict of GraphQL interface or type -> GraphQL union.
Used as a workaround for Gremlin's lack of inheritance-awareness.
Expand All @@ -57,8 +57,8 @@ def graphql_to_gremlin(schema, graphql_query, parameters, type_equivalence_hints
Returns:
a CompilationResult object, containing:
- query: basestring, the resulting compiled and parameterized query string
- language: basestring, specifying the language to which the query was compiled
- query: string, the resulting compiled and parameterized query string
- language: string, specifying the language to which the query was compiled
- output_metadata: dict, output name -> OutputMetadata namedtuple object
- input_metadata: dict, name of input variables -> inferred GraphQL type, based on use
"""
Expand Down
22 changes: 11 additions & 11 deletions graphql_compiler/compiler/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, start_class):
"""Construct a QueryRoot object that starts querying at the specified class name.
Args:
start_class: set of basestring, class names from which to start the query.
start_class: set of string, class names from which to start the query.
This will generally be a set of length 1, except when using Gremlin
with a non-final class, where we have to include all subclasses
of the start class. This is done using a Gremlin-only IR lowering step.
Expand All @@ -55,7 +55,7 @@ def validate(self):
"""Ensure that the QueryRoot block is valid."""
if not (isinstance(self.start_class, set) and
all(isinstance(x, six.string_types) for x in self.start_class)):
raise TypeError(u'Expected set of basestring start_class, got: {} {}'.format(
raise TypeError(u'Expected set of string start_class, got: {} {}'.format(
type(self.start_class).__name__, self.start_class))

for cls in self.start_class:
Expand All @@ -82,7 +82,7 @@ def __init__(self, target_class):
"""Construct a CoerceType object that filters out any data that is not of the given types.
Args:
target_class: set of basestring, class names from which to start the query.
target_class: set of string, class names from which to start the query.
This will generally be a set of length 1, except when using Gremlin
with a non-final class, where we have to include all subclasses
of the target class. This is done using a Gremlin-only IR lowering step.
Expand All @@ -98,7 +98,7 @@ def validate(self):
"""Ensure that the CoerceType block is valid."""
if not (isinstance(self.target_class, set) and
all(isinstance(x, six.string_types) for x in self.target_class)):
raise TypeError(u'Expected set of basestring target_class, got: {} {}'.format(
raise TypeError(u'Expected set of string target_class, got: {} {}'.format(
type(self.target_class).__name__, self.target_class))

for cls in self.target_class:
Expand All @@ -117,7 +117,7 @@ def __init__(self, fields):
"""Construct a ConstructResult object that maps the given field names to their expressions.
Args:
fields: dict, variable name basestring -> Expression
fields: dict, variable name string -> Expression
see rules for variable names in validate_safe_string().
Returns:
Expand Down Expand Up @@ -239,8 +239,8 @@ def __init__(self, direction, edge_name, optional=False):
"""Create a new Traverse block in the given direction and across the given edge.
Args:
direction: basestring, 'in' or 'out'
edge_name: basestring obeying variable name rules (see validate_safe_string).
direction: string, 'in' or 'out'
edge_name: string obeying variable name rules (see validate_safe_string).
optional: optional bool, specifying whether the traversal to the given location
is optional (i.e. non-filtering) or mandatory (filtering).
Expand All @@ -256,7 +256,7 @@ def __init__(self, direction, edge_name, optional=False):
def validate(self):
"""Ensure that the Traverse block is valid."""
if not isinstance(self.direction, six.string_types):
raise TypeError(u'Expected basestring direction, got: {} {}'.format(
raise TypeError(u'Expected string direction, got: {} {}'.format(
type(self.direction).__name__, self.direction))

if self.direction not in {u'in', u'out'}:
Expand Down Expand Up @@ -304,8 +304,8 @@ def __init__(self, direction, edge_name, depth):
"""Create a new Recurse block which traverses the given edge up to "depth" times.
Args:
direction: basestring, 'in' or 'out'.
edge_name: basestring obeying variable name rules (see validate_safe_string).
direction: string, 'in' or 'out'.
edge_name: string obeying variable name rules (see validate_safe_string).
depth: int, always greater than or equal to 1.
Returns:
Expand All @@ -320,7 +320,7 @@ def __init__(self, direction, edge_name, depth):
def validate(self):
"""Ensure that the Traverse block is valid."""
if not isinstance(self.direction, six.string_types):
raise TypeError(u'Expected basestring direction, got: {} {}'.format(
raise TypeError(u'Expected string direction, got: {} {}'.format(
type(self.direction).__name__, self.direction))

if self.direction not in {u'in', u'out'}:
Expand Down
8 changes: 4 additions & 4 deletions graphql_compiler/compiler/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


# The CompilationResult will have the following types for its members:
# - query: basestring, the resulting compiled query string, with placeholders for parameters
# - language: basestring, specifying the language to which the query was compiled
# - query: string, the resulting compiled query string, with placeholders for parameters
# - language: string, specifying the language to which the query was compiled
# - output_metadata: dict, output name -> OutputMetadata namedtuple object
# - input_metadata: dict, name of input variables -> inferred GraphQL type, based on use
CompilationResult = namedtuple('CompilationResult',
Expand All @@ -22,7 +22,7 @@ def compile_graphql_to_match(schema, graphql_string):
Args:
schema: GraphQL schema object describing the schema of the graph to be queried
graphql_string: the GraphQL query to compile to MATCH, as a basestring
graphql_string: the GraphQL query to compile to MATCH, as a string
Returns:
a CompilationResult object
Expand All @@ -46,7 +46,7 @@ def compile_graphql_to_gremlin(schema, graphql_string, type_equivalence_hints=No
Args:
schema: GraphQL schema object describing the schema of the graph to be queried
graphql_string: the GraphQL query to compile to Gremlin, as a basestring
graphql_string: the GraphQL query to compile to Gremlin, as a string
type_equivalence_hints: optional dict of GraphQL interface or type -> GraphQL union.
Used as a workaround for Gremlin's lack of inheritance-awareness.
When this parameter is not specified or is empty, type coercion
Expand Down
14 changes: 7 additions & 7 deletions graphql_compiler/compiler/compiler_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _get_directives(ast):
ast: GraphQL AST node, obtained from the graphql library
Returns:
dict of basestring to directive object, mapping directive names to their data
dict of string to directive object, mapping directive names to their data
"""
try:
return get_uniquely_named_objects_by_name(ast.directives)
Expand Down Expand Up @@ -652,8 +652,8 @@ def _compile_root_ast_to_ir(schema, ast):
Returns:
tuple of:
- a list of IR basic block objects
- a dict of output name (basestring) -> OutputMetadata object
- a dict of expected input parameters (basestring) -> inferred GraphQL type, based on use
- a dict of output name (string) -> OutputMetadata object
- a dict of expected input parameters (string) -> inferred GraphQL type, based on use
- a dict of location objects -> GraphQL type objects at that location
"""
if len(ast.selection_set.selections) != 1:
Expand Down Expand Up @@ -721,7 +721,7 @@ def _compile_output_step(outputs):
"""Construct the final ConstructResult basic block that defines the output format of the query.
Args:
outputs: dict, output name (basestring) -> output data dict, specifying the location
outputs: dict, output name (string) -> output data dict, specifying the location
from where to get the data, and whether the data is optional (and therefore
may be missing); missing optional data is replaced with 'null'
Expand Down Expand Up @@ -777,13 +777,13 @@ def graphql_to_ir(schema, graphql_string):
Args:
schema: GraphQL schema object, created using the GraphQL library
graphql_string: basestring containing the GraphQL to compile to compiler IR
graphql_string: string containing the GraphQL to compile to compiler IR
Returns:
tuple of:
- a list of IR basic block objects
- a dict of output name (basestring) -> OutputMetadata object
- a dict of expected input parameters (basestring) -> inferred GraphQL type, based on use
- a dict of output name (string) -> OutputMetadata object
- a dict of expected input parameters (string) -> inferred GraphQL type, based on use
- a dict of location objects -> GraphQL type objects at that location
Raises flavors of GraphQLError in the following cases:
Expand Down
4 changes: 2 additions & 2 deletions graphql_compiler/compiler/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __init__(self, variable_name, inferred_type):
"""Construct a new Variable object for the given variable name.
Args:
variable_name: basestring, should start with '$' and then obey variable naming rules
variable_name: string, should start with '$' and then obey variable naming rules
(see validate_safe_string())
inferred_type: GraphQL type object, specifying the inferred type of the variable
Expand Down Expand Up @@ -416,7 +416,7 @@ def __init__(self, root_location, relative_position, field_name, field_type):
root_location: Location, specifying where the @fold was applied.
relative_position: tuple of (edge_direction, edge_name) specifying the field's
enclosing vertex field, relative to the root_location.
field_name: basestring, the name of the field being output.
field_name: string, the name of the field being output.
field_type: GraphQL type object, specifying the type of the field being output.
Since the field is folded, this must be a GraphQLList of some kind.
Expand Down
2 changes: 1 addition & 1 deletion graphql_compiler/compiler/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _represent_argument(schema, ast, context, argument, inferred_type):
uniformity at the moment -- it is currently not used.
context: dict, various per-compilation data (e.g. declared tags, whether the current block
is optional, etc.). May be mutated in-place in this function!
argument: basestring, the name of the argument to the directive
argument: string, the name of the argument to the directive
inferred_type: GraphQL type object specifying the inferred type of the argument
Returns:
Expand Down
14 changes: 7 additions & 7 deletions graphql_compiler/compiler/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def is_graphql_type(graphql_type):


def ensure_unicode_string(value):
"""Ensure the value is a basestring, and return it as unicode."""
"""Ensure the value is a string, and return it as unicode."""
if not isinstance(value, six.string_types):
raise TypeError(u'Expected basestring value, got: {}'.format(value))
raise TypeError(u'Expected string value, got: {}'.format(value))
return six.text_type(value)


Expand Down Expand Up @@ -99,7 +99,7 @@ def validate_safe_string(value):
legal_strings_with_special_chars = frozenset({'@rid', '@class', '@this', '%'})

if not isinstance(value, six.string_types):
raise TypeError(u'Expected basestring value, got: {} {}'.format(
raise TypeError(u'Expected string value, got: {} {}'.format(
type(value).__name__, value))

if not value:
Expand Down Expand Up @@ -145,9 +145,9 @@ def __init__(self, query_path, field=None, visit_counter=1):
should have different 'visit_counter' values.
Args:
query_path: tuple of basestrings, in-order, one for each vertex in the
query_path: tuple of strings, in-order, one for each vertex in the
current nested position in the graph
field: basestring if at a field in a vertex, or None if at a vertex
field: string if at a field in a vertex, or None if at a vertex
visit_counter: int, number that allows semantic disambiguation of otherwise equivalent
Location objects -- see the explanation above.
Expand All @@ -158,7 +158,7 @@ def __init__(self, query_path, field=None, visit_counter=1):
raise TypeError(u'Expected query_path to be a tuple, was: '
u'{} {}'.format(type(query_path).__name__, query_path))
if field and not isinstance(field, six.string_types):
raise TypeError(u'Expected field to be None or basestring, was: '
raise TypeError(u'Expected field to be None or string, was: '
u'{} {}'.format(type(field).__name__, field))

self.query_path = query_path
Expand All @@ -185,7 +185,7 @@ def at_vertex(self):
def navigate_to_subpath(self, child):
"""Return a new Location object at a child vertex of the current Location's vertex."""
if not isinstance(child, six.string_types):
raise TypeError(u'Expected child to be a basestring, was: {}'.format(child))
raise TypeError(u'Expected child to be a string, was: {}'.format(child))
if self.field:
raise AssertionError(u'Currently at a field, cannot go to child: {}'.format(self))
return Location(self.query_path + (child,))
Expand Down
2 changes: 1 addition & 1 deletion graphql_compiler/query_formatting/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def insert_arguments_into_query(compilation_result, arguments):
arguments: dict, mapping argument name to its value, for every parameter the query expects.
Returns:
basestring, a query in the appropriate output language, with inserted argument data
string, a query in the appropriate output language, with inserted argument data
"""
_ensure_arguments_are_provided(compilation_result.input_metadata, arguments)

Expand Down
2 changes: 1 addition & 1 deletion graphql_compiler/query_formatting/gremlin_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def insert_arguments_into_gremlin_query(compilation_result, arguments):
arguments: dict, mapping argument name to its value, for every parameter the query expects.
Returns:
basestring, a Gremlin query with inserted argument data
string, a Gremlin query with inserted argument data
"""
if compilation_result.language != GREMLIN_LANGUAGE:
raise AssertionError(u'Unexpected query output language: {}'.format(compilation_result))
Expand Down
2 changes: 1 addition & 1 deletion graphql_compiler/query_formatting/match_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def insert_arguments_into_match_query(compilation_result, arguments):
arguments: dict, mapping argument name to its value, for every parameter the query expects.
Returns:
basestring, a MATCH query with inserted argument data
string, a MATCH query with inserted argument data
"""
if compilation_result.language != MATCH_LANGUAGE:
raise AssertionError(u'Unexpected query output language: {}'.format(compilation_result))
Expand Down
2 changes: 1 addition & 1 deletion graphql_compiler/tests/test_ir_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def check_test_data(test_case, graphql_input, expected_blocks,


def comparable_location_types(location_types):
"""Convert the dict of Location -> GraphQL object type into a dict of Location -> basestring."""
"""Convert the dict of Location -> GraphQL object type into a dict of Location -> string."""
return {
location: graphql_type.name
for location, graphql_type in six.iteritems(location_types)
Expand Down

0 comments on commit 0619dca

Please sign in to comment.