Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

Commit d420f71

Browse files
chewseleneSelene Chew
andauthored
Use inclusive language [removing sanity check] (#984)
* use inclusive language * use self-consistency check * fix typo * add typehint * lint * update mypy.ini * tighten mypy.ini * use assert for internal functions Co-authored-by: Selene Chew <[email protected]>
1 parent d35124a commit d420f71

File tree

15 files changed

+80
-61
lines changed

15 files changed

+80
-61
lines changed

graphql_compiler/compiler/compiler_frontend.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,9 @@ def _compile_vertex_ast(
543543
# Invariant: There must always be a marked location corresponding to the query position
544544
# immediately before any optional Traverse.
545545
#
546-
# This invariant is verified in the IR sanity checks module (ir_sanity_checks.py),
547-
# in the function named _sanity_check_mark_location_preceding_optional_traverse().
546+
# This invariant is verified in the IR self-consistency check module
547+
# (ir_self_consistency_checks.py), in the function named
548+
# _assert_mark_location_preceding_optional_traverse().
548549
#
549550
# This marked location is the one that the @optional directive's corresponding
550551
# optional Backtrack will jump back to. If such a marked location isn't present,
@@ -779,13 +780,13 @@ def _compile_ast_node_to_ir(schema, current_schema_type, ast, location, context)
779780
)
780781

781782
if location.field is not None: # we're at a property field
782-
# sanity-check: cannot have an inline fragment at a property field
783+
# self-consistency check: cannot have an inline fragment at a property field
783784
if fragment_exists:
784785
raise AssertionError(
785786
"Found inline fragment at a property field: {} {}".format(location, fragment)
786787
)
787788

788-
# sanity-check: locations at properties don't have their own property locations
789+
# self-consistency check: locations at properties don't have their own property locations
789790
if len(property_fields) > 0:
790791
raise AssertionError(
791792
"Found property fields on a property field: "

graphql_compiler/compiler/cypher_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def _generate_cypher_step_list_from_ir_blocks(fold_scope_location, ir_blocks, qu
154154
linked_location = block.location
155155
current_step_ir_blocks = []
156156
for block in current_step_ir_blocks:
157-
# Sanity check any leftover blocks.
157+
# Self-consistency check any leftover blocks.
158158
# The complete list of IR blocks need not end with a MarkLocation block, e.g. if you
159159
# have a Backtrack block at the end. That's fine; Backtrack is unused here anyways.
160160
# What we want to avoid is having any leftover blocks here that we should've used.

graphql_compiler/compiler/ir_lowering_cypher/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
merge_consecutive_filter_clauses,
66
optimize_boolean_expression_comparisons,
77
)
8-
from ..ir_sanity_checks import sanity_check_ir_blocks_from_frontend
8+
from ..ir_self_consistency_checks import self_consistency_check_ir_blocks_from_frontend
99
from .ir_lowering import (
1010
insert_explicit_type_bounds,
1111
move_filters_in_optional_locations_to_global_operations,
@@ -30,7 +30,7 @@ def lower_ir(schema_info, ir):
3030
Returns:
3131
CypherQuery object
3232
"""
33-
sanity_check_ir_blocks_from_frontend(ir.ir_blocks, ir.query_metadata_table)
33+
self_consistency_check_ir_blocks_from_frontend(ir.ir_blocks, ir.query_metadata_table)
3434

3535
ir_blocks = insert_explicit_type_bounds(
3636
ir.ir_blocks,

graphql_compiler/compiler/ir_lowering_gremlin/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
merge_consecutive_filter_clauses,
55
optimize_boolean_expression_comparisons,
66
)
7-
from ..ir_sanity_checks import sanity_check_ir_blocks_from_frontend
7+
from ..ir_self_consistency_checks import self_consistency_check_ir_blocks_from_frontend
88
from .ir_lowering import (
99
lower_coerce_type_block_type_data,
1010
lower_coerce_type_blocks,
@@ -28,7 +28,7 @@ def lower_ir(schema_info, ir):
2828
Returns:
2929
list of IR blocks suitable for outputting as Gremlin
3030
"""
31-
sanity_check_ir_blocks_from_frontend(ir.ir_blocks, ir.query_metadata_table)
31+
self_consistency_check_ir_blocks_from_frontend(ir.ir_blocks, ir.query_metadata_table)
3232

3333
ir_blocks = lower_context_field_existence(ir.ir_blocks, ir.query_metadata_table)
3434
ir_blocks = optimize_boolean_expression_comparisons(ir_blocks)

graphql_compiler/compiler/ir_lowering_match/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
optimize_boolean_expression_comparisons,
1313
remove_end_optionals,
1414
)
15-
from ..ir_sanity_checks import sanity_check_ir_blocks_from_frontend
15+
from ..ir_self_consistency_checks import self_consistency_check_ir_blocks_from_frontend
1616
from ..match_query import MatchQuery, convert_to_match_query
1717
from ..workarounds import (
1818
orientdb_class_with_while,
@@ -53,7 +53,7 @@ def lower_ir(schema_info: CommonSchemaInfo, ir: IrAndMetadata) -> MatchQuery:
5353
Returns:
5454
MatchQuery object containing the IR blocks organized in a MATCH-like structure
5555
"""
56-
sanity_check_ir_blocks_from_frontend(ir.ir_blocks, ir.query_metadata_table)
56+
self_consistency_check_ir_blocks_from_frontend(ir.ir_blocks, ir.query_metadata_table)
5757

5858
# Construct the mapping of each location to its corresponding GraphQL type.
5959
location_types = {

graphql_compiler/compiler/ir_sanity_checks.py renamed to graphql_compiler/compiler/ir_self_consistency_checks.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
from .metadata import QueryMetadataTable
2424

2525

26-
def sanity_check_ir_blocks_from_frontend(
26+
def self_consistency_check_ir_blocks_from_frontend(
2727
ir_blocks: List[BasicBlock], query_metadata_table: QueryMetadataTable
2828
) -> None:
2929
"""Assert that IR blocks originating from the frontend do not have nonsensical structure.
3030
3131
Args:
32-
ir_blocks: list of BasicBlocks representing the IR to sanity-check
33-
query_metadata_table: QueryMetadataTable object that captures information about the query
32+
ir_blocks: list of BasicBlocks representing the IR to self-consistency check.
33+
query_metadata_table: QueryMetadataTable object that captures information about the query.
3434
3535
Raises:
3636
AssertionError, if the IR has unexpected structure. If the IR produced by the front-end
@@ -40,19 +40,19 @@ def sanity_check_ir_blocks_from_frontend(
4040
if not ir_blocks:
4141
raise AssertionError("Received no ir_blocks: {}".format(ir_blocks))
4242

43-
_sanity_check_fold_scope_locations_are_unique(ir_blocks)
44-
_sanity_check_no_nested_folds(ir_blocks)
45-
_sanity_check_query_root_block(ir_blocks)
46-
_sanity_check_output_source_follower_blocks(ir_blocks)
47-
_sanity_check_block_pairwise_constraints(ir_blocks)
48-
_sanity_check_mark_location_preceding_optional_traverse(ir_blocks)
49-
_sanity_check_every_location_is_marked(ir_blocks)
50-
_sanity_check_coerce_type_outside_of_fold(ir_blocks)
51-
_sanity_check_all_marked_locations_are_registered(ir_blocks, query_metadata_table)
52-
_sanity_check_registered_locations_parent_locations(query_metadata_table)
43+
_assert_fold_scope_locations_are_unique(ir_blocks)
44+
_assert_no_nested_folds(ir_blocks)
45+
_assert_query_root_block(ir_blocks)
46+
_assert_output_source_follower_blocks(ir_blocks)
47+
_assert_block_pairwise_constraints(ir_blocks)
48+
_assert_mark_location_preceding_optional_traverse(ir_blocks)
49+
_assert_every_location_is_marked(ir_blocks)
50+
_assert_coerce_type_outside_of_fold(ir_blocks)
51+
_assert_all_marked_locations_are_registered(ir_blocks, query_metadata_table)
52+
_assert_registered_locations_parent_locations(query_metadata_table)
5353

5454

55-
def _sanity_check_registered_locations_parent_locations(
55+
def _assert_registered_locations_parent_locations(
5656
query_metadata_table: QueryMetadataTable,
5757
) -> None:
5858
"""Assert that all registered locations' parent locations are also registered."""
@@ -76,7 +76,7 @@ def _sanity_check_registered_locations_parent_locations(
7676
query_metadata_table.get_location_info(location_info.parent_location)
7777

7878

79-
def _sanity_check_all_marked_locations_are_registered(
79+
def _assert_all_marked_locations_are_registered(
8080
ir_blocks: List[BasicBlock], query_metadata_table: QueryMetadataTable
8181
) -> None:
8282
"""Assert that all locations in MarkLocation blocks have registered and valid metadata."""
@@ -103,7 +103,7 @@ def _sanity_check_all_marked_locations_are_registered(
103103
)
104104

105105

106-
def _sanity_check_fold_scope_locations_are_unique(ir_blocks: List[BasicBlock]) -> None:
106+
def _assert_fold_scope_locations_are_unique(ir_blocks: List[BasicBlock]) -> None:
107107
"""Assert that every FoldScopeLocation that exists on a Fold block is unique."""
108108
observed_locations: Dict[FoldScopeLocation, Fold] = dict()
109109
for block in ir_blocks:
@@ -117,7 +117,7 @@ def _sanity_check_fold_scope_locations_are_unique(ir_blocks: List[BasicBlock]) -
117117
observed_locations[block.fold_scope_location] = block
118118

119119

120-
def _sanity_check_no_nested_folds(ir_blocks: List[BasicBlock]) -> None:
120+
def _assert_no_nested_folds(ir_blocks: List[BasicBlock]) -> None:
121121
"""Assert that there are no nested Fold contexts, and that every Fold has a matching Unfold."""
122122
fold_seen = False
123123
for block in ir_blocks:
@@ -135,7 +135,7 @@ def _sanity_check_no_nested_folds(ir_blocks: List[BasicBlock]) -> None:
135135
fold_seen = False
136136

137137

138-
def _sanity_check_query_root_block(ir_blocks: List[BasicBlock]) -> None:
138+
def _assert_query_root_block(ir_blocks: List[BasicBlock]) -> None:
139139
"""Assert that QueryRoot is always the first block, and only the first block."""
140140
if not isinstance(ir_blocks[0], QueryRoot):
141141
raise AssertionError("The first block was not QueryRoot: {}".format(ir_blocks))
@@ -144,7 +144,7 @@ def _sanity_check_query_root_block(ir_blocks: List[BasicBlock]) -> None:
144144
raise AssertionError("Found QueryRoot after the first block: {}".format(ir_blocks))
145145

146146

147-
def _sanity_check_construct_result_block(ir_blocks: List[BasicBlock]) -> None:
147+
def _self_consistency_check_construct_result_block(ir_blocks: List[BasicBlock]) -> None:
148148
"""Assert that ConstructResult is always the last block, and only the last block."""
149149
if not isinstance(ir_blocks[-1], ConstructResult):
150150
raise AssertionError("The last block was not ConstructResult: {}".format(ir_blocks))
@@ -155,7 +155,7 @@ def _sanity_check_construct_result_block(ir_blocks: List[BasicBlock]) -> None:
155155
)
156156

157157

158-
def _sanity_check_output_source_follower_blocks(ir_blocks: List[BasicBlock]) -> None:
158+
def _assert_output_source_follower_blocks(ir_blocks: List[BasicBlock]) -> None:
159159
"""Ensure there are no Traverse / Backtrack / Recurse blocks after an OutputSource block."""
160160
seen_output_source = False
161161
for block in ir_blocks:
@@ -170,7 +170,7 @@ def _sanity_check_output_source_follower_blocks(ir_blocks: List[BasicBlock]) ->
170170
)
171171

172172

173-
def _sanity_check_block_pairwise_constraints(ir_blocks: List[BasicBlock]) -> None:
173+
def _assert_block_pairwise_constraints(ir_blocks: List[BasicBlock]) -> None:
174174
"""Assert that adjacent blocks obey all invariants."""
175175
for first_block, second_block in pairwise(ir_blocks):
176176
# Always Filter before MarkLocation, never after.
@@ -207,7 +207,9 @@ def _sanity_check_block_pairwise_constraints(ir_blocks: List[BasicBlock]) -> Non
207207
)
208208

209209

210-
def _sanity_check_mark_location_preceding_optional_traverse(ir_blocks: List[BasicBlock]) -> None:
210+
def _assert_mark_location_preceding_optional_traverse(
211+
ir_blocks: List[BasicBlock],
212+
) -> None:
211213
"""Assert that optional Traverse blocks are preceded by a MarkLocation."""
212214
# Once all fold blocks are removed, each optional Traverse must have
213215
# a MarkLocation block immediately before it.
@@ -222,7 +224,7 @@ def _sanity_check_mark_location_preceding_optional_traverse(ir_blocks: List[Basi
222224
)
223225

224226

225-
def _sanity_check_every_location_is_marked(ir_blocks: List[BasicBlock]) -> None:
227+
def _assert_every_location_is_marked(ir_blocks: List[BasicBlock]) -> None:
226228
"""Ensure that every new location is marked with a MarkLocation block."""
227229
# Exactly one MarkLocation block is found between any block that starts an interval of blocks
228230
# that all affect the same query position, and the first subsequent block that affects a
@@ -255,7 +257,7 @@ def _sanity_check_every_location_is_marked(ir_blocks: List[BasicBlock]) -> None:
255257
mark_location_blocks_count = 0
256258

257259

258-
def _sanity_check_coerce_type_outside_of_fold(ir_blocks: List[BasicBlock]):
260+
def _assert_coerce_type_outside_of_fold(ir_blocks: List[BasicBlock]) -> None:
259261
"""Ensure that CoerceType not in a @fold are followed by a MarkLocation or Filter block."""
260262
is_in_fold = False
261263
for first_block, second_block in pairwise(ir_blocks):

graphql_compiler/cost_estimation/statistics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class name) to count of edge instances of given class
174174
TODO(bojanserafimov): Enforce a canonical representation for quantile values and
175175
sampling summaries. Datetimes should be in utc, decimals should
176176
have type float, etc.
177-
TODO(bojanserafimov): Sanity-check class_counts against sample_ratio * num_samples
177+
TODO(bojanserafimov): Validate class_counts against sample_ratio * num_samples
178178
"""
179179
if vertex_edge_vertex_counts is None:
180180
vertex_edge_vertex_counts = dict()

graphql_compiler/schema_generation/graphql_schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ def get_graphql_schema_from_schema_graph(
331331
)
332332

333333
# N.B.: Ignore the "is_type_of" argument below, it is simply a circumvention of
334-
# a sanity check inside the GraphQL library. The library assumes that we'll use
335-
# its execution system, so it complains that we don't provide a means to
334+
# a validation check inside the GraphQL library. The library assumes that we'll
335+
# use its execution system, so it complains that we don't provide a means to
336336
# differentiate between different implementations of the same interface.
337337
# We don't care, because we compile the GraphQL query to a database query.
338338
current_graphql_type = GraphQLObjectType(

graphql_compiler/schema_generation/orientdb/schema_graph_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def _get_class_fields(class_definition):
299299
class_fields = class_definition.get("customFields")
300300
if class_fields is None:
301301
# OrientDB likes to make empty collections be None instead.
302-
# We convert this field back to an empty dict, for our general sanity.
302+
# We convert this field back to an empty dict, for our general happiness.
303303
class_fields = dict()
304304
return class_fields
305305

graphql_compiler/schema_generation/sqlalchemy/sqlalchemy_reflector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def fast_sql_server_reflect(engine, metadata, schema, primary_key_selector=None)
3939
database_name, schema_name = schema.split(".")
4040

4141
name_pattern = re.compile(r"^[a-zA-Z][_\-a-zA-Z0-9]*")
42-
# Sanity check to prevent against SQL injection.
42+
# Check to prevent against SQL injection.
4343
if not name_pattern.match(database_name):
4444
raise AssertionError("Invalid database name {}".format(database_name))
4545
if not name_pattern.match(schema_name):

0 commit comments

Comments
 (0)