diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2023-01-09 13:05:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-09 12:05:51 +0000 |
commit | e355324cefe0fa4ae7f4cd6c240fabf0bef94c1c (patch) | |
tree | 73f70e1624d052139f644a13ed87436bafa1573a | |
parent | e259af237ed140e7c15ad61483e92302b3e8ce14 (diff) | |
download | astroid-git-e355324cefe0fa4ae7f4cd6c240fabf0bef94c1c.tar.gz |
Some modifications for pep237 with pydocstringformatter (#1792)
Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
-rw-r--r-- | astroid/astroid_manager.py | 4 | ||||
-rw-r--r-- | astroid/brain/brain_boto3.py | 3 | ||||
-rw-r--r-- | astroid/brain/brain_collections.py | 4 | ||||
-rw-r--r-- | astroid/brain/brain_ctypes.py | 4 | ||||
-rw-r--r-- | astroid/brain/brain_numpy_core_einsumfunc.py | 2 | ||||
-rw-r--r-- | astroid/brain/brain_numpy_utils.py | 5 | ||||
-rw-r--r-- | astroid/brain/brain_unittest.py | 10 | ||||
-rw-r--r-- | astroid/exceptions.py | 7 | ||||
-rw-r--r-- | astroid/modutils.py | 7 | ||||
-rw-r--r-- | astroid/nodes/node_ng.py | 17 | ||||
-rw-r--r-- | astroid/objects.py | 10 | ||||
-rw-r--r-- | astroid/test_utils.py | 4 | ||||
-rw-r--r-- | astroid/transforms.py | 2 |
13 files changed, 46 insertions, 33 deletions
diff --git a/astroid/astroid_manager.py b/astroid/astroid_manager.py index da51de70..efc571a2 100644 --- a/astroid/astroid_manager.py +++ b/astroid/astroid_manager.py @@ -1,5 +1,7 @@ """ -This file contain the global astroid MANAGER, to prevent circular import that happened +This file contain the global astroid MANAGER. + +It prevents a circular import that happened when the only possibility to import it was from astroid.__init__.py. This AstroidManager is a singleton/borg so it's possible to instantiate an diff --git a/astroid/brain/brain_boto3.py b/astroid/brain/brain_boto3.py index d9698b8a..425a1d33 100644 --- a/astroid/brain/brain_boto3.py +++ b/astroid/brain/brain_boto3.py @@ -2,7 +2,8 @@ # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt -"""Astroid hooks for understanding boto3.ServiceRequest().""" +"""Astroid hooks for understanding ``boto3.ServiceRequest()``.""" + from astroid import extract_node from astroid.manager import AstroidManager from astroid.nodes.scoped_nodes import ClassDef diff --git a/astroid/brain/brain_collections.py b/astroid/brain/brain_collections.py index 123096a2..51014dfa 100644 --- a/astroid/brain/brain_collections.py +++ b/astroid/brain/brain_collections.py @@ -86,8 +86,8 @@ register_module_extender(AstroidManager(), "collections", _collections_transform def _looks_like_subscriptable(node: ClassDef) -> bool: """ - Returns True if the node corresponds to a ClassDef of the Collections.abc module that - supports subscripting + Returns True if the node corresponds to a ClassDef of the Collections.abc module + that supports subscripting. :param node: ClassDef node """ diff --git a/astroid/brain/brain_ctypes.py b/astroid/brain/brain_ctypes.py index 323b19cc..35cb208f 100644 --- a/astroid/brain/brain_ctypes.py +++ b/astroid/brain/brain_ctypes.py @@ -19,7 +19,9 @@ from astroid.manager import AstroidManager def enrich_ctypes_redefined_types(): """ - For each ctypes redefined types, overload 'value' and '_type_' members definition. + For each ctypes redefined types, overload 'value' and '_type_' members + definition. + Overloading 'value' is mandatory otherwise astroid cannot infer the correct type for it. Overloading '_type_' is necessary because the class definition made here replaces the original one, in which '_type_' member is defined. Luckily those original class definitions are very short diff --git a/astroid/brain/brain_numpy_core_einsumfunc.py b/astroid/brain/brain_numpy_core_einsumfunc.py index 0f4789c6..d76241e4 100644 --- a/astroid/brain/brain_numpy_core_einsumfunc.py +++ b/astroid/brain/brain_numpy_core_einsumfunc.py @@ -4,7 +4,7 @@ """ Astroid hooks for numpy.core.einsumfunc module: -https://github.com/numpy/numpy/blob/main/numpy/core/einsumfunc.py +https://github.com/numpy/numpy/blob/main/numpy/core/einsumfunc.py. """ from astroid import nodes diff --git a/astroid/brain/brain_numpy_utils.py b/astroid/brain/brain_numpy_utils.py index b9e5d5f3..a3dbb116 100644 --- a/astroid/brain/brain_numpy_utils.py +++ b/astroid/brain/brain_numpy_utils.py @@ -22,8 +22,9 @@ def numpy_supports_type_hints() -> bool: def _get_numpy_version() -> tuple[str, str, str]: """ - Return the numpy version number if numpy can be imported. Otherwise returns - ('0', '0', '0') + Return the numpy version number if numpy can be imported. + + Otherwise returns ('0', '0', '0') """ try: import numpy # pylint: disable=import-outside-toplevel diff --git a/astroid/brain/brain_unittest.py b/astroid/brain/brain_unittest.py index b34e1cf5..89f5d26f 100644 --- a/astroid/brain/brain_unittest.py +++ b/astroid/brain/brain_unittest.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 -"""Astroid hooks for unittest module""" +"""Astroid hooks for unittest module.""" from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.const import PY38_PLUS @@ -11,9 +11,11 @@ from astroid.manager import AstroidManager def IsolatedAsyncioTestCaseImport(): """ - In the unittest package, the IsolatedAsyncioTestCase class is imported lazily, i.e only - when the __getattr__ method of the unittest module is called with 'IsolatedAsyncioTestCase' as - argument. Thus the IsolatedAsyncioTestCase is not imported statically (during import time). + In the unittest package, the IsolatedAsyncioTestCase class is imported lazily. + + I.E. only when the ``__getattr__`` method of the unittest module is called with + 'IsolatedAsyncioTestCase' as argument. Thus the IsolatedAsyncioTestCase + is not imported statically (during import time). This function mocks a classical static import of the IsolatedAsyncioTestCase. (see https://github.com/PyCQA/pylint/issues/4060) diff --git a/astroid/exceptions.py b/astroid/exceptions.py index fe6d43ba..c89ef72c 100644 --- a/astroid/exceptions.py +++ b/astroid/exceptions.py @@ -400,9 +400,10 @@ class ParentMissingError(AstroidError): class StatementMissing(ParentMissingError): - """Raised when a call to node.statement() does not return a node. This is because - a node in the chain does not have a parent attribute and therefore does not - return a node for statement(). + """Raised when a call to node.statement() does not return a node. + + This is because a node in the chain does not have a parent attribute + and therefore does not return a node for statement(). Standard attributes: target: The node for which the parent lookup failed. diff --git a/astroid/modutils.py b/astroid/modutils.py index 74a9cd7d..1b5057f5 100644 --- a/astroid/modutils.py +++ b/astroid/modutils.py @@ -339,9 +339,10 @@ def file_info_from_modpath( path: Sequence[str] | None = None, context_file: str | None = None, ) -> spec.ModuleSpec: - """given a mod path (i.e. split module / package name), return the - corresponding file, giving priority to source file over precompiled - file if it exists + """Given a mod path (i.e. split module / package name), return the + corresponding file. + + Giving priority to source file over precompiled file if it exists. :param modpath: split module's name (i.e name of a module or package split diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index 249e4129..38172f5f 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -126,13 +126,15 @@ class NodeNG: self.end_col_offset: int | None = end_col_offset """The end column this node appears on in the source code. + Note: This is after the last symbol. """ self.position: Position | None = None - """Position of keyword(s) and name. Used as fallback for block nodes - which might not provide good enough positional information. - E.g. ClassDef, FunctionDef. + """Position of keyword(s) and name. + + Used as fallback for block nodes which might not provide good + enough positional information. E.g. ClassDef, FunctionDef. """ def infer( @@ -262,7 +264,7 @@ class NodeNG: yield from () def last_child(self) -> NodeNG | None: - """An optimized version of list(get_children())[-1]""" + """An optimized version of list(get_children())[-1].""" for field in self._astroid_fields[::-1]: attr = getattr(self, field) if not attr: # None or empty list / tuple @@ -349,6 +351,7 @@ class NodeNG: def scope(self) -> nodes.LocalsDictNodeNG: """The first parent node defining a new scope. + These can be Module, FunctionDef, ClassDef, Lambda, or GeneratorExp nodes. :returns: The first parent scope node. @@ -591,7 +594,7 @@ class NodeNG: def _infer( self, context: InferenceContext | None = None, **kwargs: Any ) -> Generator[InferenceResult, None, InferenceErrorInfo | None]: - """we don't know how to resolve a statement by default""" + """We don't know how to resolve a statement by default.""" # this method is overridden by most concrete classes raise InferenceError( "No inference function for {node!r}.", node=self, context=context @@ -696,7 +699,9 @@ class NodeNG: @_repr_tree.register(tuple) @_repr_tree.register(list) def _repr_seq(node, result, done, cur_indent="", depth=1): - """Outputs a representation of a sequence that's contained within an AST.""" + """Outputs a representation of a sequence that's contained within an + AST. + """ cur_indent += indent result.append("[") if not node: diff --git a/astroid/objects.py b/astroid/objects.py index 16816c5e..0b68c693 100644 --- a/astroid/objects.py +++ b/astroid/objects.py @@ -42,7 +42,7 @@ _T = TypeVar("_T") class FrozenSet(node_classes.BaseContainer): - """class representing a FrozenSet composite node""" + """Class representing a FrozenSet composite node.""" def pytype(self) -> Literal["builtins.frozenset"]: return "builtins.frozenset" @@ -225,7 +225,7 @@ class Super(node_classes.NodeNG): class ExceptionInstance(bases.Instance): - """Class for instances of exceptions + """Class for instances of exceptions. It has special treatment for some of the exceptions's attributes, which are transformed at runtime into certain concrete objects, such as @@ -242,7 +242,7 @@ class ExceptionInstance(bases.Instance): class DictInstance(bases.Instance): - """Special kind of instances for dictionaries + """Special kind of instances for dictionaries. This instance knows the underlying object model of the dictionaries, which means that methods such as .values or .items can be properly inferred. @@ -271,7 +271,7 @@ class DictValues(bases.Proxy): class PartialFunction(scoped_nodes.FunctionDef): - """A class representing partial function obtained via functools.partial""" + """A class representing partial function obtained via functools.partial.""" @decorators.deprecate_arguments(doc="Use the postinit arg 'doc_node' instead") def __init__( @@ -322,7 +322,7 @@ node_classes.Dict.__bases__ = (node_classes.NodeNG, DictInstance) class Property(scoped_nodes.FunctionDef): - """Class representing a Python property""" + """Class representing a Python property.""" @decorators.deprecate_arguments(doc="Use the postinit arg 'doc_node' instead") def __init__( diff --git a/astroid/test_utils.py b/astroid/test_utils.py index c08a4818..c3b4c2e0 100644 --- a/astroid/test_utils.py +++ b/astroid/test_utils.py @@ -18,9 +18,7 @@ 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. - Skip 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: diff --git a/astroid/transforms.py b/astroid/transforms.py index 6f312633..be37879f 100644 --- a/astroid/transforms.py +++ b/astroid/transforms.py @@ -81,7 +81,7 @@ class TransformVisitor: self.transforms[node_class].remove((transform, predicate)) def visit(self, module): - """Walk the given astroid *tree* and transform each encountered node + """Walk the given astroid *tree* and transform each encountered node. Only the nodes which have transforms registered will actually be replaced or changed. |