summaryrefslogtreecommitdiff
path: root/pylint/checkers/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'pylint/checkers/utils.py')
-rw-r--r--pylint/checkers/utils.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index 026a78b5e..4cc413e5c 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -512,8 +512,9 @@ class UnsupportedFormatCharacter(Exception):
def parse_format_string(
format_string: str,
) -> Tuple[Set[str], int, Dict[str, str], List[str]]:
- """Parses a format string, returning a tuple of (keys, num_args), where 'keys'
- is the set of mapping keys in the format string, and 'num_args' is the number
+ """Parses a format string, returning a tuple (keys, num_args).
+
+ Where 'keys' is the set of mapping keys in the format string, and 'num_args' is the number
of arguments required by the format string. Raises IncompleteFormatString or
UnsupportedFormatCharacter if a parse error occurs.
"""
@@ -593,8 +594,9 @@ def split_format_field_names(format_string) -> Tuple[str, Iterable[Tuple[bool, s
def collect_string_fields(format_string) -> Iterable[Optional[str]]:
"""Given a format string, return an iterator
- of all the valid format fields. It handles nested fields
- as well.
+ of all the valid format fields.
+
+ It handles nested fields as well.
"""
formatter = string.Formatter()
try:
@@ -627,8 +629,9 @@ def parse_format_method_string(
format_string: str,
) -> Tuple[List[Tuple[str, List[Tuple[bool, str]]]], int, int]:
"""Parses a PEP 3101 format string, returning a tuple of
- (keyword_arguments, implicit_pos_args_cnt, explicit_pos_args),
- where keyword_arguments is the set of mapping keys in the format string, implicit_pos_args_cnt
+ (keyword_arguments, implicit_pos_args_cnt, explicit_pos_args).
+
+ keyword_arguments is the set of mapping keys in the format string, implicit_pos_args_cnt
is the number of arguments required by the format string and
explicit_pos_args is the number of arguments passed with the position.
"""
@@ -1045,8 +1048,8 @@ def get_exception_handlers(
def is_node_inside_try_except(node: nodes.Raise) -> bool:
- """Check if the node is directly under a Try/Except statement.
- (but not under an ExceptHandler!)
+ """Check if the node is directly under a Try/Except statement
+ (but not under an ExceptHandler!).
Args:
node (nodes.Raise): the node raising the exception.
@@ -1366,7 +1369,9 @@ def is_registered_in_singledispatch_function(node: nodes.FunctionDef) -> bool:
def get_node_last_lineno(node: nodes.NodeNG) -> int:
- """Get the last lineno of the given node. For a simple statement this will just be node.lineno,
+ """Get the last lineno of the given node.
+
+ For a simple statement this will just be node.lineno,
but for a node that has child statements (e.g. a method) this will be the lineno of the last
child statement recursively.
"""
@@ -1438,6 +1443,7 @@ def is_node_in_type_annotation_context(node: nodes.NodeNG) -> bool:
def is_subclass_of(child: nodes.ClassDef, parent: nodes.ClassDef) -> bool:
"""Check if first node is a subclass of second node.
+
:param child: Node to check for subclass.
:param parent: Node to check for superclass.
:returns: True if child is derived from parent. False otherwise.
@@ -1658,6 +1664,7 @@ def is_typing_guard(node: nodes.If) -> bool:
def is_node_in_guarded_import_block(node: nodes.NodeNG) -> bool:
"""Return True if node is part for guarded if block.
+
I.e. `sys.version_info` or `typing.TYPE_CHECKING`
"""
return isinstance(node.parent, nodes.If) and (
@@ -1731,8 +1738,9 @@ def get_node_first_ancestor_of_type_and_its_child(
node: nodes.NodeNG, ancestor_type: Union[Type[T_Node], Tuple[Type[T_Node], ...]]
) -> Union[Tuple[None, None], Tuple[T_Node, nodes.NodeNG]]:
"""Modified version of get_node_first_ancestor_of_type to also return the
- descendant visited directly before reaching the sought ancestor. Useful
- for extracting whether a statement is guarded by a try, except, or finally
+ descendant visited directly before reaching the sought ancestor
+
+ Useful for extracting whether a statement is guarded by a try, except, or finally
when searching for a TryFinally ancestor.
"""
child = node