All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
Follow up from #1325
Adds docstrings to the fmt checking functions.
Renames fmt_on to is_fmt_on.
Adds the functions to the autodocs.
"""
container: Optional[LN] = container_of(leaf)
while container is not None and container.type != token.ENDMARKER:
"""
container: Optional[LN] = container_of(leaf)
while container is not None and container.type != token.ENDMARKER:
+ if is_fmt_on(container):
return
# fix for fmt: on in children
return
# fix for fmt: on in children
container = container.next_sibling
container = container.next_sibling
-def fmt_on(container: LN) -> bool:
- is_fmt_on = False
+def is_fmt_on(container: LN) -> bool:
+ """Determine whether formatting is switched on within a container.
+ Determined by whether the last `# fmt:` comment is `on` or `off`.
+ """
+ fmt_on = False
for comment in list_comments(container.prefix, is_endmarker=False):
if comment.value in FMT_ON:
for comment in list_comments(container.prefix, is_endmarker=False):
if comment.value in FMT_ON:
elif comment.value in FMT_OFF:
elif comment.value in FMT_OFF:
- is_fmt_on = False
- return is_fmt_on
+ fmt_on = False
+ return fmt_on
def contains_fmt_on_at_column(container: LN, column: int) -> bool:
def contains_fmt_on_at_column(container: LN, column: int) -> bool:
+ """Determine if children at a given column have formatting switched on."""
for child in container.children:
if (
isinstance(child, Node)
for child in container.children:
if (
isinstance(child, Node)
or isinstance(child, Leaf)
and child.column == column
):
or isinstance(child, Leaf)
and child.column == column
):
return True
return False
def first_leaf_column(node: Node) -> Optional[int]:
return True
return False
def first_leaf_column(node: Node) -> Optional[int]:
+ """Returns the column of the first leaf child of a node."""
for child in node.children:
if isinstance(child, Leaf):
return child.column
for child in node.children:
if isinstance(child, Leaf):
return child.column
.. autofunction:: black.generate_ignored_nodes
.. autofunction:: black.generate_ignored_nodes
+.. autofunction:: black.is_fmt_on
+
+.. autofunction:: black.contains_fmt_on_at_column
+
+.. autofunction:: black.first_leaf_column
+
.. autofunction:: black.generate_trailers_to_omit
.. autofunction:: black.get_future_imports
.. autofunction:: black.generate_trailers_to_omit
.. autofunction:: black.get_future_imports