diff options
| author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2023-01-09 13:16:36 +0100 |
|---|---|---|
| committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2023-01-09 13:16:36 +0100 |
| commit | daa3770f7c55457d79a2e93a14aa35a2d712ee2f (patch) | |
| tree | dce21936f7bedd83309af081bdf2b1884160531f | |
| parent | 317ace19727a4d2d74b4eaf99d4c3be1f10d05af (diff) | |
| download | astroid-git-daa3770f7c55457d79a2e93a14aa35a2d712ee2f.tar.gz | |
Automated changes
| -rw-r--r-- | .pre-commit-config.yaml | 2 | ||||
| -rw-r--r-- | astroid/brain/brain_attrs.py | 4 | ||||
| -rw-r--r-- | astroid/brain/brain_hypothesis.py | 3 | ||||
| -rw-r--r-- | astroid/brain/brain_namedtuple_enum.py | 1 | ||||
| -rw-r--r-- | astroid/brain/brain_typing.py | 7 | ||||
| -rw-r--r-- | astroid/constraint.py | 5 | ||||
| -rw-r--r-- | astroid/manager.py | 5 | ||||
| -rw-r--r-- | astroid/nodes/as_string.py | 135 | ||||
| -rw-r--r-- | astroid/nodes/scoped_nodes/mixin.py | 9 | ||||
| -rw-r--r-- | astroid/raw_building.py | 51 | ||||
| -rw-r--r-- | astroid/test_utils.py | 4 |
11 files changed, 120 insertions, 106 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a2c71c56..b7538cc4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -95,7 +95,7 @@ repos: - id: prettier args: [--prose-wrap=always, --print-width=88] - repo: https://github.com/DanielNoord/pydocstringformatter - rev: v0.7.0 + rev: v0.7.3 hooks: - id: pydocstringformatter exclude: tests/testdata diff --git a/astroid/brain/brain_attrs.py b/astroid/brain/brain_attrs.py index acb069e3..07d04979 100644 --- a/astroid/brain/brain_attrs.py +++ b/astroid/brain/brain_attrs.py @@ -3,7 +3,7 @@ # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt """ -Astroid hook for the attrs library +Astroid hook for the attrs library. Without this hook pylint reports unsupported-assignment-operation for attrs classes @@ -45,7 +45,7 @@ def is_decorated_with_attrs(node, decorator_names=ATTRS_NAMES) -> bool: def attr_attributes_transform(node: ClassDef) -> None: """Given that the ClassNode has an attr decorator, - rewrite class attributes as instance attributes + rewrite class attributes as instance attributes. """ # Astroid can't infer this attribute properly # Prevents https://github.com/PyCQA/pylint/issues/1884 diff --git a/astroid/brain/brain_hypothesis.py b/astroid/brain/brain_hypothesis.py index 5d68f732..6880a588 100644 --- a/astroid/brain/brain_hypothesis.py +++ b/astroid/brain/brain_hypothesis.py @@ -38,7 +38,8 @@ def is_decorated_with_st_composite(node) -> bool: def remove_draw_parameter_from_composite_strategy(node): """Given that the FunctionDef is decorated with @st.composite, remove the - first argument (`draw`) - it's always supplied by Hypothesis so we don't + first argument (`draw`) - it's always supplied by Hypothesis so we don't. + need to emit the no-value-for-parameter lint. """ del node.args.args[0] diff --git a/astroid/brain/brain_namedtuple_enum.py b/astroid/brain/brain_namedtuple_enum.py index ed80e783..2fa27848 100644 --- a/astroid/brain/brain_namedtuple_enum.py +++ b/astroid/brain/brain_namedtuple_enum.py @@ -499,6 +499,7 @@ def infer_typing_namedtuple_class(class_node, context: InferenceContext | None = def infer_typing_namedtuple_function(node, context: InferenceContext | None = None): """ Starting with python3.9, NamedTuple is a function of the typing module. + The class NamedTuple is build dynamically through a call to `type` during initialization of the `_NamedTuple` variable. """ diff --git a/astroid/brain/brain_typing.py b/astroid/brain/brain_typing.py index 15059f44..c7397308 100644 --- a/astroid/brain/brain_typing.py +++ b/astroid/brain/brain_typing.py @@ -238,7 +238,9 @@ def _forbid_class_getitem_access(node: ClassDef) -> None: def full_raiser(origin_func, attr, *args, **kwargs): """ - Raises an AttributeInferenceError in case of access to __class_getitem__ method. + Raises an AttributeInferenceError in case of access to __class_getitem__ + method. + Otherwise, just call origin_func. """ if attr == "__class_getitem__": @@ -262,7 +264,8 @@ def infer_typing_alias( ) -> Iterator[ClassDef]: """ Infers the call to _alias function - Insert ClassDef, with same name as aliased class, + Insert ClassDef, with same name as aliased class,. + in mro to simulate _GenericAlias. :param node: call node diff --git a/astroid/constraint.py b/astroid/constraint.py index deed9ac5..31d931e7 100644 --- a/astroid/constraint.py +++ b/astroid/constraint.py @@ -28,7 +28,10 @@ class Constraint(ABC): self.node = node """The node that this constraint applies to.""" self.negate = negate - """True if this constraint is negated. E.g., "is not" instead of "is".""" + """True if this constraint is negated. + + E.g., "is not" instead of "is". + """ @classmethod @abstractmethod diff --git a/astroid/manager.py b/astroid/manager.py index 8a5b05c7..98095370 100644 --- a/astroid/manager.py +++ b/astroid/manager.py @@ -2,8 +2,9 @@ # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt -"""astroid manager: avoid multiple astroid build of a same module when -possible by providing a class responsible to get astroid representation +"""Astroid manager: avoid multiple astroid build of a same module when +possible by providing a class responsible to get astroid representation. + from various source and using a cache of built modules) """ diff --git a/astroid/nodes/as_string.py b/astroid/nodes/as_string.py index cbd5ee17..6c37ff7f 100644 --- a/astroid/nodes/as_string.py +++ b/astroid/nodes/as_string.py @@ -2,7 +2,7 @@ # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt -"""This module renders Astroid nodes as string""" +"""This module renders Astroid nodes as string.""" from __future__ import annotations @@ -33,17 +33,17 @@ DOC_NEWLINE = "\0" # Visitor pattern require argument all the time and is not better with staticmethod # noinspection PyUnusedLocal,PyMethodMayBeStatic class AsStringVisitor: - """Visitor to render an Astroid node as a valid python code string""" + """Visitor to render an Astroid node as a valid python code string.""" def __init__(self, indent: str = " "): self.indent: str = indent def __call__(self, node) -> str: - """Makes this visitor behave as a simple function""" + """Makes this visitor behave as a simple function.""" return node.accept(self).replace(DOC_NEWLINE, "\n") def _docs_dedent(self, doc_node: Const | None) -> str: - """Stop newlines in docs being indented by self._stmt_list""" + """Stop newlines in docs being indented by self._stmt_list.""" if not doc_node: return "" @@ -52,7 +52,7 @@ class AsStringVisitor: ) def _stmt_list(self, stmts: list, indent: bool = True) -> str: - """return a list of nodes to string""" + """Return a list of nodes to string.""" stmts_str: str = "\n".join( nstr for nstr in [n.accept(self) for n in stmts] if nstr ) @@ -62,7 +62,7 @@ class AsStringVisitor: return self.indent + stmts_str.replace("\n", "\n" + self.indent) def _precedence_parens(self, node, child, is_left: bool = True) -> str: - """Wrap child in parens only if required to keep same semantics""" + """Wrap child in parens only if required to keep same semantics.""" if self._should_wrap(node, child, is_left): return f"({child.accept(self)})" @@ -70,7 +70,8 @@ class AsStringVisitor: def _should_wrap(self, node, child, is_left: bool) -> bool: """Wrap child if: - - it has lower precedence + - it has lower precedence. + - same precedence with position opposite to associativity direction """ node_precedence = node.op_precedence() @@ -102,34 +103,34 @@ class AsStringVisitor: return f"async {self.visit_for(node)}" def visit_arguments(self, node) -> str: - """return an astroid.Function node as string""" + """Return an astroid.Function node as string.""" return node.format_args() def visit_assignattr(self, node) -> str: - """return an astroid.AssAttr node as string""" + """Return an astroid.AssAttr node as string.""" return self.visit_attribute(node) def visit_assert(self, node) -> str: - """return an astroid.Assert node as string""" + """Return an astroid.Assert node as string.""" if node.fail: return f"assert {node.test.accept(self)}, {node.fail.accept(self)}" return f"assert {node.test.accept(self)}" def visit_assignname(self, node) -> str: - """return an astroid.AssName node as string""" + """Return an astroid.AssName node as string.""" return node.name def visit_assign(self, node) -> str: - """return an astroid.Assign node as string""" + """Return an astroid.Assign node as string.""" lhs = " = ".join(n.accept(self) for n in node.targets) return f"{lhs} = {node.value.accept(self)}" def visit_augassign(self, node) -> str: - """return an astroid.AugAssign node as string""" + """Return an astroid.AugAssign node as string.""" return f"{node.target.accept(self)} {node.op} {node.value.accept(self)}" def visit_annassign(self, node) -> str: - """Return an astroid.AugAssign node as string""" + """Return an astroid.AugAssign node as string.""" target = node.target.accept(self) annotation = node.annotation.accept(self) @@ -138,7 +139,7 @@ class AsStringVisitor: return f"{target}: {annotation} = {node.value.accept(self)}" def visit_binop(self, node) -> str: - """return an astroid.BinOp node as string""" + """Return an astroid.BinOp node as string.""" left = self._precedence_parens(node, node.left) right = self._precedence_parens(node, node.right, is_left=False) if node.op == "**": @@ -147,16 +148,16 @@ class AsStringVisitor: return f"{left} {node.op} {right}" def visit_boolop(self, node) -> str: - """return an astroid.BoolOp node as string""" + """Return an astroid.BoolOp node as string.""" values = [f"{self._precedence_parens(node, n)}" for n in node.values] return (f" {node.op} ").join(values) def visit_break(self, node) -> str: - """return an astroid.Break node as string""" + """Return an astroid.Break node as string.""" return "break" def visit_call(self, node) -> str: - """return an astroid.Call node as string""" + """Return an astroid.Call node as string.""" expr_str = self._precedence_parens(node, node.func) args = [arg.accept(self) for arg in node.args] if node.keywords: @@ -168,7 +169,7 @@ class AsStringVisitor: return f"{expr_str}({', '.join(args)})" def visit_classdef(self, node) -> str: - """return an astroid.ClassDef node as string""" + """Return an astroid.ClassDef node as string.""" decorate = node.decorators.accept(self) if node.decorators else "" args = [n.accept(self) for n in node.bases] if node._metaclass and not node.has_metaclass_hack(): @@ -181,7 +182,7 @@ class AsStringVisitor: ) def visit_compare(self, node) -> str: - """return an astroid.Compare node as string""" + """Return an astroid.Compare node as string.""" rhs_str = " ".join( f"{op} {self._precedence_parens(node, expr, is_left=False)}" for op, expr in node.ops @@ -189,39 +190,39 @@ class AsStringVisitor: return f"{self._precedence_parens(node, node.left)} {rhs_str}" def visit_comprehension(self, node) -> str: - """return an astroid.Comprehension node as string""" + """Return an astroid.Comprehension node as string.""" ifs = "".join(f" if {n.accept(self)}" for n in node.ifs) generated = f"for {node.target.accept(self)} in {node.iter.accept(self)}{ifs}" return f"{'async ' if node.is_async else ''}{generated}" def visit_const(self, node) -> str: - """return an astroid.Const node as string""" + """Return an astroid.Const node as string.""" if node.value is Ellipsis: return "..." return repr(node.value) def visit_continue(self, node) -> str: - """return an astroid.Continue node as string""" + """Return an astroid.Continue node as string.""" return "continue" def visit_delete(self, node) -> str: # XXX check if correct - """return an astroid.Delete node as string""" + """Return an astroid.Delete node as string.""" return f"del {', '.join(child.accept(self) for child in node.targets)}" def visit_delattr(self, node) -> str: - """return an astroid.DelAttr node as string""" + """Return an astroid.DelAttr node as string.""" return self.visit_attribute(node) def visit_delname(self, node) -> str: - """return an astroid.DelName node as string""" + """Return an astroid.DelName node as string.""" return node.name def visit_decorators(self, node) -> str: - """return an astroid.Decorators node as string""" + """Return an astroid.Decorators node as string.""" return "@%s\n" % "\n@".join(item.accept(self) for item in node.nodes) def visit_dict(self, node) -> str: - """return an astroid.Dict node as string""" + """Return an astroid.Dict node as string.""" return "{%s}" % ", ".join(self._visit_dict(node)) def _visit_dict(self, node) -> Iterator[str]: @@ -238,7 +239,7 @@ class AsStringVisitor: return "**" def visit_dictcomp(self, node) -> str: - """return an astroid.DictComp node as string""" + """Return an astroid.DictComp node as string.""" return "{{{}: {} {}}}".format( node.key.accept(self), node.value.accept(self), @@ -246,11 +247,11 @@ class AsStringVisitor: ) def visit_expr(self, node) -> str: - """return an astroid.Discard node as string""" + """Return an astroid.Discard node as string.""" return node.value.accept(self) def visit_emptynode(self, node) -> str: - """dummy method for visiting an Empty node""" + """Dummy method for visiting an Empty node.""" return "" def visit_excepthandler(self, node) -> str: @@ -264,11 +265,11 @@ class AsStringVisitor: return f"{excs}:\n{self._stmt_list(node.body)}" def visit_empty(self, node) -> str: - """return an Empty node as string""" + """Return an Empty node as string.""" return "" def visit_for(self, node) -> str: - """return an astroid.For node as string""" + """Return an astroid.For node as string.""" fors = "for {} in {}:\n{}".format( node.target.accept(self), node.iter.accept(self), self._stmt_list(node.body) ) @@ -277,7 +278,7 @@ class AsStringVisitor: return fors def visit_importfrom(self, node) -> str: - """return an astroid.ImportFrom node as string""" + """Return an astroid.ImportFrom node as string.""" return "from {} import {}".format( "." * (node.level or 0) + node.modname, _import_string(node.names) ) @@ -318,7 +319,7 @@ class AsStringVisitor: return "{%s}" % result def handle_functiondef(self, node, keyword) -> str: - """return a (possibly async) function definition node as string""" + """Return a (possibly async) function definition node as string.""" decorate = node.decorators.accept(self) if node.decorators else "" docs = self._docs_dedent(node.doc_node) trailer = ":" @@ -337,32 +338,32 @@ class AsStringVisitor: ) def visit_functiondef(self, node) -> str: - """return an astroid.FunctionDef node as string""" + """Return an astroid.FunctionDef node as string.""" return self.handle_functiondef(node, "def") def visit_asyncfunctiondef(self, node) -> str: - """return an astroid.AsyncFunction node as string""" + """Return an astroid.AsyncFunction node as string.""" return self.handle_functiondef(node, "async def") def visit_generatorexp(self, node) -> str: - """return an astroid.GeneratorExp node as string""" + """Return an astroid.GeneratorExp node as string.""" return "({} {})".format( node.elt.accept(self), " ".join(n.accept(self) for n in node.generators) ) def visit_attribute(self, node) -> str: - """return an astroid.Getattr node as string""" + """Return an astroid.Getattr node as string.""" left = self._precedence_parens(node, node.expr) if left.isdigit(): left = f"({left})" return f"{left}.{node.attrname}" def visit_global(self, node) -> str: - """return an astroid.Global node as string""" + """Return an astroid.Global node as string.""" return f"global {', '.join(node.names)}" def visit_if(self, node) -> str: - """return an astroid.If node as string""" + """Return an astroid.If node as string.""" ifs = [f"if {node.test.accept(self)}:\n{self._stmt_list(node.body)}"] if node.has_elif_block(): ifs.append(f"el{self._stmt_list(node.orelse, indent=False)}") @@ -371,7 +372,7 @@ class AsStringVisitor: return "\n".join(ifs) def visit_ifexp(self, node) -> str: - """return an astroid.IfExp node as string""" + """Return an astroid.IfExp node as string.""" return "{} if {} else {}".format( self._precedence_parens(node, node.body, is_left=True), self._precedence_parens(node, node.test, is_left=True), @@ -379,17 +380,17 @@ class AsStringVisitor: ) def visit_import(self, node) -> str: - """return an astroid.Import node as string""" + """Return an astroid.Import node as string.""" return f"import {_import_string(node.names)}" def visit_keyword(self, node) -> str: - """return an astroid.Keyword node as string""" + """Return an astroid.Keyword node as string.""" if node.arg is None: return f"**{node.value.accept(self)}" return f"{node.arg}={node.value.accept(self)}" def visit_lambda(self, node) -> str: - """return an astroid.Lambda node as string""" + """Return an astroid.Lambda node as string.""" args = node.args.accept(self) body = node.body.accept(self) if args: @@ -398,40 +399,40 @@ class AsStringVisitor: return f"lambda: {body}" def visit_list(self, node) -> str: - """return an astroid.List node as string""" + """Return an astroid.List node as string.""" return f"[{', '.join(child.accept(self) for child in node.elts)}]" def visit_listcomp(self, node) -> str: - """return an astroid.ListComp node as string""" + """Return an astroid.ListComp node as string.""" return "[{} {}]".format( node.elt.accept(self), " ".join(n.accept(self) for n in node.generators) ) def visit_module(self, node) -> str: - """return an astroid.Module node as string""" + """Return an astroid.Module node as string.""" docs = f'"""{node.doc_node.value}"""\n\n' if node.doc_node else "" return docs + "\n".join(n.accept(self) for n in node.body) + "\n\n" def visit_name(self, node) -> str: - """return an astroid.Name node as string""" + """Return an astroid.Name node as string.""" return node.name def visit_namedexpr(self, node) -> str: - """Return an assignment expression node as string""" + """Return an assignment expression node as string.""" target = node.target.accept(self) value = node.value.accept(self) return f"{target} := {value}" def visit_nonlocal(self, node) -> str: - """return an astroid.Nonlocal node as string""" + """Return an astroid.Nonlocal node as string.""" return f"nonlocal {', '.join(node.names)}" def visit_pass(self, node) -> str: - """return an astroid.Pass node as string""" + """Return an astroid.Pass node as string.""" return "pass" def visit_raise(self, node) -> str: - """return an astroid.Raise node as string""" + """Return an astroid.Raise node as string.""" if node.exc: if node.cause: return f"raise {node.exc.accept(self)} from {node.cause.accept(self)}" @@ -439,7 +440,7 @@ class AsStringVisitor: return "raise" def visit_return(self, node) -> str: - """return an astroid.Return node as string""" + """Return an astroid.Return node as string.""" if node.is_tuple_return() and len(node.value.elts) > 1: elts = [child.accept(self) for child in node.value.elts] return f"return {', '.join(elts)}" @@ -450,17 +451,17 @@ class AsStringVisitor: return "return" def visit_set(self, node) -> str: - """return an astroid.Set node as string""" + """Return an astroid.Set node as string.""" return "{%s}" % ", ".join(child.accept(self) for child in node.elts) def visit_setcomp(self, node) -> str: - """return an astroid.SetComp node as string""" + """Return an astroid.SetComp node as string.""" return "{{{} {}}}".format( node.elt.accept(self), " ".join(n.accept(self) for n in node.generators) ) def visit_slice(self, node) -> str: - """return an astroid.Slice node as string""" + """Return an astroid.Slice node as string.""" lower = node.lower.accept(self) if node.lower else "" upper = node.upper.accept(self) if node.upper else "" step = node.step.accept(self) if node.step else "" @@ -469,7 +470,7 @@ class AsStringVisitor: return f"{lower}:{upper}" def visit_subscript(self, node) -> str: - """return an astroid.Subscript node as string""" + """Return an astroid.Subscript node as string.""" idx = node.slice if idx.__class__.__name__.lower() == "index": idx = idx.value @@ -481,7 +482,7 @@ class AsStringVisitor: return f"{self._precedence_parens(node, node.value)}[{idxstr}]" def visit_tryexcept(self, node) -> str: - """return an astroid.TryExcept node as string""" + """Return an astroid.TryExcept node as string.""" trys = [f"try:\n{self._stmt_list(node.body)}"] for handler in node.handlers: trys.append(handler.accept(self)) @@ -490,19 +491,19 @@ class AsStringVisitor: return "\n".join(trys) def visit_tryfinally(self, node) -> str: - """return an astroid.TryFinally node as string""" + """Return an astroid.TryFinally node as string.""" return "try:\n{}\nfinally:\n{}".format( self._stmt_list(node.body), self._stmt_list(node.finalbody) ) def visit_tuple(self, node) -> str: - """return an astroid.Tuple node as string""" + """Return an astroid.Tuple node as string.""" if len(node.elts) == 1: return f"({node.elts[0].accept(self)}, )" return f"({', '.join(child.accept(self) for child in node.elts)})" def visit_unaryop(self, node) -> str: - """return an astroid.UnaryOp node as string""" + """Return an astroid.UnaryOp node as string.""" if node.op == "not": operator = "not " else: @@ -510,14 +511,14 @@ class AsStringVisitor: return f"{operator}{self._precedence_parens(node, node.operand)}" def visit_while(self, node) -> str: - """return an astroid.While node as string""" + """Return an astroid.While node as string.""" whiles = f"while {node.test.accept(self)}:\n{self._stmt_list(node.body)}" if node.orelse: whiles = f"{whiles}\nelse:\n{self._stmt_list(node.orelse)}" return whiles def visit_with(self, node) -> str: # 'with' without 'as' is possible - """return an astroid.With node as string""" + """Return an astroid.With node as string.""" items = ", ".join( f"{expr.accept(self)}" + (v and f" as {v.accept(self)}" or "") for expr, v in node.items @@ -525,7 +526,7 @@ class AsStringVisitor: return f"with {items}:\n{self._stmt_list(node.body)}" def visit_yield(self, node) -> str: - """yield an ast.Yield node as string""" + """Yield an ast.Yield node as string.""" yi_val = (" " + node.value.accept(self)) if node.value else "" expr = "yield" + yi_val if node.parent.is_statement: @@ -543,7 +544,7 @@ class AsStringVisitor: return f"({expr})" def visit_starred(self, node) -> str: - """return Starred node as string""" + """Return Starred node as string.""" return "*" + node.value.accept(self) def visit_match(self, node: Match) -> str: @@ -642,7 +643,7 @@ class AsStringVisitor: def _import_string(names) -> str: - """return a list of (name, asname) formatted as a string""" + """Return a list of (name, asname) formatted as a string.""" _names = [] for name, asname in names: if asname is not None: diff --git a/astroid/nodes/scoped_nodes/mixin.py b/astroid/nodes/scoped_nodes/mixin.py index ff37994c..64a24081 100644 --- a/astroid/nodes/scoped_nodes/mixin.py +++ b/astroid/nodes/scoped_nodes/mixin.py @@ -20,8 +20,9 @@ _T = TypeVar("_T") class LocalsDictNodeNG(node_classes.LookupMixIn): - """this class provides locals handling common to Module, FunctionDef - and ClassDef nodes, including a dict like interface for direct access + """This class provides locals handling common to Module, FunctionDef + and ClassDef nodes, including a dict like interface for direct access. + to locals information """ @@ -70,7 +71,7 @@ class LocalsDictNodeNG(node_classes.LookupMixIn): raise NotImplementedError def _scope_lookup(self, node, name, offset=0): - """XXX method for interfacing the scope lookup""" + """XXX method for interfacing the scope lookup.""" try: stmts = _filter_stmts(node, self.locals[name], self, offset) except KeyError: @@ -104,7 +105,7 @@ class LocalsDictNodeNG(node_classes.LookupMixIn): __setitem__ = set_local def _append_node(self, child: nodes.NodeNG) -> None: - """append a child, linking it in the tree""" + """Append a child, linking it in the tree.""" # pylint: disable=no-member; depending by the class # which uses the current class as a mixin or base class. # It's rewritten in 2.0, so it makes no sense for now diff --git a/astroid/raw_building.py b/astroid/raw_building.py index fe19bb75..5325ed25 100644 --- a/astroid/raw_building.py +++ b/astroid/raw_building.py @@ -2,8 +2,8 @@ # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt -"""this module contains a set of functions to create astroid trees from scratch -(build_* functions) or from living object (object_build_* functions) +"""This module contains a set of functions to create astroid trees from scratch +(build_* functions) or from living object (object_build_* functions). """ from __future__ import annotations @@ -56,8 +56,8 @@ def _add_dunder_class(func, member) -> None: def attach_dummy_node(node, name: str, runtime_object=_EMPTY_OBJECT_MARKER) -> None: - """create a dummy node and register it in the locals of the given - node with the specified name + """Create a dummy node and register it in the locals of the given + node with the specified name. """ enode = nodes.EmptyNode() enode.object = runtime_object @@ -65,23 +65,23 @@ def attach_dummy_node(node, name: str, runtime_object=_EMPTY_OBJECT_MARKER) -> N def attach_const_node(node, name: str, value) -> None: - """create a Const node and register it in the locals of the given - node with the specified name + """Create a Const node and register it in the locals of the given + node with the specified name. """ if name not in node.special_attributes: _attach_local_node(node, nodes.const_factory(value), name) def attach_import_node(node, modname: str, membername: str) -> None: - """create a ImportFrom node and register it in the locals of the given - node with the specified name + """Create a ImportFrom node and register it in the locals of the given + node with the specified name. """ from_node = nodes.ImportFrom(modname, [(membername, None)]) _attach_local_node(node, from_node, membername) def build_module(name: str, doc: str | None = None) -> nodes.Module: - """create and initialize an astroid Module node""" + """Create and initialize an astroid Module node.""" node = nodes.Module(name, pure_python=False, package=False) node.postinit( body=[], @@ -112,7 +112,7 @@ def build_function( doc: str | None = None, kwonlyargs: list[str] | None = None, ) -> nodes.FunctionDef: - """create and initialize an astroid FunctionDef node""" + """Create and initialize an astroid FunctionDef node.""" # first argument is now a list of decorators func = nodes.FunctionDef(name) argsnode = nodes.Arguments(parent=func) @@ -157,12 +157,12 @@ def build_function( def build_from_import(fromname: str, names: list[str]) -> nodes.ImportFrom: - """create and initialize an astroid ImportFrom import statement""" + """Create and initialize an astroid ImportFrom import statement.""" return nodes.ImportFrom(fromname, [(name, None) for name in names]) def register_arguments(func: nodes.FunctionDef, args: list | None = None) -> None: - """add given arguments to local + """Add given arguments to local. args is a list that may contains nested lists (i.e. def func(a, (b, c, d)): ...) @@ -187,7 +187,7 @@ def register_arguments(func: nodes.FunctionDef, args: list | None = None) -> Non def object_build_class( node: nodes.Module | nodes.ClassDef, member: type, localname: str ) -> nodes.ClassDef: - """create astroid for a living class object""" + """Create astroid for a living class object.""" basenames = [base.__name__ for base in member.__bases__] return _base_class_object_build(node, member, basenames, localname=localname) @@ -225,7 +225,7 @@ def _get_args_info_from_callable( def object_build_function( node: nodes.Module | nodes.ClassDef, member: _FunctionTypes, localname: str ) -> None: - """create astroid for a living function object""" + """Create astroid for a living function object.""" args, posonlyargs, defaults, kwonlyargs = _get_args_info_from_callable(member) func = build_function( @@ -243,7 +243,7 @@ def object_build_function( def object_build_datadescriptor( node: nodes.Module | nodes.ClassDef, member: type, name: str ) -> nodes.ClassDef: - """create astroid for a living data descriptor object""" + """Create astroid for a living data descriptor object.""" return _base_class_object_build(node, member, [], name) @@ -252,7 +252,7 @@ def object_build_methoddescriptor( member: _FunctionTypes, localname: str, ) -> None: - """create astroid for a living method descriptor object""" + """Create astroid for a living method descriptor object.""" # FIXME get arguments ? func = build_function( getattr(member, "__name__", None) or localname, doc=member.__doc__ @@ -268,8 +268,8 @@ def _base_class_object_build( name: str | None = None, localname: str | None = None, ) -> nodes.ClassDef: - """create astroid for a living class object, with a given set of base names - (e.g. ancestors) + """Create astroid for a living class object, with a given set of base names + (e.g. ancestors). """ class_name = name or getattr(member, "__name__", None) or localname assert isinstance(class_name, str) @@ -325,7 +325,7 @@ def _build_from_function( class InspectBuilder: - """class for building nodes from living object + """Class for building nodes from living object. this is actually a really minimal representation, including only Module, FunctionDef and ClassDef nodes and some others as guessed. @@ -342,8 +342,9 @@ class InspectBuilder: modname: str | None = None, path: str | None = None, ) -> nodes.Module: - """build astroid from a living module (i.e. using inspect) - this is used when there is no python source code available (either + """Build astroid from a living module (i.e. using inspect) + this is used when there is no python source code available (either. + because it's a built-in module or because the .py is not available) """ self._module = module @@ -369,8 +370,8 @@ class InspectBuilder: def object_build( self, node: nodes.Module | nodes.ClassDef, obj: types.ModuleType | type ) -> None: - """recursive method which create a partial ast from real objects - (only function, class, and method are handled) + """Recursive method which create a partial ast from real objects + (only function, class, and method are handled). """ if obj in self._done: return None @@ -430,7 +431,7 @@ class InspectBuilder: return None def imported_member(self, node, member, name: str) -> bool: - """verify this is not an imported class or handle it""" + """Verify this is not an imported class or handle it.""" # /!\ some classes like ExtensionClass doesn't have a __module__ # attribute ! Also, this may trigger an exception on badly built module # (see http://www.logilab.org/ticket/57299 for instance) @@ -480,7 +481,7 @@ def _set_proxied(const) -> nodes.ClassDef: def _astroid_bootstrapping() -> None: - """astroid bootstrapping the builtins module""" + """Astroid bootstrapping the builtins module.""" # this boot strapping is necessary since we need the Const nodes to # inspect_build builtins, and then we can proxy Const builder = InspectBuilder() diff --git a/astroid/test_utils.py b/astroid/test_utils.py index c3b4c2e0..3fad9332 100644 --- a/astroid/test_utils.py +++ b/astroid/test_utils.py @@ -18,7 +18,9 @@ from astroid import manager, nodes, transforms def require_version(minver: str = "0.0.0", maxver: str = "4.0.0") -> Callable: - """Compare version of python interpreter to the given one and skips the test if older.""" + """Compare version of python interpreter to the given one and skips the test if + older. + """ def parse(python_version: str) -> tuple[int, ...]: try: |
