Skip to content

Initial pass with pydocstringformatter #1947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion astroid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion astroid/_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def parse(self, string: str, type_comments: bool = True) -> ast.Module:


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

Expand Down
8 changes: 4 additions & 4 deletions astroid/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


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.
Expand Down Expand Up @@ -65,7 +65,7 @@ def from_call(cls, call_node, context: InferenceContext | None = None):
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.
Expand All @@ -75,7 +75,7 @@ def has_invalid_arguments(self):
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
Expand Down Expand Up @@ -154,7 +154,7 @@ def _unpack_args(self, args, context: InferenceContext | None = None):
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.
Expand Down
22 changes: 12 additions & 10 deletions astroid/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _is_property(meth, context: InferenceContext | None = None) -> bool:


class Proxy:
"""a simple proxy object
"""A simple proxy object.

Note:

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -252,7 +254,7 @@ def getattr(self, name, context: InferenceContext | None = None, lookupclass=Tru
return values

def igetattr(self, name, context: InferenceContext | None = None):
"""inferred getattr"""
"""Inferred getattr."""
if not context:
context = InferenceContext()
try:
Expand Down Expand Up @@ -283,7 +285,7 @@ def igetattr(self, name, context: InferenceContext | None = None):
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):
Expand All @@ -301,7 +303,7 @@ def _wrap_attr(self, attrs, context: InferenceContext | None = None):
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

Expand Down Expand Up @@ -357,7 +359,7 @@ def display_type(self) -> str:
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:

Expand Down Expand Up @@ -403,7 +405,7 @@ def getitem(self, index, context: InferenceContext | None = None):


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())
Expand Down Expand Up @@ -485,7 +487,7 @@ def bool_value(self, context: InferenceContext | None = None) -> Literal[True]:


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())
Expand Down Expand Up @@ -614,7 +616,7 @@ def bool_value(self, context: InferenceContext | None = None) -> Literal[True]:


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.
"""
Expand Down Expand Up @@ -654,7 +656,7 @@ def __str__(self) -> str:


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"
Expand Down
4 changes: 2 additions & 2 deletions astroid/brain/brain_boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -11,7 +11,7 @@


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
Expand Down
24 changes: 12 additions & 12 deletions astroid/brain/brain_builtin_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def ljust(self, width, fillchar=None):


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():
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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__,
Expand All @@ -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.
Expand Down Expand Up @@ -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
"""
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions astroid/brain/brain_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion astroid/brain/brain_dateutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion astroid/brain/brain_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion astroid/brain/brain_hypothesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def a_strategy(draw):
return draw(st.integers())

a_strategy()

"""
from astroid.manager import AstroidManager
from astroid.nodes.scoped_nodes import FunctionDef
Expand Down
4 changes: 3 additions & 1 deletion astroid/brain/brain_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@


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]
Expand Down
6 changes: 3 additions & 3 deletions astroid/brain/brain_namedtuple_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -185,7 +185,7 @@ def _looks_like(node, name) -> bool:
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
Expand Down Expand Up @@ -464,7 +464,7 @@ def name(self):


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
Expand Down
4 changes: 2 additions & 2 deletions astroid/brain/brain_numpy_ma.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -11,7 +11,7 @@

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
Expand Down
Loading