Skip to content

Commit 7b27aa5

Browse files
authored
More fixes for ReST rendering in docstrings (#87)
1 parent 555a266 commit 7b27aa5

20 files changed

+87
-75
lines changed

docs/usage/extension.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ follows::
1717
"""))
1818

1919
Note that this function expects the extensions as an AST, which we can get using the
20-
:func:`graphql.language.parse` function. Also note that the `extend_schema` function
20+
:func:`graphql.language.parse` function. Also note that the :func:`~graphql.extend_schema` function
2121
does not alter the original schema, but returns a new schema object.
2222

2323
We also need to attach a resolver function to the new field::

src/graphql/execution/execute.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@
9797
class ExecutionResult(NamedTuple):
9898
"""The result of GraphQL execution.
9999
100-
- `data` is the result of a successful execution of the query.
101-
- `errors` is included when any errors occurred as a non-empty list.
100+
- ``data`` is the result of a successful execution of the query.
101+
- ``errors`` is included when any errors occurred as a non-empty list.
102102
"""
103103

104104
data: Optional[Dict[str, Any]]
@@ -678,7 +678,8 @@ def complete_value(
678678
inner type on each item in the list.
679679
680680
If the field type is a Scalar or Enum, ensures the completed value is a legal
681-
value of the type by calling the `serialize` method of GraphQL type definition.
681+
value of the type by calling the ``serialize`` method of GraphQL type
682+
definition.
682683
683684
If the field is an abstract type, determine the runtime type of the value and
684685
then complete based on that type.
@@ -948,7 +949,7 @@ def collect_subfields(
948949
"""Collect subfields.
949950
950951
A cached collection of relevant subfields with regard to the return type is
951-
kept in the execution context as `_subfields_cache`. This ensures the
952+
kept in the execution context as ``_subfields_cache``. This ensures the
952953
subfields are not repeatedly calculated, which saves overhead when resolving
953954
lists of values.
954955
"""
@@ -1065,9 +1066,9 @@ def get_field_def(
10651066
"""Get field definition.
10661067
10671068
This method looks up the field on the given type definition. It has special casing
1068-
for the two introspection fields, `__schema` and `__typename`. `__typename` is
1069+
for the two introspection fields, ``__schema`` and ``__typename``. ``__typename`` is
10691070
special because it can always be queried as a field, even in situations where no
1070-
other fields are allowed, like on a Union. `__schema` could get automatically
1071+
other fields are allowed, like on a Union. ``__schema`` could get automatically
10711072
added to the query type, but that would require mutating type definitions, which
10721073
would cause issues.
10731074
@@ -1098,7 +1099,7 @@ def invalid_return_type_error(
10981099

10991100

11001101
def get_typename(value: Any) -> Optional[str]:
1101-
"""Get the `__typename` property of the given value."""
1102+
"""Get the ``__typename`` property of the given value."""
11021103
if isinstance(value, dict):
11031104
return value.get("__typename")
11041105
# need to de-mangle the attribute assumed to be "private" in Python
@@ -1117,11 +1118,12 @@ def default_type_resolver(
11171118
If a resolve_type function is not given, then a default resolve behavior is used
11181119
which attempts two strategies:
11191120
1120-
First, See if the provided value has a `__typename` field defined, if so, use that
1121+
First, See if the provided value has a ``__typename`` field defined, if so, use that
11211122
value as name of the resolved type.
11221123
1123-
Otherwise, test each possible type for the abstract type by calling `is_type_of`
1124-
for the object being coerced, returning the first type that matches.
1124+
Otherwise, test each possible type for the abstract type by calling
1125+
:meth:`~graphql.type.GraphQLObjectType.is_type_of` for the object
1126+
being coerced, returning the first type that matches.
11251127
"""
11261128
# First, look for `__typename`.
11271129
type_name = get_typename(value)

src/graphql/execution/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class MiddlewareManager:
1313
1414
This class helps to wrap resolver functions with the provided middleware functions
1515
and/or objects. The functions take the next middleware function as first argument.
16-
If middleware is provided as an object, it must provide a method `resolve` that is
16+
If middleware is provided as an object, it must provide a method ``resolve`` that is
1717
used as the middleware function.
1818
1919
Note that since resolvers return "AwaitableOrValue"s, all middleware functions

src/graphql/graphql.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ async def graphql(
6565
:arg type_resolver:
6666
A type resolver function to use when none is provided by the schema.
6767
If not provided, the default type resolver is used (which looks for a
68-
`__typename` field or alternatively calls the `is_type_of` method).
68+
``__typename`` field or alternatively calls the
69+
:meth:`~graphql.type.GraphQLObjectType.is_type_of` method).
6970
:arg middleware:
7071
The middleware to wrap the resolvers with
7172
:arg execution_context_class:

src/graphql/language/parser.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,16 @@ def parse(
7777
Throws GraphQLError if a syntax error is encountered.
7878
7979
By default, the parser creates AST nodes that know the location in the source that
80-
they correspond to. The `no_location` option disables that behavior for performance
81-
or testing.
80+
they correspond to. The ``no_location`` option disables that behavior for
81+
performance or testing.
8282
8383
Experimental features:
8484
85-
If `experimental_fragment_variables` is set to True, the parser will understand
86-
and parse variable definitions contained in a fragment definition. They'll be
87-
represented in the `variable_definitions` field of the `FragmentDefinitionNode`.
85+
If ``experimental_fragment_variables`` is set to ``True``, the parser will
86+
understand and parse variable definitions contained in a fragment definition.
87+
They'll be represented in the
88+
:attr:`~graphql.language.FragmentDefinitionNode.variable_definitions` field
89+
of the :class:`~graphql.language.FragmentDefinitionNode`.
8890
8991
The syntax is identical to normal, query-defined variables. For example::
9092
@@ -110,7 +112,8 @@ def parse_value(
110112
This is useful within tools that operate upon GraphQL Values directly and in
111113
isolation of complete GraphQL documents.
112114
113-
Consider providing the results to the utility function: `value_from_ast()`.
115+
Consider providing the results to the utility function:
116+
:func:`~graphql.value_from_ast`.
114117
"""
115118
parser = Parser(
116119
source,
@@ -133,7 +136,8 @@ def parse_type(
133136
This is useful within tools that operate upon GraphQL Types directly and
134137
in isolation of complete GraphQL documents.
135138
136-
Consider providing the results to the utility function: `type_from_ast()`.
139+
Consider providing the results to the utility function:
140+
:func:`~graphql.value_from_ast`.
137141
"""
138142
parser = Parser(
139143
source,
@@ -390,7 +394,7 @@ def parse_fragment_definition(self) -> FragmentDefinitionNode:
390394
)
391395

392396
def parse_fragment_name(self) -> NameNode:
393-
"""FragmentName: Name but not `on`"""
397+
"""FragmentName: Name but not ``on``"""
394398
if self._lexer.token.value == "on":
395399
raise self.unexpected()
396400
return self.parse_name()
@@ -1042,9 +1046,10 @@ def any(
10421046
) -> List[T]:
10431047
"""Fetch any matching nodes, possibly none.
10441048
1045-
Returns a possibly empty list of parse nodes, determined by the `parse_fn`.
1046-
This list begins with a lex token of `open_kind` and ends with a lex token of
1047-
`close_kind`. Advances the parser to the next lex token after the closing token.
1049+
Returns a possibly empty list of parse nodes, determined by the ``parse_fn``.
1050+
This list begins with a lex token of ``open_kind`` and ends with a lex token of
1051+
``close_kind``. Advances the parser to the next lex token after the closing
1052+
token.
10481053
"""
10491054
self.expect_token(open_kind)
10501055
nodes: List[T] = []
@@ -1058,10 +1063,11 @@ def optional_many(
10581063
) -> List[T]:
10591064
"""Fetch matching nodes, maybe none.
10601065
1061-
Returns a list of parse nodes, determined by the `parse_fn`. It can be empty
1066+
Returns a list of parse nodes, determined by the ``parse_fn``. It can be empty
10621067
only if the open token is missing, otherwise it will always return a non-empty
1063-
list that begins with a lex token of `open_kind` and ends with a lex token of
1064-
`close_kind`. Advances the parser to the next lex token after the closing token.
1068+
list that begins with a lex token of ``open_kind`` and ends with a lex token of
1069+
``close_kind``. Advances the parser to the next lex token after the closing
1070+
token.
10651071
"""
10661072
if self.expect_optional_token(open_kind):
10671073
nodes = [parse_fn()]
@@ -1076,9 +1082,10 @@ def many(
10761082
) -> List[T]:
10771083
"""Fetch matching nodes, at least one.
10781084
1079-
Returns a non-empty list of parse nodes, determined by the `parse_fn`.
1080-
This list begins with a lex token of `open_kind` and ends with a lex token of
1081-
`close_kind`. Advances the parser to the next lex token after the closing token.
1085+
Returns a non-empty list of parse nodes, determined by the ``parse_fn``.
1086+
This list begins with a lex token of ``open_kind`` and ends with a lex token of
1087+
``close_kind``. Advances the parser to the next lex token after the closing
1088+
token.
10821089
"""
10831090
self.expect_token(open_kind)
10841091
nodes = [parse_fn()]

src/graphql/language/source.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def __init__(
1818
"""Initialize source input.
1919
2020
21-
`name` and `location_offset` are optional. They are useful for clients who
21+
``name`` and ``location_offset`` are optional. They are useful for clients who
2222
store GraphQL documents in source files; for example, if the GraphQL input
2323
starts at line 40 in a file named Foo.graphql, it might be useful for name
24-
to be "Foo.graphql" and location to be `(40, 0)`.
24+
to be "Foo.graphql" and location to be ``(40, 0)``.
2525
2626
line and column in location_offset are 1-indexed
2727
"""

src/graphql/language/visitor.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ def enter(self, node, key, parent, path, ancestors):
142142
:arg parent: the parent immediately above this node, which may be an Array.
143143
:arg path: The key path to get to this node from the root node.
144144
:arg ancestors: All nodes and Arrays visited before reaching parent
145-
of this node. These correspond to array indices in `path`.
145+
of this node. These correspond to array indices in ``path``.
146146
Note: ancestors includes arrays which contain the parent of visited node.
147147
148148
You can also define node kind specific methods by suffixing them with an underscore
149-
followed by the kind of the node to be visited. For instance, to visit `field`
150-
nodes, you would defined the methods `enter_field()` and/or `leave_field()`, with
151-
the same signature as above. If no kind specific method has been defined for a given
152-
node, the generic method is called.
149+
followed by the kind of the node to be visited. For instance, to visit ``field``
150+
nodes, you would defined the methods ``enter_field()`` and/or ``leave_field()``,
151+
with the same signature as above. If no kind specific method has been defined
152+
for a given node, the generic method is called.
153153
"""
154154

155155
# Provide special return values as attributes
@@ -200,18 +200,18 @@ class Stack(NamedTuple):
200200
def visit(root: Node, visitor: Visitor, visitor_keys=None) -> Any:
201201
"""Visit each node in an AST.
202202
203-
`visit()` will walk through an AST using a depth first traversal, calling the
203+
:func:`~.visit` will walk through an AST using a depth first traversal, calling the
204204
visitor's enter methods at each node in the traversal, and calling the leave methods
205205
after visiting that node and all of its child nodes.
206206
207207
By returning different values from the enter and leave methods, the behavior of the
208208
visitor can be altered, including skipping over a sub-tree of the AST (by returning
209209
False), editing the AST by returning a value or None to remove the value, or to stop
210-
the whole traversal by returning `BREAK`.
210+
the whole traversal by returning :data:`~.BREAK`.
211211
212-
When using `visit()` to edit an AST, the original AST will not be modified, and a
213-
new version of the AST with the changes applied will be returned from the visit
214-
function.
212+
When using :func:`~.visit` to edit an AST, the original AST will not be modified,
213+
and a new version of the AST with the changes applied will be returned from the
214+
visit function.
215215
216216
To customize the node attributes to be used for traversal, you can provide a
217217
dictionary visitor_keys mapping node kinds to node attributes.

src/graphql/subscription/subscribe.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async def subscribe(
5151
5252
If the source stream could not be created due to faulty subscription resolver logic
5353
or underlying systems, the coroutine object will yield a single ExecutionResult
54-
containing `errors` and no `data`.
54+
containing ``errors`` and no ``data``.
5555
5656
If the operation succeeded, the coroutine will yield an AsyncIterator, which yields
5757
a stream of ExecutionResults representing the response stream.
@@ -75,11 +75,11 @@ async def map_source_to_response(payload) -> ExecutionResult:
7575
"""Map source to response.
7676
7777
For each payload yielded from a subscription, map it over the normal GraphQL
78-
`execute` function, with `payload` as the `root_value`. This implements the
79-
"MapSourceToResponseEvent" algorithm described in the GraphQL specification.
80-
The `execute` function provides the "ExecuteSubscriptionEvent" algorithm,
81-
as it is nearly identical to the "ExecuteQuery" algorithm, for which `execute`
82-
is also used.
78+
:func:`~graphql.execute` function, with ``payload`` as the ``root_value``.
79+
This implements the "MapSourceToResponseEvent" algorithm described in the
80+
GraphQL specification. The :func:`~graphql.execute` function provides the
81+
"ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
82+
"ExecuteQuery" algorithm, for which :func:`~graphql.execute` is also used.
8383
"""
8484
result = execute(
8585
schema,

src/graphql/type/definition.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class GraphQLScalarType(GraphQLNamedType):
306306
and are defined with a name and a series of functions used to parse input from ast
307307
or variables and to ensure validity.
308308
309-
If a type's serialize function does not return a value (i.e. it returns `None`),
309+
If a type's serialize function does not return a value (i.e. it returns ``None``),
310310
then no error will be included in the response.
311311
312312
Example::
@@ -1245,7 +1245,7 @@ class GraphQLInputObjectType(GraphQLNamedType):
12451245
An input object defines a structured collection of fields which may be supplied
12461246
to a field argument.
12471247
1248-
Using `NonNull` will ensure that a value must be provided by the query.
1248+
Using ``NonNull`` will ensure that a value must be provided by the query.
12491249
12501250
Example::
12511251
@@ -1261,7 +1261,7 @@ class GeoPoint(GraphQLInputObjectType):
12611261
}
12621262
12631263
The outbound values will be Python dictionaries by default, but you can have them
1264-
converted to other types by specifying an `out_type` function or class.
1264+
converted to other types by specifying an ``out_type`` function or class.
12651265
"""
12661266

12671267
ast_node: Optional[InputObjectTypeDefinitionNode]

src/graphql/type/schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ class GraphQLSchema:
7878
# you want them to be included in the final schema.
7979
types=[human_type, droid_type])
8080
81-
Note: If a list of `directives` is provided to GraphQLSchema, that will be the
82-
exact list of directives represented and allowed. If `directives` is not provided,
81+
Note: If a list of ``directives`` is provided to GraphQLSchema, that will be the
82+
exact list of directives represented and allowed. If ``directives`` is not provided,
8383
then a default set of the specified directives (e.g. @include and @skip) will be
8484
used. If you wish to provide *additional* directives to these specified directives,
8585
you must explicitly declare them. Example::
@@ -119,7 +119,7 @@ def __init__(
119119
"""Initialize GraphQL schema.
120120
121121
If this schema was built from a source known to be valid, then it may be marked
122-
with `assume_valid` to avoid an additional type system validation.
122+
with ``assume_valid`` to avoid an additional type system validation.
123123
"""
124124
self._validation_errors = [] if assume_valid else None
125125

src/graphql/utilities/build_ast_schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def build_ast_schema(
3636
resolve methods, so execution will use default resolvers.
3737
3838
When building a schema from a GraphQL service's introspection result, it might
39-
be safe to assume the schema is valid. Set `assume_valid` to True to assume the
40-
produced schema is valid. Set `assume_valid_sdl` to True to assume it is already
41-
a valid SDL document.
39+
be safe to assume the schema is valid. Set ``assume_valid`` to ``True`` to assume
40+
the produced schema is valid. Set ``assume_valid_sdl`` to ``True`` to assume it is
41+
already a valid SDL document.
4242
"""
4343
if not isinstance(document_ast, DocumentNode):
4444
raise TypeError("Must provide valid Document AST.")

src/graphql/utilities/extend_schema.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ def extend_schema(
108108
copy. The original schema remains unaltered.
109109
110110
When extending a schema with a known valid extension, it might be safe to assume the
111-
schema is valid. Set `assume_valid` to true to assume the produced schema is valid.
112-
Set `assume_valid_sdl` to True to assume it is already a valid SDL document.
111+
schema is valid. Set ``assume_valid`` to ``True`` to assume the produced schema is
112+
valid. Set ``assume_valid_sdl`` to ``True`` to assume it is already a valid SDL
113+
document.
113114
"""
114115
assert_schema(schema)
115116

src/graphql/utilities/type_from_ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def type_from_ast(schema, type_node):
4444
4545
Given a Schema and an AST node describing a type, return a GraphQLType definition
4646
which applies to that type. For example, if provided the parsed AST node for
47-
`[User]`, a GraphQLList instance will be returned, containing the type called
47+
``[User]``, a GraphQLList instance will be returned, containing the type called
4848
"User" found in the schema. If a type called "User" is not found in the schema,
4949
then None will be returned.
5050
"""

src/graphql/utilities/type_info.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class TypeInfo:
5656
5757
TypeInfo is a utility class which, given a GraphQL schema, can keep track of the
5858
current field and type definitions at any point in a GraphQL document AST during
59-
a recursive descent by calling `enter(node)` and `leave(node)`.
59+
a recursive descent by calling :meth:`enter(node) <.TypeInfo.enter>` and
60+
:meth:`leave(node) <.TypeInfo.leave>`.
6061
"""
6162

6263
def __init__(
@@ -262,9 +263,9 @@ def get_field_def(
262263
) -> Optional[GraphQLField]:
263264
"""Get field definition.
264265
265-
Not exactly the same as the executor's definition of `get_field_def()`, in this
266-
statically evaluated environment we do not always have an Object type, and need
267-
to handle Interface and Union types.
266+
Not exactly the same as the executor's definition of
267+
:func:`graphql.execution.get_field_def`, in this statically evaluated environment
268+
we do not always have an Object type, and need to handle Interface and Union types.
268269
"""
269270
name = field_node.name.value
270271
if name == "__schema" and schema.query_type is parent_type:

src/graphql/utilities/value_from_ast.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def value_from_ast(
3333
A GraphQL type must be provided, which will be used to interpret different GraphQL
3434
Value literals.
3535
36-
Returns `Undefined` when the value could not be validly coerced according
36+
Returns ``Undefined`` when the value could not be validly coerced according
3737
to the provided type.
3838
3939
=================== ============== ================
@@ -143,7 +143,7 @@ def value_from_ast(
143143
def is_missing_variable(
144144
value_node: ValueNode, variables: Optional[Dict[str, Any]] = None
145145
) -> bool:
146-
"""Check if `value_node` is a variable not defined in the `variables` dict."""
146+
"""Check if ``value_node`` is a variable not defined in the ``variables`` dict."""
147147
return isinstance(value_node, VariableNode) and (
148148
not variables or variables.get(value_node.name.value, Undefined) is Undefined
149149
)

0 commit comments

Comments
 (0)