summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--astroid/__init__.py2
-rw-r--r--astroid/_ast.py2
-rw-r--r--astroid/arguments.py8
-rw-r--r--astroid/bases.py22
-rw-r--r--astroid/brain/brain_boto3.py4
-rw-r--r--astroid/brain/brain_builtin_inference.py24
-rw-r--r--astroid/brain/brain_dataclasses.py12
-rw-r--r--astroid/brain/brain_dateutil.py2
-rw-r--r--astroid/brain/brain_functools.py2
-rw-r--r--astroid/brain/brain_hypothesis.py1
-rw-r--r--astroid/brain/brain_io.py4
-rw-r--r--astroid/brain/brain_namedtuple_enum.py6
-rw-r--r--astroid/brain/brain_numpy_ma.py4
-rw-r--r--astroid/brain/brain_numpy_utils.py6
-rw-r--r--astroid/brain/brain_re.py5
-rw-r--r--astroid/brain/brain_regex.py5
-rw-r--r--astroid/brain/brain_responses.py1
-rw-r--r--astroid/brain/brain_six.py4
-rw-r--r--astroid/brain/brain_type.py4
-rw-r--r--astroid/brain/brain_typing.py14
-rw-r--r--astroid/builder.py14
-rw-r--r--astroid/context.py18
-rw-r--r--astroid/decorators.py14
-rw-r--r--astroid/exceptions.py25
-rw-r--r--astroid/filter_statements.py8
-rw-r--r--astroid/helpers.py12
-rw-r--r--astroid/inference.py31
-rw-r--r--astroid/inference_tip.py4
-rw-r--r--astroid/interpreter/_import/spec.py4
-rw-r--r--astroid/interpreter/dunder_lookup.py2
-rw-r--r--astroid/interpreter/objectmodel.py12
-rw-r--r--astroid/manager.py17
-rw-r--r--astroid/mixins.py3
-rw-r--r--astroid/modutils.py48
-rw-r--r--astroid/nodes/_base_nodes.py17
-rw-r--r--astroid/nodes/scoped_nodes/__init__.py4
-rw-r--r--astroid/nodes/scoped_nodes/utils.py4
-rw-r--r--astroid/protocols.py10
-rw-r--r--astroid/rebuilder.py120
-rw-r--r--astroid/util.py2
40 files changed, 258 insertions, 243 deletions
diff --git a/astroid/__init__.py b/astroid/__init__.py
index 41b8fffd..605a8b48 100644
--- a/astroid/__init__.py
+++ b/astroid/__init__.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
-"""Python Abstract Syntax Tree New Generation
+"""Python Abstract Syntax Tree New Generation.
The aim of this module is to provide a common base representation of
python source code for projects such as pychecker, pyreverse,
diff --git a/astroid/_ast.py b/astroid/_ast.py
index edd822b6..9a84492d 100644
--- a/astroid/_ast.py
+++ b/astroid/_ast.py
@@ -51,7 +51,7 @@ class ParserModule(NamedTuple):
def parse_function_type_comment(type_comment: str) -> FunctionType | None:
- """Given a correct type comment, obtain a FunctionType object"""
+ """Given a correct type comment, obtain a FunctionType object."""
if _ast_py3 is None:
return None
diff --git a/astroid/arguments.py b/astroid/arguments.py
index 875c7ce2..8ac83dcb 100644
--- a/astroid/arguments.py
+++ b/astroid/arguments.py
@@ -12,7 +12,7 @@ from astroid.util import Uninferable
class CallSite:
- """Class for understanding arguments passed into a call site
+ """Class for understanding arguments passed into a call site.
It needs a call context, which contains the arguments and the
keyword arguments that were passed into a given call site.
@@ -65,7 +65,7 @@ class CallSite:
return cls(callcontext, context=context)
def has_invalid_arguments(self):
- """Check if in the current CallSite were passed *invalid* arguments
+ """Check if in the current CallSite were passed *invalid* arguments.
This can mean multiple things. For instance, if an unpacking
of an invalid object was passed, then this method will return True.
@@ -75,7 +75,7 @@ class CallSite:
return len(self.positional_arguments) != len(self._unpacked_args)
def has_invalid_keywords(self) -> bool:
- """Check if in the current CallSite were passed *invalid* keyword arguments
+ """Check if in the current CallSite were passed *invalid* keyword arguments.
For instance, unpacking a dictionary with integer keys is invalid
(**{1:2}), because the keys must be strings, which will make this
@@ -154,7 +154,7 @@ class CallSite:
return values
def infer_argument(self, funcnode, name, context): # noqa: C901
- """infer a function argument value according to the call context
+ """Infer a function argument value according to the call context.
Arguments:
funcnode: The function being called.
diff --git a/astroid/bases.py b/astroid/bases.py
index bf99ddce..d6c830c7 100644
--- a/astroid/bases.py
+++ b/astroid/bases.py
@@ -103,7 +103,7 @@ def _is_property(meth, context: InferenceContext | None = None) -> bool:
class Proxy:
- """a simple proxy object
+ """A simple proxy object.
Note:
@@ -218,7 +218,9 @@ def _infer_method_result_truth(instance, method_name, context):
class BaseInstance(Proxy):
- """An instance base class, which provides lookup methods for potential instances."""
+ """An instance base class, which provides lookup methods for potential
+ instances.
+ """
special_attributes = None
@@ -252,7 +254,7 @@ class BaseInstance(Proxy):
return values
def igetattr(self, name, context: InferenceContext | None = None):
- """inferred getattr"""
+ """Inferred getattr."""
if not context:
context = InferenceContext()
try:
@@ -283,7 +285,7 @@ class BaseInstance(Proxy):
raise InferenceError(**vars(error)) from error
def _wrap_attr(self, attrs, context: InferenceContext | None = None):
- """wrap bound methods of attrs in a InstanceMethod proxies"""
+ """Wrap bound methods of attrs in a InstanceMethod proxies."""
for attr in attrs:
if isinstance(attr, UnboundMethod):
if _is_property(attr):
@@ -301,7 +303,7 @@ class BaseInstance(Proxy):
def infer_call_result(
self, caller: nodes.Call | Proxy, context: InferenceContext | None = None
):
- """infer what a class instance is returning when called"""
+ """Infer what a class instance is returning when called."""
context = bind_context_to_node(context, self)
inferred = False
@@ -357,7 +359,7 @@ class Instance(BaseInstance):
return "Instance of"
def bool_value(self, context: InferenceContext | None = None):
- """Infer the truth value for an Instance
+ """Infer the truth value for an Instance.
The truth value of an instance is determined by these conditions:
@@ -403,7 +405,7 @@ class Instance(BaseInstance):
class UnboundMethod(Proxy):
- """a special node representing a method not bound to an instance"""
+ """A special node representing a method not bound to an instance."""
# pylint: disable=unnecessary-lambda
special_attributes = lazy_descriptor(lambda: objectmodel.UnboundMethodModel())
@@ -485,7 +487,7 @@ class UnboundMethod(Proxy):
class BoundMethod(UnboundMethod):
- """a special node representing a method bound to an instance"""
+ """A special node representing a method bound to an instance."""
# pylint: disable=unnecessary-lambda
special_attributes = lazy_descriptor(lambda: objectmodel.BoundMethodModel())
@@ -614,7 +616,7 @@ class BoundMethod(UnboundMethod):
class Generator(BaseInstance):
- """a special node representing a generator.
+ """A special node representing a generator.
Proxied class is set once for all in raw_building.
"""
@@ -654,7 +656,7 @@ class Generator(BaseInstance):
class AsyncGenerator(Generator):
- """Special node representing an async generator"""
+ """Special node representing an async generator."""
def pytype(self) -> Literal["builtins.async_generator"]:
return "builtins.async_generator"
diff --git a/astroid/brain/brain_boto3.py b/astroid/brain/brain_boto3.py
index 5be223b4..d9698b8a 100644
--- a/astroid/brain/brain_boto3.py
+++ b/astroid/brain/brain_boto3.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 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
@@ -11,7 +11,7 @@ BOTO_SERVICE_FACTORY_QUALIFIED_NAME = "boto3.resources.base.ServiceResource"
def service_request_transform(node):
- """Transform ServiceResource to look like dynamic classes"""
+ """Transform ServiceResource to look like dynamic classes."""
code = """
def __getattr__(self, attr):
return 0
diff --git a/astroid/brain/brain_builtin_inference.py b/astroid/brain/brain_builtin_inference.py
index 767b65e0..b51d63a5 100644
--- a/astroid/brain/brain_builtin_inference.py
+++ b/astroid/brain/brain_builtin_inference.py
@@ -108,7 +108,7 @@ class whatever(object):
def _extend_string_class(class_node, code, rvalue):
- """function to extend builtin str/unicode class"""
+ """Function to extend builtin str/unicode class."""
code = code.format(rvalue=rvalue)
fake = AstroidBuilder(AstroidManager()).string_build(code)["whatever"]
for method in fake.mymethods():
@@ -459,7 +459,7 @@ def _infer_getattr_args(node, context):
def infer_getattr(node, context: InferenceContext | None = None):
- """Understand getattr calls
+ """Understand getattr calls.
If one of the arguments is an Uninferable object, then the
result will be an Uninferable object. Otherwise, the normal attribute
@@ -487,7 +487,7 @@ def infer_getattr(node, context: InferenceContext | None = None):
def infer_hasattr(node, context: InferenceContext | None = None):
- """Understand hasattr calls
+ """Understand hasattr calls.
This always guarantees three possible outcomes for calling
hasattr: Const(False) when we are sure that the object
@@ -514,7 +514,7 @@ def infer_hasattr(node, context: InferenceContext | None = None):
def infer_callable(node, context: InferenceContext | None = None):
- """Understand callable calls
+ """Understand callable calls.
This follows Python's semantics, where an object
is callable if it provides an attribute __call__,
@@ -538,7 +538,7 @@ def infer_callable(node, context: InferenceContext | None = None):
def infer_property(
node: nodes.Call, context: InferenceContext | None = None
) -> objects.Property:
- """Understand `property` class
+ """Understand `property` class.
This only infers the output of `property`
call, not the arguments themselves.
@@ -636,7 +636,7 @@ def _infer_object__new__decorator(node, context: InferenceContext | None = None)
def _infer_object__new__decorator_check(node) -> bool:
- """Predicate before inference_tip
+ """Predicate before inference_tip.
Check if the given ClassDef has an @object.__new__ decorator
"""
@@ -651,7 +651,7 @@ def _infer_object__new__decorator_check(node) -> bool:
def infer_issubclass(callnode, context: InferenceContext | None = None):
- """Infer issubclass() calls
+ """Infer issubclass() calls.
:param nodes.Call callnode: an `issubclass` call
:param InferenceContext context: the context for the inference
@@ -694,7 +694,7 @@ def infer_issubclass(callnode, context: InferenceContext | None = None):
def infer_isinstance(callnode, context: InferenceContext | None = None):
- """Infer isinstance calls
+ """Infer isinstance calls.
:param nodes.Call callnode: an isinstance call
:rtype nodes.Const: Boolean Const value of isinstance call
@@ -756,7 +756,7 @@ def _class_or_tuple_to_container(node, context: InferenceContext | None = None):
def infer_len(node, context: InferenceContext | None = None):
- """Infer length calls
+ """Infer length calls.
:param nodes.Call node: len call to infer
:param context.InferenceContext: node context
@@ -779,7 +779,7 @@ def infer_len(node, context: InferenceContext | None = None):
def infer_str(node, context: InferenceContext | None = None):
- """Infer str() calls
+ """Infer str() calls.
:param nodes.Call node: str() call to infer
:param context.InferenceContext: node context
@@ -795,7 +795,7 @@ def infer_str(node, context: InferenceContext | None = None):
def infer_int(node, context: InferenceContext | None = None):
- """Infer int() calls
+ """Infer int() calls.
:param nodes.Call node: int() call to infer
:param context.InferenceContext: node context
@@ -827,7 +827,7 @@ def infer_int(node, context: InferenceContext | None = None):
def infer_dict_fromkeys(node, context: InferenceContext | None = None):
- """Infer dict.fromkeys
+ """Infer dict.fromkeys.
:param nodes.Call node: dict.fromkeys() call to infer
:param context.InferenceContext context: node context
diff --git a/astroid/brain/brain_dataclasses.py b/astroid/brain/brain_dataclasses.py
index c54c2931..7ad62848 100644
--- a/astroid/brain/brain_dataclasses.py
+++ b/astroid/brain/brain_dataclasses.py
@@ -3,14 +3,13 @@
# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt
"""
-Astroid hook for the dataclasses library
+Astroid hook for the dataclasses library.
Support built-in dataclasses, pydantic.dataclasses, and marshmallow_dataclass-annotated
dataclasses. References:
- https://docs.python.org/3/library/dataclasses.html
- https://pydantic-docs.helpmanual.io/usage/dataclasses/
- https://lovasoa.github.io/marshmallow_dataclass/
-
"""
from __future__ import annotations
@@ -61,7 +60,7 @@ def is_decorated_with_dataclass(
def dataclass_transform(node: nodes.ClassDef) -> None:
- """Rewrite a dataclass to be easily understood by pylint"""
+ """Rewrite a dataclass to be easily understood by pylint."""
node.is_dataclass = True
for assign_node in _get_dataclass_attributes(node):
@@ -170,7 +169,9 @@ def _check_generate_dataclass_init(node: nodes.ClassDef) -> bool:
def _find_arguments_from_base_classes(
node: nodes.ClassDef, skippable_names: set[str]
) -> tuple[str, str]:
- """Iterate through all bases and add them to the list of arguments to add to the init."""
+ """Iterate through all bases and add them to the list of arguments to add to the
+ init.
+ """
pos_only_store: dict[str, tuple[str | None, str | None]] = {}
kw_only_store: dict[str, tuple[str | None, str | None]] = {}
# See TODO down below
@@ -482,7 +483,8 @@ def _looks_like_dataclass_field_call(
def _get_field_default(field_call: nodes.Call) -> _FieldDefaultReturn:
- """Return a the default value of a field call, and the corresponding keyword argument name.
+ """Return a the default value of a field call, and the corresponding keyword
+ argument name.
field(default=...) results in the ... node
field(default_factory=...) results in a Call node with func ... and no arguments
diff --git a/astroid/brain/brain_dateutil.py b/astroid/brain/brain_dateutil.py
index 0d27135a..4579e026 100644
--- a/astroid/brain/brain_dateutil.py
+++ b/astroid/brain/brain_dateutil.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 dateutil"""
+"""Astroid hooks for dateutil."""
import textwrap
diff --git a/astroid/brain/brain_functools.py b/astroid/brain/brain_functools.py
index bff04e98..ffdbc888 100644
--- a/astroid/brain/brain_functools.py
+++ b/astroid/brain/brain_functools.py
@@ -137,7 +137,7 @@ def _looks_like_lru_cache(node) -> bool:
def _looks_like_functools_member(node, member) -> bool:
- """Check if the given Call node is a functools.partial call"""
+ """Check if the given Call node is a functools.partial call."""
if isinstance(node.func, Name):
return node.func.name == member
if isinstance(node.func, Attribute):
diff --git a/astroid/brain/brain_hypothesis.py b/astroid/brain/brain_hypothesis.py
index 39651135..5d68f732 100644
--- a/astroid/brain/brain_hypothesis.py
+++ b/astroid/brain/brain_hypothesis.py
@@ -15,7 +15,6 @@ defined using the `@hypothesis.strategies.composite` decorator. For example:
return draw(st.integers())
a_strategy()
-
"""
from astroid.manager import AstroidManager
from astroid.nodes.scoped_nodes import FunctionDef
diff --git a/astroid/brain/brain_io.py b/astroid/brain/brain_io.py
index 9957ce94..c0ae6fe1 100644
--- a/astroid/brain/brain_io.py
+++ b/astroid/brain/brain_io.py
@@ -13,7 +13,9 @@ BufferedWriter = "BufferedWriter"
def _generic_io_transform(node, name, cls):
- """Transform the given name, by adding the given *class* as a member of the node."""
+ """Transform the given name, by adding the given *class* as a member of the
+ node.
+ """
io_module = AstroidManager().ast_from_module_name("_io")
attribute_object = io_module[cls]
diff --git a/astroid/brain/brain_namedtuple_enum.py b/astroid/brain/brain_namedtuple_enum.py
index 5be9eeb0..ed80e783 100644
--- a/astroid/brain/brain_namedtuple_enum.py
+++ b/astroid/brain/brain_namedtuple_enum.py
@@ -160,7 +160,7 @@ def infer_func_form(
def _has_namedtuple_base(node):
- """Predicate for class inference tip
+ """Predicate for class inference tip.
:type node: ClassDef
:rtype: bool
@@ -185,7 +185,7 @@ _looks_like_typing_namedtuple = functools.partial(_looks_like, name="NamedTuple"
def infer_named_tuple(
node: nodes.Call, context: InferenceContext | None = None
) -> Iterator[nodes.ClassDef]:
- """Specific inference function for namedtuple Call node"""
+ """Specific inference function for namedtuple Call node."""
tuple_base_name: list[nodes.NodeNG] = [nodes.Name(name="tuple", parent=node.root())]
class_node, name, attributes = infer_func_form(
node, tuple_base_name, context=context
@@ -464,7 +464,7 @@ def infer_enum_class(node: nodes.ClassDef) -> nodes.ClassDef:
def infer_typing_namedtuple_class(class_node, context: InferenceContext | None = None):
- """Infer a subclass of typing.NamedTuple"""
+ """Infer a subclass of typing.NamedTuple."""
# Check if it has the corresponding bases
annassigns_fields = [
annassign.target.name
diff --git a/astroid/brain/brain_numpy_ma.py b/astroid/brain/brain_numpy_ma.py
index f1a7aa0b..8654f907 100644
--- a/astroid/brain/brain_numpy_ma.py
+++ b/astroid/brain/brain_numpy_ma.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 numpy ma module"""
+"""Astroid hooks for numpy ma module."""
from astroid.brain.helpers import register_module_extender
from astroid.builder import parse
@@ -11,7 +11,7 @@ from astroid.manager import AstroidManager
def numpy_ma_transform():
"""
- Infer the call of various numpy.ma functions
+ Infer the call of various numpy.ma functions.
:param node: node to infer
:param context: inference context
diff --git a/astroid/brain/brain_numpy_utils.py b/astroid/brain/brain_numpy_utils.py
index 3091e379..b9e5d5f3 100644
--- a/astroid/brain/brain_numpy_utils.py
+++ b/astroid/brain/brain_numpy_utils.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
-"""Different utilities for the numpy brains"""
+"""Different utilities for the numpy brains."""
from __future__ import annotations
@@ -15,9 +15,7 @@ NUMPY_VERSION_TYPE_HINTS_SUPPORT = ("1", "20", "0")
def numpy_supports_type_hints() -> bool:
- """
- Returns True if numpy supports type hints
- """
+ """Returns True if numpy supports type hints."""
np_ver = _get_numpy_version()
return np_ver and np_ver > NUMPY_VERSION_TYPE_HINTS_SUPPORT
diff --git a/astroid/brain/brain_re.py b/astroid/brain/brain_re.py
index 76ad16df..5f05d473 100644
--- a/astroid/brain/brain_re.py
+++ b/astroid/brain/brain_re.py
@@ -75,7 +75,10 @@ def _looks_like_pattern_or_match(node: nodes.Call) -> bool:
def infer_pattern_match(node: nodes.Call, ctx: context.InferenceContext | None = None):
- """Infer re.Pattern and re.Match as classes. For PY39+ add `__class_getitem__`."""
+ """Infer re.Pattern and re.Match as classes.
+
+ For PY39+ add `__class_getitem__`.
+ """
class_def = nodes.ClassDef(
name=node.parent.targets[0].name,
lineno=node.lineno,
diff --git a/astroid/brain/brain_regex.py b/astroid/brain/brain_regex.py
index 498e2a3e..9d149639 100644
--- a/astroid/brain/brain_regex.py
+++ b/astroid/brain/brain_regex.py
@@ -74,7 +74,10 @@ def _looks_like_pattern_or_match(node: nodes.Call) -> bool:
def infer_pattern_match(node: nodes.Call, ctx: context.InferenceContext | None = None):
- """Infer regex.Pattern and regex.Match as classes. For PY39+ add `__class_getitem__`."""
+ """Infer regex.Pattern and regex.Match as classes.
+
+ For PY39+ add `__class_getitem__`.
+ """
class_def = nodes.ClassDef(
name=node.parent.targets[0].name,
lineno=node.lineno,
diff --git a/astroid/brain/brain_responses.py b/astroid/brain/brain_responses.py
index 0fb0e426..100f3831 100644
--- a/astroid/brain/brain_responses.py
+++ b/astroid/brain/brain_responses.py
@@ -9,7 +9,6 @@ It might need to be manually updated from the public methods of
:class:`responses.RequestsMock`.
See: https://github.com/getsentry/responses/blob/master/responses.py
-
"""
from astroid.brain.helpers import register_module_extender
from astroid.builder import parse
diff --git a/astroid/brain/brain_six.py b/astroid/brain/brain_six.py
index 5b704ce4..a35cfdd6 100644
--- a/astroid/brain/brain_six.py
+++ b/astroid/brain/brain_six.py
@@ -167,7 +167,7 @@ def _looks_like_decorated_with_six_add_metaclass(node) -> bool:
def transform_six_add_metaclass(node): # pylint: disable=inconsistent-return-statements
- """Check if the given class node is decorated with *six.add_metaclass*
+ """Check if the given class node is decorated with *six.add_metaclass*.
If so, inject its argument as the metaclass of the underlying class.
"""
@@ -213,7 +213,7 @@ def _looks_like_nested_from_six_with_metaclass(node) -> bool:
def transform_six_with_metaclass(node):
- """Check if the given class node is defined with *six.with_metaclass*
+ """Check if the given class node is defined with *six.with_metaclass*.
If so, inject its argument as the metaclass of the underlying class.
"""
diff --git a/astroid/brain/brain_type.py b/astroid/brain/brain_type.py
index e261d081..e63f9733 100644
--- a/astroid/brain/brain_type.py
+++ b/astroid/brain/brain_type.py
@@ -31,7 +31,7 @@ from astroid.manager import AstroidManager
def _looks_like_type_subscript(node) -> bool:
"""
- Try to figure out if a Name node is used inside a type related subscript
+ Try to figure out if a Name node is used inside a type related subscript.
:param node: node to check
:type node: astroid.nodes.node_classes.NodeNG
@@ -44,7 +44,7 @@ def _looks_like_type_subscript(node) -> bool:
def infer_type_sub(node, context: InferenceContext | None = None):
"""
- Infer a type[...] subscript
+ Infer a type[...] subscript.
:param node: node to infer
:type node: astroid.nodes.node_classes.NodeNG
diff --git a/astroid/brain/brain_typing.py b/astroid/brain/brain_typing.py
index ea22100c..15059f44 100644
--- a/astroid/brain/brain_typing.py
+++ b/astroid/brain/brain_typing.py
@@ -113,7 +113,7 @@ def looks_like_typing_typevar_or_newtype(node) -> bool:
def infer_typing_typevar_or_newtype(node, context_itton=None):
- """Infer a typing.TypeVar(...) or typing.NewType(...) call"""
+ """Infer a typing.TypeVar(...) or typing.NewType(...) call."""
try:
func = next(node.func.infer(context=context_itton))
except (InferenceError, StopIteration) as exc:
@@ -133,7 +133,7 @@ def infer_typing_typevar_or_newtype(node, context_itton=None):
def _looks_like_typing_subscript(node) -> bool:
- """Try to figure out if a Subscript node *might* be a typing-related subscript"""
+ """Try to figure out if a Subscript node *might* be a typing-related subscript."""
if isinstance(node, Name):
return node.name in TYPING_MEMBERS
if isinstance(node, Attribute):
@@ -146,7 +146,7 @@ def _looks_like_typing_subscript(node) -> bool:
def infer_typing_attr(
node: Subscript, ctx: context.InferenceContext | None = None
) -> Iterator[ClassDef]:
- """Infer a typing.X[...] subscript"""
+ """Infer a typing.X[...] subscript."""
try:
value = next(node.value.infer()) # type: ignore[union-attr] # value shouldn't be None for Subscript.
except (InferenceError, StopIteration) as exc:
@@ -216,6 +216,7 @@ def infer_typedDict( # pylint: disable=invalid-name
def _looks_like_typing_alias(node: Call) -> bool:
"""
Returns True if the node corresponds to a call to _alias function.
+
For example :
MutableSet = _alias(collections.abc.MutableSet, T)
@@ -233,9 +234,7 @@ def _looks_like_typing_alias(node: Call) -> bool:
def _forbid_class_getitem_access(node: ClassDef) -> None:
- """
- Disable the access to __class_getitem__ method for the node in parameters
- """
+ """Disable the access to __class_getitem__ method for the node in parameters."""
def full_raiser(origin_func, attr, *args, **kwargs):
"""
@@ -321,7 +320,6 @@ def _looks_like_special_alias(node: Call) -> bool:
PY37: Tuple = _VariadicGenericAlias(tuple, (), inst=False, special=True)
PY39: Tuple = _TupleType(tuple, -1, inst=False, name='Tuple')
-
PY37: Callable = _VariadicGenericAlias(collections.abc.Callable, (), special=True)
PY39: Callable = _CallableType(collections.abc.Callable, 2)
"""
@@ -384,7 +382,7 @@ def _looks_like_typing_cast(node: Call) -> bool:
def infer_typing_cast(
node: Call, ctx: context.InferenceContext | None = None
) -> Iterator[NodeNG]:
- """Infer call to cast() returning same type as casted-from var"""
+ """Infer call to cast() returning same type as casted-from var."""
if not isinstance(node.func, (Name, Attribute)):
raise UseInferenceDefault
diff --git a/astroid/builder.py b/astroid/builder.py
index 72f63c93..a03bd987 100644
--- a/astroid/builder.py
+++ b/astroid/builder.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
-"""The AstroidBuilder makes astroid from living object and / or from _ast
+"""The AstroidBuilder makes astroid from living object and / or from _ast.
The builder is not thread safe and can't be used to parse different sources
at the same time.
@@ -107,7 +107,7 @@ class AstroidBuilder(raw_building.InspectBuilder):
return node
def file_build(self, path: str, modname: str | None = None) -> nodes.Module:
- """Build astroid from a source code file (i.e. from an ast)
+ """Build astroid from a source code file (i.e. from an ast).
*path* is expected to be a python source file
"""
@@ -155,7 +155,7 @@ class AstroidBuilder(raw_building.InspectBuilder):
def _post_build(
self, module: nodes.Module, builder: rebuilder.TreeRebuilder, encoding: str
) -> nodes.Module:
- """Handles encoding and delayed nodes after a module has been built"""
+ """Handles encoding and delayed nodes after a module has been built."""
module.file_encoding = encoding
self._manager.cache_module(module)
# post tree building steps after we stored the module in the cache:
@@ -176,7 +176,7 @@ class AstroidBuilder(raw_building.InspectBuilder):
def _data_build(
self, data: str, modname: str, path: str | None
) -> tuple[nodes.Module, rebuilder.TreeRebuilder]:
- """Build tree node from data and add some informations"""
+ """Build tree node from data and add some informations."""
try:
node, parser_module = _parse_string(data, type_comments=True)
except (TypeError, ValueError, SyntaxError) as exc:
@@ -205,7 +205,7 @@ class AstroidBuilder(raw_building.InspectBuilder):
return module, builder
def add_from_names_to_locals(self, node: nodes.ImportFrom) -> None:
- """Store imported names to the locals
+ """Store imported names to the locals.
Resort the locals if coming from a delayed node
"""
@@ -231,7 +231,7 @@ class AstroidBuilder(raw_building.InspectBuilder):
sort_locals(node.parent.scope().locals[asname or name]) # type: ignore[arg-type]
def delayed_assattr(self, node: nodes.AssignAttr) -> None:
- """Visit a AssAttr node
+ """Visit a AssAttr node.
This adds name to locals and handle members definition.
"""
@@ -294,7 +294,7 @@ def parse(
path: str | None = None,
apply_transforms: bool = True,
) -> nodes.Module:
- """Parses a source string in order to obtain an astroid AST from it
+ """Parses a source string in order to obtain an astroid AST from it.
:param str code: The code for the module.
:param str module_name: The name for the module, if any
diff --git a/astroid/context.py b/astroid/context.py
index 221fd84f..b4699648 100644
--- a/astroid/context.py
+++ b/astroid/context.py
@@ -26,7 +26,7 @@ def _invalidate_cache() -> None:
class InferenceContext:
- """Provide context for inference
+ """Provide context for inference.
Store already inferred nodes to save time
Account for already visited nodes to stop infinite recursion
@@ -93,7 +93,7 @@ class InferenceContext:
@property
def nodes_inferred(self) -> int:
"""
- Number of nodes inferred in this context and all its clones/descendents
+ Number of nodes inferred in this context and all its clones/descendents.
Wrap inner value in a mutable cell to allow for mutating a class
variable in the presence of __slots__
@@ -107,7 +107,7 @@ class InferenceContext:
@property
def inferred(self) -> _InferenceCache:
"""
- Inferred node contexts to their mapped results
+ Inferred node contexts to their mapped results.
Currently the key is ``(node, lookupname, callcontext, boundnode)``
and the value is tuple of the inferred results
@@ -115,12 +115,13 @@ class InferenceContext:
return _INFERENCE_CACHE
def push(self, node) -> bool:
- """Push node into inference path
+ """Push node into inference path.
:return: Whether node is already in context path.
Allows one to see if the given node has already
- been looked at for this inference context"""
+ been looked at for this inference context
+ """
name = self.lookupname
if (node, name) in self.path:
return True
@@ -129,11 +130,12 @@ class InferenceContext:
return False
def clone(self) -> InferenceContext:
- """Clone inference path
+ """Clone inference path.
For example, each side of a binary operation (BinOp)
starts with the same context but diverge as each side is inferred
- so the InferenceContext will need be cloned"""
+ so the InferenceContext will need be cloned
+ """
# XXX copy lookupname/callcontext ?
clone = InferenceContext(self.path.copy(), nodes_inferred=self._nodes_inferred)
clone.callcontext = self.callcontext
@@ -177,7 +179,7 @@ class CallContext:
def copy_context(context: InferenceContext | None) -> InferenceContext:
- """Clone a context if given, or return a fresh contexxt"""
+ """Clone a context if given, or return a fresh context."""
if context is not None:
return context.clone()
diff --git a/astroid/decorators.py b/astroid/decorators.py
index 7ce157b9..b99803a2 100644
--- a/astroid/decorators.py
+++ b/astroid/decorators.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
-""" A few useful function/method decorators."""
+"""A few useful function/method decorators."""
from __future__ import annotations
@@ -90,7 +90,7 @@ class cachedproperty:
def path_wrapper(func):
- """return the given infer function wrapped to handle the path
+ """Return the given infer function wrapped to handle the path.
Used to stop inference if the node has already been looked
at for a given `InferenceContext` to prevent infinite recursion
@@ -100,7 +100,7 @@ def path_wrapper(func):
def wrapped(
node, context: InferenceContext | None = None, _func=func, **kwargs
) -> Generator:
- """wrapper function handling context"""
+ """Wrapper function handling context."""
if context is None:
context = InferenceContext()
if context.push(node):
@@ -263,7 +263,9 @@ else:
def deprecate_default_argument_values(
astroid_version: str = "3.0", **arguments: str
) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]:
- """Passthrough decorator to improve performance if DeprecationWarnings are disabled."""
+ """Passthrough decorator to improve performance if DeprecationWarnings are
+ disabled.
+ """
def deco(func: Callable[_P, _R]) -> Callable[_P, _R]:
"""Decorator function."""
@@ -274,7 +276,9 @@ else:
def deprecate_arguments(
astroid_version: str = "3.0", **arguments: str
) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]:
- """Passthrough decorator to improve performance if DeprecationWarnings are disabled."""
+ """Passthrough decorator to improve performance if DeprecationWarnings are
+ disabled.
+ """
def deco(func: Callable[_P, _R]) -> Callable[_P, _R]:
"""Decorator function."""
diff --git a/astroid/exceptions.py b/astroid/exceptions.py
index 412b0ac7..fe6d43ba 100644
--- a/astroid/exceptions.py
+++ b/astroid/exceptions.py
@@ -2,8 +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 contains exceptions used in the astroid library
-"""
+"""This module contains exceptions used in the astroid library."""
from __future__ import annotations
@@ -49,7 +48,7 @@ __all__ = (
class AstroidError(Exception):
- """base exception class for all astroid related exceptions
+ """Base exception class for all astroid related exceptions.
AstroidError and its subclasses are structured, intended to hold
objects representing state when the exception is thrown. Field
@@ -73,7 +72,7 @@ class AstroidError(Exception):
class AstroidBuildingError(AstroidError):
- """exception class when we are unable to build an astroid representation
+ """Exception class when we are unable to build an astroid representation.
Standard attributes:
modname: Name of the module that AST construction failed for.
@@ -140,8 +139,8 @@ class AstroidSyntaxError(AstroidBuildingError):
class NoDefault(AstroidError):
- """raised by function's `default_value` method when an argument has
- no default value
+ """Raised by function's `default_value` method when an argument has
+ no default value.
Standard attributes:
func: Function node.
@@ -228,7 +227,7 @@ class SuperError(ResolveError):
class InferenceError(ResolveError): # pylint: disable=too-many-instance-attributes
- """raised when we are unable to infer a node
+ """Raised when we are unable to infer a node.
Standard attributes:
node: The node inference was called on.
@@ -332,13 +331,15 @@ class AttributeInferenceError(ResolveError):
class UseInferenceDefault(Exception):
- """exception to be raised in custom inference function to indicate that it
- should go back to the default behaviour
+ """Exception to be raised in custom inference function to indicate that it
+ should go back to the default behaviour.
"""
class _NonDeducibleTypeHierarchy(Exception):
- """Raised when is_subtype / is_supertype can't deduce the relation between two types."""
+ """Raised when is_subtype / is_supertype can't deduce the relation between two
+ types.
+ """
class AstroidIndexError(AstroidError):
@@ -380,14 +381,14 @@ class AstroidValueError(AstroidError):
class InferenceOverwriteError(AstroidError):
- """Raised when an inference tip is overwritten
+ """Raised when an inference tip is overwritten.
Currently only used for debugging.
"""
class ParentMissingError(AstroidError):
- """Raised when a node which is expected to have a parent attribute is missing one
+ """Raised when a node which is expected to have a parent attribute is missing one.
Standard attributes:
target: The node for which the parent lookup failed.
diff --git a/astroid/filter_statements.py b/astroid/filter_statements.py
index 3b94ecc1..002078d7 100644
--- a/astroid/filter_statements.py
+++ b/astroid/filter_statements.py
@@ -2,7 +2,9 @@
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt
-"""_filter_stmts and helper functions. This method gets used in LocalsDictnodes.NodeNG._scope_lookup.
+"""_filter_stmts and helper functions.
+
+This method gets used in LocalsDictnodes.NodeNG._scope_lookup.
It is not considered public.
"""
@@ -27,12 +29,12 @@ def _get_filtered_node_statements(
def _is_from_decorator(node) -> bool:
- """Return whether the given node is the child of a decorator"""
+ """Return whether the given node is the child of a decorator."""
return any(isinstance(parent, nodes.Decorators) for parent in node.node_ancestors())
def _get_if_statement_ancestor(node: nodes.NodeNG) -> nodes.If | None:
- """Return the first parent node that is an If node (or None)"""
+ """Return the first parent node that is an If node (or None)."""
for parent in node.node_ancestors():
if isinstance(parent, nodes.If):
return parent
diff --git a/astroid/helpers.py b/astroid/helpers.py
index a4a5cca2..8ab01b81 100644
--- a/astroid/helpers.py
+++ b/astroid/helpers.py
@@ -2,9 +2,7 @@
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt
-"""
-Various helper utilities.
-"""
+"""Various helper utilities."""
from __future__ import annotations
@@ -76,7 +74,7 @@ def _object_type(
def object_type(
node: SuccessfulInferenceResult, context: InferenceContext | None = None
) -> InferenceResult | None:
- """Obtain the type of the given node
+ """Obtain the type of the given node.
This is used to implement the ``type`` builtin, which means that it's
used for inferring type calls, as well as used in a couple of other places
@@ -124,7 +122,7 @@ def _object_type_is_subclass(
def object_isinstance(node, class_or_seq, context: InferenceContext | None = None):
- """Check if a node 'isinstance' any node in class_or_seq
+ """Check if a node 'isinstance' any node in class_or_seq.
:param node: A given node
:param class_or_seq: Union[nodes.NodeNG, Sequence[nodes.NodeNG]]
@@ -139,7 +137,7 @@ def object_isinstance(node, class_or_seq, context: InferenceContext | None = Non
def object_issubclass(node, class_or_seq, context: InferenceContext | None = None):
- """Check if a type is a subclass of any node in class_or_seq
+ """Check if a type is a subclass of any node in class_or_seq.
:param node: A given node
:param class_or_seq: Union[Nodes.NodeNG, Sequence[nodes.NodeNG]]
@@ -243,7 +241,7 @@ def class_instance_as_index(node: SuccessfulInferenceResult) -> nodes.Const | No
def object_len(node, context: InferenceContext | None = None):
- """Infer length of given node object
+ """Infer length of given node object.
:param Union[nodes.ClassDef, nodes.Instance] node:
:param node: Node to infer length of
diff --git a/astroid/inference.py b/astroid/inference.py
index b3a0c4a1..e8fec289 100644
--- a/astroid/inference.py
+++ b/astroid/inference.py
@@ -2,8 +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 contains a set of functions to handle inference on astroid trees
-"""
+"""This module contains a set of functions to handle inference on astroid trees."""
from __future__ import annotations
@@ -70,7 +69,7 @@ GetFlowFactory = typing.Callable[
def infer_end(
self: _T, context: InferenceContext | None = None, **kwargs: Any
) -> Iterator[_T]:
- """Inference's end for nodes that yield themselves on inference
+ """Inference's end for nodes that yield themselves on inference.
These are objects for which inference does not have any semantic,
such as Module or Consts.
@@ -90,7 +89,7 @@ nodes.Slice._infer = infer_end # type: ignore[assignment]
def _infer_sequence_helper(
node: _BaseContainerT, context: InferenceContext | None = None
) -> list[SuccessfulInferenceResult]:
- """Infer all values based on _BaseContainer.elts"""
+ """Infer all values based on _BaseContainer.elts."""
values = []
for elt in node.elts:
@@ -153,7 +152,7 @@ def _update_with_replacement(
lhs_dict: dict[SuccessfulInferenceResult, SuccessfulInferenceResult],
rhs_dict: dict[SuccessfulInferenceResult, SuccessfulInferenceResult],
) -> dict[SuccessfulInferenceResult, SuccessfulInferenceResult]:
- """Delete nodes that equate to duplicate keys
+ """Delete nodes that equate to duplicate keys.
Since an astroid node doesn't 'equal' another node with the same value,
this function uses the as_string method to make sure duplicate keys
@@ -178,7 +177,7 @@ def _update_with_replacement(
def _infer_map(
node: nodes.Dict, context: InferenceContext | None
) -> dict[SuccessfulInferenceResult, SuccessfulInferenceResult]:
- """Infer all values based on Dict.items"""
+ """Infer all values based on Dict.items."""
values: dict[SuccessfulInferenceResult, SuccessfulInferenceResult] = {}
for name, value in node.items:
if isinstance(name, nodes.DictUnpack):
@@ -227,7 +226,7 @@ def infer_name(
context: InferenceContext | None = None,
**kwargs: Any,
) -> Generator[InferenceResult, None, None]:
- """infer a Name: use name lookup rules"""
+ """Infer a Name: use name lookup rules."""
frame, stmts = self.lookup(self.name)
if not stmts:
# Try to see if the name is enclosed in a nested function
@@ -261,7 +260,7 @@ nodes.AssignName.infer_lhs = infer_name # won't work with a path wrapper
def infer_call(
self: nodes.Call, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[InferenceResult, None, InferenceErrorInfo]:
- """infer a Call node by trying to guess what the function returns"""
+ """Infer a Call node by trying to guess what the function returns."""
callcontext = copy_context(context)
callcontext.boundnode = None
if context is not None:
@@ -293,7 +292,7 @@ def infer_import(
asname: bool = True,
**kwargs: Any,
) -> Generator[nodes.Module, None, None]:
- """infer an Import node: return the imported module/object"""
+ """Infer an Import node: return the imported module/object."""
context = context or InferenceContext()
name = context.lookupname
if name is None:
@@ -319,7 +318,7 @@ def infer_import_from(
asname: bool = True,
**kwargs: Any,
) -> Generator[InferenceResult, None, None]:
- """infer a ImportFrom node: return the imported module/object"""
+ """Infer a ImportFrom node: return the imported module/object."""
context = context or InferenceContext()
name = context.lookupname
if name is None:
@@ -354,7 +353,7 @@ def infer_attribute(
context: InferenceContext | None = None,
**kwargs: Any,
) -> Generator[InferenceResult, None, InferenceErrorInfo]:
- """infer an Attribute node by using getattr on the associated object"""
+ """Infer an Attribute node by using getattr on the associated object."""
for owner in self.expr.infer(context):
if owner is util.Uninferable:
yield owner
@@ -414,7 +413,7 @@ _SUBSCRIPT_SENTINEL = object()
def infer_subscript(
self: nodes.Subscript, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[InferenceResult, None, InferenceErrorInfo | None]:
- """Inference for subscripts
+ """Inference for subscripts.
We're understanding if the index is a Const
or a slice, passing the result of inference
@@ -876,7 +875,7 @@ def _infer_binary_operation(
context: InferenceContext,
flow_factory: GetFlowFactory,
) -> Generator[InferenceResult | util.BadBinaryOperationMessage, None, None]:
- """Infer a binary operation between a left operand and a right operand
+ """Infer a binary operation between a left operand and a right operand.
This is used by both normal binary operations and augmented binary
operations, the only difference is the flow factory used.
@@ -1119,8 +1118,8 @@ def infer_assign(
context: InferenceContext | None = None,
**kwargs: Any,
) -> Generator[InferenceResult, None, None]:
- """infer a AssignName/AssignAttr: need to inspect the RHS part of the
- assign node
+ """Infer a AssignName/AssignAttr: need to inspect the RHS part of the
+ assign node.
"""
if isinstance(self.parent, nodes.AugAssign):
return self.parent.infer(context)
@@ -1173,7 +1172,7 @@ def _populate_context_lookup(call: nodes.Call, context: InferenceContext | None)
def infer_ifexp(
self: nodes.IfExp, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[InferenceResult, None, None]:
- """Support IfExp inference
+ """Support IfExp inference.
If we can't infer the truthiness of the condition, we default
to inferring both branches. Otherwise, we infer either branch
diff --git a/astroid/inference_tip.py b/astroid/inference_tip.py
index e4c54822..957cd043 100644
--- a/astroid/inference_tip.py
+++ b/astroid/inference_tip.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
-"""Transform utilities (filters and decorator)"""
+"""Transform utilities (filters and decorator)."""
from __future__ import annotations
@@ -32,7 +32,7 @@ def clear_inference_tip_cache() -> None:
def _inference_tip_cached(
func: InferFn, instance: None, args: typing.Any, kwargs: typing.Any
) -> Iterator[InferOptions]:
- """Cache decorator used for inference tips"""
+ """Cache decorator used for inference tips."""
node = args[0]
try:
result = _cache[func, node]
diff --git a/astroid/interpreter/_import/spec.py b/astroid/interpreter/_import/spec.py
index 05fec7ef..ecf330b0 100644
--- a/astroid/interpreter/_import/spec.py
+++ b/astroid/interpreter/_import/spec.py
@@ -44,7 +44,7 @@ class ModuleType(enum.Enum):
class ModuleSpec(NamedTuple):
- """Defines a class similar to PEP 420's ModuleSpec
+ """Defines a class similar to PEP 420's ModuleSpec.
A module spec defines a name of a module, its type, location
and where submodules can be found, if the module is a package.
@@ -71,7 +71,7 @@ class Finder:
processed: list[str],
submodule_path: Sequence[str] | None,
) -> ModuleSpec | None:
- """Find the given module
+ """Find the given module.
Each finder is responsible for each protocol of finding, as long as
they all return a ModuleSpec.
diff --git a/astroid/interpreter/dunder_lookup.py b/astroid/interpreter/dunder_lookup.py
index 8ec0e9fc..272d27ec 100644
--- a/astroid/interpreter/dunder_lookup.py
+++ b/astroid/interpreter/dunder_lookup.py
@@ -32,7 +32,7 @@ def _lookup_in_mro(node, name) -> list:
def lookup(node, name) -> list:
- """Lookup the given special method name in the given *node*
+ """Lookup the given special method name in the given *node*.
If the special method was found, then a list of attributes
will be returned. Otherwise, `astroid.AttributeInferenceError`
diff --git a/astroid/interpreter/objectmodel.py b/astroid/interpreter/objectmodel.py
index 5a12ef8d..491358aa 100644
--- a/astroid/interpreter/objectmodel.py
+++ b/astroid/interpreter/objectmodel.py
@@ -125,7 +125,7 @@ class ObjectModel:
return [o[LEN_OF_IMPL_PREFIX:] for o in dir(self) if o.startswith(IMPL_PREFIX)]
def lookup(self, name):
- """Look up the given *name* in the current model
+ """Look up the given *name* in the current model.
It should return an AST or an interpreter object,
but if the name is not found, then an AttributeInferenceError will be raised.
@@ -333,7 +333,9 @@ class FunctionModel(ObjectModel):
func = self._instance
class DescriptorBoundMethod(bases.BoundMethod):
- """Bound method which knows how to understand calling descriptor binding."""
+ """Bound method which knows how to understand calling descriptor
+ binding.
+ """
def implicit_parameters(self) -> Literal[0]:
# Different than BoundMethod since the signature
@@ -390,7 +392,7 @@ class FunctionModel(ObjectModel):
@property
def args(self):
- """Overwrite the underlying args to match those of the underlying func
+ """Overwrite the underlying args to match those of the underlying func.
Usually the underlying *func* is a function/method, as in:
@@ -514,7 +516,7 @@ class ClassModel(ObjectModel):
@property
def attr___subclasses__(self):
- """Get the subclasses of the underlying class
+ """Get the subclasses of the underlying class.
This looks only in the current module for retrieving the subclasses,
thus it might miss a couple of them.
@@ -841,7 +843,7 @@ class DictModel(ObjectModel):
class PropertyModel(ObjectModel):
- """Model for a builtin property"""
+ """Model for a builtin property."""
def _init_function(self, name):
function = nodes.FunctionDef(name=name, parent=self._instance)
diff --git a/astroid/manager.py b/astroid/manager.py
index 29de7cb5..8a5b05c7 100644
--- a/astroid/manager.py
+++ b/astroid/manager.py
@@ -101,7 +101,7 @@ class AstroidManager:
fallback: bool = True,
source: bool = False,
) -> nodes.Module:
- """given a module name, return the astroid object"""
+ """Given a module name, return the astroid object."""
try:
filepath = get_source_file(filepath, include_no_ext=True)
source = True
@@ -129,7 +129,9 @@ class AstroidManager:
def ast_from_string(
self, data: str, modname: str = "", filepath: str | None = None
) -> nodes.Module:
- """Given some source code as a string, return its corresponding astroid object"""
+ """Given some source code as a string, return its corresponding astroid
+ object.
+ """
# pylint: disable=import-outside-toplevel; circular import
from astroid.builder import AstroidBuilder
@@ -293,7 +295,7 @@ class AstroidManager:
def ast_from_module(
self, module: types.ModuleType, modname: str | None = None
) -> nodes.Module:
- """given an imported module, return the astroid object"""
+ """Given an imported module, return the astroid object."""
modname = modname or module.__name__
if modname in self.astroid_cache:
return self.astroid_cache[modname]
@@ -312,7 +314,7 @@ class AstroidManager:
return AstroidBuilder(self).module_build(module, modname)
def ast_from_class(self, klass: type, modname: str | None = None) -> nodes.ClassDef:
- """get astroid for the given class"""
+ """Get astroid for the given class."""
if modname is None:
try:
modname = klass.__module__
@@ -331,7 +333,7 @@ class AstroidManager:
def infer_ast_from_something(
self, obj: object, context: InferenceContext | None = None
) -> Iterator[InferenceResult]:
- """infer astroid for the given class"""
+ """Infer astroid for the given class."""
if hasattr(obj, "__class__") and not isinstance(obj, type):
klass = obj.__class__
elif isinstance(obj, type):
@@ -395,7 +397,7 @@ class AstroidManager:
self.astroid_cache.setdefault(module.name, module)
def bootstrap(self) -> None:
- """Bootstrap the required AST modules needed for the manager to work
+ """Bootstrap the required AST modules needed for the manager to work.
The bootstrap usually involves building the AST for the builtins
module, which is required by the rest of astroid to work correctly.
@@ -406,7 +408,8 @@ class AstroidManager:
def clear_cache(self) -> None:
"""Clear the underlying cache, bootstrap the builtins module and
- re-register transforms."""
+ re-register transforms.
+ """
# import here because of cyclic imports
# pylint: disable=import-outside-toplevel
from astroid.inference_tip import clear_inference_tip_cache
diff --git a/astroid/mixins.py b/astroid/mixins.py
index 9db40cf5..d7fc1dee 100644
--- a/astroid/mixins.py
+++ b/astroid/mixins.py
@@ -2,8 +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 contains some mixins for the different nodes.
-"""
+"""This module contains some mixins for the different nodes."""
import warnings
diff --git a/astroid/modutils.py b/astroid/modutils.py
index 23c1ee17..74a9cd7d 100644
--- a/astroid/modutils.py
+++ b/astroid/modutils.py
@@ -110,8 +110,8 @@ BUILTIN_MODULES = dict.fromkeys(sys.builtin_module_names, True)
class NoSourceFile(Exception):
- """exception raised when we are not able to get a python
- source file for a precompiled file
+ """Exception raised when we are not able to get a python
+ source file for a precompiled file.
"""
@@ -138,7 +138,7 @@ def _path_from_filename(filename: str, is_jython: bool = IS_JYTHON) -> str:
def _handle_blacklist(
blacklist: Sequence[str], dirnames: list[str], filenames: list[str]
) -> None:
- """remove files/directories in the black list
+ """Remove files/directories in the black list.
dirnames/filenames are usually from os.walk
"""
@@ -230,7 +230,7 @@ def load_module_from_file(filepath: str) -> types.ModuleType:
def check_modpath_has_init(path: str, mod_path: list[str]) -> bool:
- """check there are some __init__.py all along the way"""
+ """Check there are some __init__.py all along the way."""
modpath: list[str] = []
for part in mod_path:
modpath.append(part)
@@ -243,7 +243,7 @@ def check_modpath_has_init(path: str, mod_path: list[str]) -> bool:
def _get_relative_base_path(filename: str, path_to_check: str) -> list[str] | None:
- """Extracts the relative mod path of the file to import from
+ """Extracts the relative mod path of the file to import from.
Check if a file is within the passed in path and if so, returns the
relative mod path from the one passed in.
@@ -306,7 +306,7 @@ def modpath_from_file_with_callback(
def modpath_from_file(filename: str, path: Sequence[str] | None = None) -> list[str]:
- """Get the corresponding split module's name from a filename
+ """Get the corresponding split module's name from a filename.
This function will return the name of a module or package split on `.`.
@@ -385,7 +385,7 @@ def file_info_from_modpath(
def get_module_part(dotted_name: str, context_file: str | None = None) -> str:
- """given a dotted name return the module part of the name :
+ """Given a dotted name return the module part of the name :
>>> get_module_part('astroid.as_string.dump')
'astroid.as_string'
@@ -397,7 +397,6 @@ def get_module_part(dotted_name: str, context_file: str | None = None) -> str:
introduced using a relative import unresolvable in the actual
context (i.e. modutils)
-
:raise ImportError: if there is no such module in the directory
:return:
@@ -448,8 +447,8 @@ def get_module_part(dotted_name: str, context_file: str | None = None) -> str:
def get_module_files(
src_directory: str, blacklist: Sequence[str], list_all: bool = False
) -> list[str]:
- """given a package directory return a list of all available python
- module's files in the package and its subpackages
+ """Given a package directory return a list of all available python
+ module's files in the package and its subpackages.
:param src_directory:
path of the directory corresponding to the package
@@ -481,8 +480,9 @@ def get_module_files(
def get_source_file(filename: str, include_no_ext: bool = False) -> str:
- """given a python module's file name return the matching source file
- name (the filename will be returned identically if it's already an
+ """Given a python module's file name return the matching source file
+ name (the filename will be returned identically if it's already an.
+
absolute path to a python source file...)
:param filename: python module's file name
@@ -503,17 +503,15 @@ def get_source_file(filename: str, include_no_ext: bool = False) -> str:
def is_python_source(filename: str | None) -> bool:
- """
- return: True if the filename is a python source file
- """
+ """Return: True if the filename is a python source file."""
if not filename:
return False
return os.path.splitext(filename)[1][1:] in PY_SOURCE_EXTS
def is_standard_module(modname: str, std_path: Iterable[str] | None = None) -> bool:
- """try to guess if a module is a standard python module (by default,
- see `std_path` parameter's description)
+ """Try to guess if a module is a standard python module (by default,
+ see `std_path` parameter's description).
:param modname: name of the module we are interested in
@@ -547,8 +545,8 @@ def is_standard_module(modname: str, std_path: Iterable[str] | None = None) -> b
def is_relative(modname: str, from_file: str) -> bool:
- """return true if the given module name is relative to the given
- file name
+ """Return true if the given module name is relative to the given
+ file name.
:param modname: name of the module we are interested in
@@ -577,8 +575,8 @@ def _spec_from_modpath(
path: Sequence[str] | None = None,
context: str | None = None,
) -> spec.ModuleSpec:
- """given a mod path (i.e. split module / package name), return the
- corresponding spec
+ """Given a mod path (i.e. split module / package name), return the
+ corresponding spec.
this function is used internally, see `file_from_modpath`'s
documentation for more information
@@ -614,7 +612,7 @@ def _spec_from_modpath(
def _is_python_file(filename: str) -> bool:
- """return true if the given filename should be considered as a python file
+ """Return true if the given filename should be considered as a python file.
.pyc and .pyo are ignored
"""
@@ -622,8 +620,8 @@ def _is_python_file(filename: str) -> bool:
def _has_init(directory: str) -> str | None:
- """if the given directory has a valid __init__ file, return its path,
- else return None
+ """If the given directory has a valid __init__ file, return its path,
+ else return None.
"""
mod_or_pack = os.path.join(directory, "__init__")
for ext in PY_SOURCE_EXTS + ("pyc", "pyo"):
@@ -644,7 +642,7 @@ def is_module_name_part_of_extension_package_whitelist(
module_name: str, package_whitelist: set[str]
) -> bool:
"""
- Returns True if one part of the module name is in the package whitelist
+ Returns True if one part of the module name is in the package whitelist.
>>> is_module_name_part_of_extension_package_whitelist('numpy.core.umath', {'numpy'})
True
diff --git a/astroid/nodes/_base_nodes.py b/astroid/nodes/_base_nodes.py
index a70fcf0c..23e71229 100644
--- a/astroid/nodes/_base_nodes.py
+++ b/astroid/nodes/_base_nodes.py
@@ -28,7 +28,7 @@ else:
class Statement(NodeNG):
- """Statement node adding a few attributes
+ """Statement node adding a few attributes.
NOTE: This class is part of the public API of 'astroid.nodes'.
"""
@@ -70,10 +70,10 @@ class NoChildrenNode(NodeNG):
class FilterStmtsBaseNode(NodeNG):
- """Base node for statement filtering and assignment type"""
+ """Base node for statement filtering and assignment type."""
def _get_filtered_stmts(self, _, node, _stmts, mystmt: Statement | None):
- """method used in _filter_stmts to get statements and trigger break"""
+ """Method used in _filter_stmts to get statements and trigger break."""
if self.statement(future=True) is mystmt:
# original node's statement is the assignment, only keep
# current node (gen exp, list comp)
@@ -91,7 +91,7 @@ class AssignTypeNode(NodeNG):
return self
def _get_filtered_stmts(self, lookup_node, node, _stmts, mystmt: Statement | None):
- """method used in filter_stmts"""
+ """Method used in filter_stmts."""
if self is mystmt:
return _stmts, True
if self.statement(future=True) is mystmt:
@@ -109,7 +109,7 @@ class ParentAssignNode(AssignTypeNode):
class ImportNode(FilterStmtsBaseNode, NoChildrenNode, Statement):
- """Base node for From and Import Nodes"""
+ """Base node for From and Import Nodes."""
modname: str | None
"""The module that is being imported from.
@@ -151,7 +151,7 @@ class ImportNode(FilterStmtsBaseNode, NoChildrenNode, Statement):
)
def real_name(self, asname: str) -> str:
- """get name from 'as' name"""
+ """Get name from 'as' name."""
for name, _asname in self.names:
if name == "*":
return asname
@@ -169,6 +169,7 @@ class ImportNode(FilterStmtsBaseNode, NoChildrenNode, Statement):
class MultiLineBlockNode(NodeNG):
"""Base node for multi-line blocks, e.g. For and FunctionDef.
+
Note that this does not apply to every node with a `body` field.
For instance, an If node has a multi-line body, but the body of an
IfExpr is not multi-line, and hence cannot contain Return nodes,
@@ -213,8 +214,8 @@ class MultiLineWithElseBlockNode(MultiLineBlockNode):
return self.lineno
def _elsed_block_range(self, lineno, orelse, last=None):
- """handle block line numbers range for try/finally, for, if and while
- statements
+ """Handle block line numbers range for try/finally, for, if and while
+ statements.
"""
if lineno == self.fromlineno:
return lineno, lineno
diff --git a/astroid/nodes/scoped_nodes/__init__.py b/astroid/nodes/scoped_nodes/__init__.py
index 816bd83a..7b190057 100644
--- a/astroid/nodes/scoped_nodes/__init__.py
+++ b/astroid/nodes/scoped_nodes/__init__.py
@@ -2,7 +2,9 @@
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt
-"""This module contains all classes that are considered a "scoped" node and anything related.
+"""This module contains all classes that are considered a "scoped" node and anything
+related.
+
A scope node is a node that opens a new local scope in the language definition:
Module, ClassDef, FunctionDef (and Lambda, GeneratorExp, DictComp and SetComp to some extent).
"""
diff --git a/astroid/nodes/scoped_nodes/utils.py b/astroid/nodes/scoped_nodes/utils.py
index 794c81ca..e4a07724 100644
--- a/astroid/nodes/scoped_nodes/utils.py
+++ b/astroid/nodes/scoped_nodes/utils.py
@@ -2,9 +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 contains utility functions for scoped nodes.
-"""
+"""This module contains utility functions for scoped nodes."""
from __future__ import annotations
diff --git a/astroid/protocols.py b/astroid/protocols.py
index 0638c669..72549b79 100644
--- a/astroid/protocols.py
+++ b/astroid/protocols.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 contains a set of functions to handle python protocols for nodes
+"""This module contains a set of functions to handle python protocols for nodes
where it makes sense.
"""
@@ -259,7 +259,7 @@ nodes.ClassDef.infer_binary_op = instance_class_infer_binary_op
# assignment ##################################################################
-"""the assigned_stmts method is responsible to return the assigned statement
+"""The assigned_stmts method is responsible to return the assigned statement
(e.g. not inferred) according to the assignment type.
The `assign_path` argument is used to record the lhs path of the original node.
@@ -272,7 +272,7 @@ to any intermediary inference necessary.
def _resolve_looppart(parts, assign_path, context):
- """recursive function to resolve multiple assignments on loops"""
+ """Recursive function to resolve multiple assignments on loops."""
assign_path = assign_path[:]
index = assign_path.pop(0)
for part in parts:
@@ -520,7 +520,7 @@ nodes.AugAssign.assigned_stmts = assign_assigned_stmts
def _resolve_assignment_parts(parts, assign_path, context):
- """recursive function to resolve multiple assignments"""
+ """Recursive function to resolve multiple assignments."""
assign_path = assign_path[:]
index = assign_path.pop(0)
for part in parts:
@@ -710,7 +710,7 @@ def named_expr_assigned_stmts(
context: InferenceContext | None = None,
assign_path: list[int] | None = None,
) -> Any:
- """Infer names and other nodes from an assignment expression"""
+ """Infer names and other nodes from an assignment expression."""
if self.target == node:
yield from self.value.infer(context=context)
else:
diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py
index e75aa737..f0acac39 100644
--- a/astroid/rebuilder.py
+++ b/astroid/rebuilder.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 utilities for rebuilding an _ast tree in
-order to get a single Astroid representation
+"""This module contains utilities for rebuilding an _ast tree in
+order to get a single Astroid representation.
"""
from __future__ import annotations
@@ -55,7 +55,7 @@ NodesWithDocsType = Union[nodes.Module, nodes.ClassDef, nodes.FunctionDef]
# noinspection PyMethodMayBeStatic
class TreeRebuilder:
- """Rebuilds the _ast tree to become an Astroid tree"""
+ """Rebuilds the _ast tree to become an Astroid tree."""
def __init__(
self,
@@ -238,7 +238,7 @@ class TreeRebuilder:
def visit_module(
self, node: ast.Module, modname: str, modpath: str, package: bool
) -> nodes.Module:
- """visit a Module node by returning a fresh instance of it
+ """Visit a Module node by returning a fresh instance of it.
Note: Method not called by 'visit'
"""
@@ -605,7 +605,7 @@ class TreeRebuilder:
return visit_method(node, parent)
def _save_assignment(self, node: nodes.AssignName | nodes.DelName) -> None:
- """save assignment situation since node.parent is not available yet"""
+ """Save assignment situation since node.parent is not available yet."""
if self._global_names and node.name in self._global_names[-1]:
node.root().set_local(node.name, node)
else:
@@ -614,11 +614,11 @@ class TreeRebuilder:
node.parent.set_local(node.name, node)
def visit_arg(self, node: ast.arg, parent: NodeNG) -> nodes.AssignName:
- """visit an arg node by returning a fresh AssName instance"""
+ """Visit an arg node by returning a fresh AssName instance."""
return self.visit_assignname(node, parent, node.arg)
def visit_arguments(self, node: ast.arguments, parent: NodeNG) -> nodes.Arguments:
- """visit an Arguments node by returning a fresh instance of it"""
+ """Visit an Arguments node by returning a fresh instance of it."""
vararg: str | None = None
kwarg: str | None = None
newnode = nodes.Arguments(
@@ -696,7 +696,7 @@ class TreeRebuilder:
return newnode
def visit_assert(self, node: ast.Assert, parent: NodeNG) -> nodes.Assert:
- """visit a Assert node by returning a fresh instance of it"""
+ """Visit a Assert node by returning a fresh instance of it."""
newnode = nodes.Assert(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -795,7 +795,7 @@ class TreeRebuilder:
return self._visit_with(nodes.AsyncWith, node, parent)
def visit_assign(self, node: ast.Assign, parent: NodeNG) -> nodes.Assign:
- """visit a Assign node by returning a fresh instance of it"""
+ """Visit a Assign node by returning a fresh instance of it."""
newnode = nodes.Assign(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -813,7 +813,7 @@ class TreeRebuilder:
return newnode
def visit_annassign(self, node: ast.AnnAssign, parent: NodeNG) -> nodes.AnnAssign:
- """visit an AnnAssign node by returning a fresh instance of it"""
+ """Visit an AnnAssign node by returning a fresh instance of it."""
newnode = nodes.AnnAssign(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -843,7 +843,7 @@ class TreeRebuilder:
def visit_assignname(
self, node: ast.AST, parent: NodeNG, node_name: str | None
) -> nodes.AssignName | None:
- """visit a node and return a AssignName node
+ """Visit a node and return a AssignName node.
Note: Method not called by 'visit'
"""
@@ -862,7 +862,7 @@ class TreeRebuilder:
return newnode
def visit_augassign(self, node: ast.AugAssign, parent: NodeNG) -> nodes.AugAssign:
- """visit a AugAssign node by returning a fresh instance of it"""
+ """Visit a AugAssign node by returning a fresh instance of it."""
newnode = nodes.AugAssign(
op=self._parser_module.bin_op_classes[type(node.op)] + "=",
lineno=node.lineno,
@@ -878,7 +878,7 @@ class TreeRebuilder:
return newnode
def visit_binop(self, node: ast.BinOp, parent: NodeNG) -> nodes.BinOp:
- """visit a BinOp node by returning a fresh instance of it"""
+ """Visit a BinOp node by returning a fresh instance of it."""
newnode = nodes.BinOp(
op=self._parser_module.bin_op_classes[type(node.op)],
lineno=node.lineno,
@@ -894,7 +894,7 @@ class TreeRebuilder:
return newnode
def visit_boolop(self, node: ast.BoolOp, parent: NodeNG) -> nodes.BoolOp:
- """visit a BoolOp node by returning a fresh instance of it"""
+ """Visit a BoolOp node by returning a fresh instance of it."""
newnode = nodes.BoolOp(
op=self._parser_module.bool_op_classes[type(node.op)],
lineno=node.lineno,
@@ -908,7 +908,7 @@ class TreeRebuilder:
return newnode
def visit_break(self, node: ast.Break, parent: NodeNG) -> nodes.Break:
- """visit a Break node by returning a fresh instance of it"""
+ """Visit a Break node by returning a fresh instance of it."""
return nodes.Break(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -919,7 +919,7 @@ class TreeRebuilder:
)
def visit_call(self, node: ast.Call, parent: NodeNG) -> nodes.Call:
- """visit a CallFunc node by returning a fresh instance of it"""
+ """Visit a CallFunc node by returning a fresh instance of it."""
newnode = nodes.Call(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -938,7 +938,7 @@ class TreeRebuilder:
def visit_classdef(
self, node: ast.ClassDef, parent: NodeNG, newstyle: bool = True
) -> nodes.ClassDef:
- """visit a ClassDef node to become astroid"""
+ """Visit a ClassDef node to become astroid."""
node, doc_ast_node = self._get_doc(node)
newnode = nodes.ClassDef(
name=node.name,
@@ -973,7 +973,7 @@ class TreeRebuilder:
return newnode
def visit_continue(self, node: ast.Continue, parent: NodeNG) -> nodes.Continue:
- """visit a Continue node by returning a fresh instance of it"""
+ """Visit a Continue node by returning a fresh instance of it."""
return nodes.Continue(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -984,7 +984,7 @@ class TreeRebuilder:
)
def visit_compare(self, node: ast.Compare, parent: NodeNG) -> nodes.Compare:
- """visit a Compare node by returning a fresh instance of it"""
+ """Visit a Compare node by returning a fresh instance of it."""
newnode = nodes.Compare(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1008,7 +1008,7 @@ class TreeRebuilder:
def visit_comprehension(
self, node: ast.comprehension, parent: NodeNG
) -> nodes.Comprehension:
- """visit a Comprehension node by returning a fresh instance of it"""
+ """Visit a Comprehension node by returning a fresh instance of it."""
newnode = nodes.Comprehension(parent)
newnode.postinit(
self.visit(node.target, newnode),
@@ -1023,7 +1023,7 @@ class TreeRebuilder:
node: ast.ClassDef | ast.FunctionDef | ast.AsyncFunctionDef,
parent: NodeNG,
) -> nodes.Decorators | None:
- """visit a Decorators node by returning a fresh instance of it
+ """Visit a Decorators node by returning a fresh instance of it.
Note: Method not called by 'visit'
"""
@@ -1051,7 +1051,7 @@ class TreeRebuilder:
return newnode
def visit_delete(self, node: ast.Delete, parent: NodeNG) -> nodes.Delete:
- """visit a Delete node by returning a fresh instance of it"""
+ """Visit a Delete node by returning a fresh instance of it."""
newnode = nodes.Delete(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1084,7 +1084,7 @@ class TreeRebuilder:
yield rebuilt_key, rebuilt_value
def visit_dict(self, node: ast.Dict, parent: NodeNG) -> nodes.Dict:
- """visit a Dict node by returning a fresh instance of it"""
+ """Visit a Dict node by returning a fresh instance of it."""
newnode = nodes.Dict(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1100,7 +1100,7 @@ class TreeRebuilder:
return newnode
def visit_dictcomp(self, node: ast.DictComp, parent: NodeNG) -> nodes.DictComp:
- """visit a DictComp node by returning a fresh instance of it"""
+ """Visit a DictComp node by returning a fresh instance of it."""
newnode = nodes.DictComp(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1117,7 +1117,7 @@ class TreeRebuilder:
return newnode
def visit_expr(self, node: ast.Expr, parent: NodeNG) -> nodes.Expr:
- """visit a Expr node by returning a fresh instance of it"""
+ """Visit a Expr node by returning a fresh instance of it."""
newnode = nodes.Expr(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1132,7 +1132,7 @@ class TreeRebuilder:
def visit_excepthandler(
self, node: ast.ExceptHandler, parent: NodeNG
) -> nodes.ExceptHandler:
- """visit an ExceptHandler node by returning a fresh instance of it"""
+ """Visit an ExceptHandler node by returning a fresh instance of it."""
newnode = nodes.ExceptHandler(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1163,7 +1163,7 @@ class TreeRebuilder:
def _visit_for(
self, cls: type[_ForT], node: ast.For | ast.AsyncFor, parent: NodeNG
) -> _ForT:
- """visit a For node by returning a fresh instance of it"""
+ """Visit a For node by returning a fresh instance of it."""
col_offset = node.col_offset
if IS_PYPY and not PY39_PLUS and isinstance(node, ast.AsyncFor) and self._data:
# pylint: disable-next=unsubscriptable-object
@@ -1193,7 +1193,7 @@ class TreeRebuilder:
def visit_importfrom(
self, node: ast.ImportFrom, parent: NodeNG
) -> nodes.ImportFrom:
- """visit an ImportFrom node by returning a fresh instance of it"""
+ """Visit an ImportFrom node by returning a fresh instance of it."""
names = [(alias.name, alias.asname) for alias in node.names]
newnode = nodes.ImportFrom(
fromname=node.module or "",
@@ -1231,7 +1231,7 @@ class TreeRebuilder:
node: ast.FunctionDef | ast.AsyncFunctionDef,
parent: NodeNG,
) -> _FunctionT:
- """visit an FunctionDef node to become astroid"""
+ """Visit an FunctionDef node to become astroid."""
self._global_names.append({})
node, doc_ast_node = self._get_doc(node)
@@ -1288,7 +1288,7 @@ class TreeRebuilder:
def visit_generatorexp(
self, node: ast.GeneratorExp, parent: NodeNG
) -> nodes.GeneratorExp:
- """visit a GeneratorExp node by returning a fresh instance of it"""
+ """Visit a GeneratorExp node by returning a fresh instance of it."""
newnode = nodes.GeneratorExp(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1306,7 +1306,7 @@ class TreeRebuilder:
def visit_attribute(
self, node: ast.Attribute, parent: NodeNG
) -> nodes.Attribute | nodes.AssignAttr | nodes.DelAttr:
- """visit an Attribute node by returning a fresh instance of it"""
+ """Visit an Attribute node by returning a fresh instance of it."""
context = self._get_context(node)
newnode: nodes.Attribute | nodes.AssignAttr | nodes.DelAttr
if context == Context.Del:
@@ -1351,7 +1351,7 @@ class TreeRebuilder:
return newnode
def visit_global(self, node: ast.Global, parent: NodeNG) -> nodes.Global:
- """visit a Global node to become astroid"""
+ """Visit a Global node to become astroid."""
newnode = nodes.Global(
names=node.names,
lineno=node.lineno,
@@ -1367,7 +1367,7 @@ class TreeRebuilder:
return newnode
def visit_if(self, node: ast.If, parent: NodeNG) -> nodes.If:
- """visit an If node by returning a fresh instance of it"""
+ """Visit an If node by returning a fresh instance of it."""
newnode = nodes.If(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1384,7 +1384,7 @@ class TreeRebuilder:
return newnode
def visit_ifexp(self, node: ast.IfExp, parent: NodeNG) -> nodes.IfExp:
- """visit a IfExp node by returning a fresh instance of it"""
+ """Visit a IfExp node by returning a fresh instance of it."""
newnode = nodes.IfExp(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1401,7 +1401,7 @@ class TreeRebuilder:
return newnode
def visit_import(self, node: ast.Import, parent: NodeNG) -> nodes.Import:
- """visit a Import node by returning a fresh instance of it"""
+ """Visit a Import node by returning a fresh instance of it."""
names = [(alias.name, alias.asname) for alias in node.names]
newnode = nodes.Import(
names=names,
@@ -1471,18 +1471,18 @@ class TreeRebuilder:
def visit_extslice(
self, node: ast.ExtSlice, parent: nodes.Subscript
) -> nodes.Tuple:
- """visit an ExtSlice node by returning a fresh instance of Tuple"""
+ """Visit an ExtSlice node by returning a fresh instance of Tuple."""
# ExtSlice doesn't have lineno or col_offset information
newnode = nodes.Tuple(ctx=Context.Load, parent=parent)
newnode.postinit([self.visit(dim, newnode) for dim in node.dims])
return newnode
def visit_index(self, node: ast.Index, parent: nodes.Subscript) -> NodeNG:
- """visit a Index node by returning a fresh instance of NodeNG"""
+ """Visit a Index node by returning a fresh instance of NodeNG."""
return self.visit(node.value, parent)
def visit_keyword(self, node: ast.keyword, parent: NodeNG) -> nodes.Keyword:
- """visit a Keyword node by returning a fresh instance of it"""
+ """Visit a Keyword node by returning a fresh instance of it."""
newnode = nodes.Keyword(
arg=node.arg,
# position attributes added in 3.9
@@ -1496,7 +1496,7 @@ class TreeRebuilder:
return newnode
def visit_lambda(self, node: ast.Lambda, parent: NodeNG) -> nodes.Lambda:
- """visit a Lambda node by returning a fresh instance of it"""
+ """Visit a Lambda node by returning a fresh instance of it."""
newnode = nodes.Lambda(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1509,7 +1509,7 @@ class TreeRebuilder:
return newnode
def visit_list(self, node: ast.List, parent: NodeNG) -> nodes.List:
- """visit a List node by returning a fresh instance of it"""
+ """Visit a List node by returning a fresh instance of it."""
context = self._get_context(node)
newnode = nodes.List(
ctx=context,
@@ -1524,7 +1524,7 @@ class TreeRebuilder:
return newnode
def visit_listcomp(self, node: ast.ListComp, parent: NodeNG) -> nodes.ListComp:
- """visit a ListComp node by returning a fresh instance of it"""
+ """Visit a ListComp node by returning a fresh instance of it."""
newnode = nodes.ListComp(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1542,7 +1542,7 @@ class TreeRebuilder:
def visit_name(
self, node: ast.Name, parent: NodeNG
) -> nodes.Name | nodes.AssignName | nodes.DelName:
- """visit a Name node by returning a fresh instance of it"""
+ """Visit a Name node by returning a fresh instance of it."""
context = self._get_context(node)
newnode: nodes.Name | nodes.AssignName | nodes.DelName
if context == Context.Del:
@@ -1582,7 +1582,7 @@ class TreeRebuilder:
return newnode
def visit_nonlocal(self, node: ast.Nonlocal, parent: NodeNG) -> nodes.Nonlocal:
- """visit a Nonlocal node and return a new instance of it"""
+ """Visit a Nonlocal node and return a new instance of it."""
return nodes.Nonlocal(
names=node.names,
lineno=node.lineno,
@@ -1594,7 +1594,7 @@ class TreeRebuilder:
)
def visit_constant(self, node: ast.Constant, parent: NodeNG) -> nodes.Const:
- """visit a Constant node by returning a fresh instance of Const"""
+ """Visit a Constant node by returning a fresh instance of Const."""
return nodes.Const(
value=node.value,
kind=node.kind,
@@ -1609,7 +1609,7 @@ class TreeRebuilder:
if sys.version_info < (3, 8):
# Not used in Python 3.8+.
def visit_ellipsis(self, node: ast.Ellipsis, parent: NodeNG) -> nodes.Const:
- """visit an Ellipsis node by returning a fresh instance of Const"""
+ """Visit an Ellipsis node by returning a fresh instance of Const."""
return nodes.Const(
value=Ellipsis,
lineno=node.lineno,
@@ -1629,7 +1629,7 @@ class TreeRebuilder:
)
def visit_str(self, node: ast.Str | ast.Bytes, parent: NodeNG) -> nodes.Const:
- """visit a String/Bytes node by returning a fresh instance of Const"""
+ """Visit a String/Bytes node by returning a fresh instance of Const."""
return nodes.Const(
node.s,
node.lineno,
@@ -1640,7 +1640,7 @@ class TreeRebuilder:
visit_bytes = visit_str
def visit_num(self, node: ast.Num, parent: NodeNG) -> nodes.Const:
- """visit a Num node by returning a fresh instance of Const"""
+ """Visit a Num node by returning a fresh instance of Const."""
return nodes.Const(
node.n,
node.lineno,
@@ -1649,7 +1649,7 @@ class TreeRebuilder:
)
def visit_pass(self, node: ast.Pass, parent: NodeNG) -> nodes.Pass:
- """visit a Pass node by returning a fresh instance of it"""
+ """Visit a Pass node by returning a fresh instance of it."""
return nodes.Pass(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1660,7 +1660,7 @@ class TreeRebuilder:
)
def visit_raise(self, node: ast.Raise, parent: NodeNG) -> nodes.Raise:
- """visit a Raise node by returning a fresh instance of it"""
+ """Visit a Raise node by returning a fresh instance of it."""
newnode = nodes.Raise(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1677,7 +1677,7 @@ class TreeRebuilder:
return newnode
def visit_return(self, node: ast.Return, parent: NodeNG) -> nodes.Return:
- """visit a Return node by returning a fresh instance of it"""
+ """Visit a Return node by returning a fresh instance of it."""
newnode = nodes.Return(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1691,7 +1691,7 @@ class TreeRebuilder:
return newnode
def visit_set(self, node: ast.Set, parent: NodeNG) -> nodes.Set:
- """visit a Set node by returning a fresh instance of it"""
+ """Visit a Set node by returning a fresh instance of it."""
newnode = nodes.Set(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1704,7 +1704,7 @@ class TreeRebuilder:
return newnode
def visit_setcomp(self, node: ast.SetComp, parent: NodeNG) -> nodes.SetComp:
- """visit a SetComp node by returning a fresh instance of it"""
+ """Visit a SetComp node by returning a fresh instance of it."""
newnode = nodes.SetComp(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1720,7 +1720,7 @@ class TreeRebuilder:
return newnode
def visit_slice(self, node: ast.Slice, parent: nodes.Subscript) -> nodes.Slice:
- """visit a Slice node by returning a fresh instance of it"""
+ """Visit a Slice node by returning a fresh instance of it."""
newnode = nodes.Slice(
# position attributes added in 3.9
lineno=getattr(node, "lineno", None),
@@ -1737,7 +1737,7 @@ class TreeRebuilder:
return newnode
def visit_subscript(self, node: ast.Subscript, parent: NodeNG) -> nodes.Subscript:
- """visit a Subscript node by returning a fresh instance of it"""
+ """Visit a Subscript node by returning a fresh instance of it."""
context = self._get_context(node)
newnode = nodes.Subscript(
ctx=context,
@@ -1754,7 +1754,7 @@ class TreeRebuilder:
return newnode
def visit_starred(self, node: ast.Starred, parent: NodeNG) -> nodes.Starred:
- """visit a Starred node and return a new instance of it"""
+ """Visit a Starred node and return a new instance of it."""
context = self._get_context(node)
newnode = nodes.Starred(
ctx=context,
@@ -1769,7 +1769,7 @@ class TreeRebuilder:
return newnode
def visit_tryexcept(self, node: ast.Try, parent: NodeNG) -> nodes.TryExcept:
- """visit a TryExcept node by returning a fresh instance of it"""
+ """Visit a TryExcept node by returning a fresh instance of it."""
if sys.version_info >= (3, 8):
# TryExcept excludes the 'finally' but that will be included in the
# end_lineno from 'node'. Therefore, we check all non 'finally'
@@ -1823,7 +1823,7 @@ class TreeRebuilder:
return None
def visit_tuple(self, node: ast.Tuple, parent: NodeNG) -> nodes.Tuple:
- """visit a Tuple node by returning a fresh instance of it"""
+ """Visit a Tuple node by returning a fresh instance of it."""
context = self._get_context(node)
newnode = nodes.Tuple(
ctx=context,
@@ -1838,7 +1838,7 @@ class TreeRebuilder:
return newnode
def visit_unaryop(self, node: ast.UnaryOp, parent: NodeNG) -> nodes.UnaryOp:
- """visit a UnaryOp node by returning a fresh instance of it"""
+ """Visit a UnaryOp node by returning a fresh instance of it."""
newnode = nodes.UnaryOp(
op=self._parser_module.unary_op_classes[node.op.__class__],
lineno=node.lineno,
@@ -1852,7 +1852,7 @@ class TreeRebuilder:
return newnode
def visit_while(self, node: ast.While, parent: NodeNG) -> nodes.While:
- """visit a While node by returning a fresh instance of it"""
+ """Visit a While node by returning a fresh instance of it."""
newnode = nodes.While(
lineno=node.lineno,
col_offset=node.col_offset,
@@ -1917,7 +1917,7 @@ class TreeRebuilder:
return self._visit_with(nodes.With, node, parent)
def visit_yield(self, node: ast.Yield, parent: NodeNG) -> NodeNG:
- """visit a Yield node by returning a fresh instance of it"""
+ """Visit a Yield node by returning a fresh instance of it."""
newnode = nodes.Yield(
lineno=node.lineno,
col_offset=node.col_offset,
diff --git a/astroid/util.py b/astroid/util.py
index 51595ca7..39fba921 100644
--- a/astroid/util.py
+++ b/astroid/util.py
@@ -60,7 +60,7 @@ class Uninferable:
class BadOperationMessage:
- """Object which describes a TypeError occurred somewhere in the inference chain
+ """Object which describes a TypeError occurred somewhere in the inference chain.
This is not an exception, but a container object which holds the types and
the error which occurred.