Skip to content

Address pylint 3.3 messages #2575

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
Sep 22, 2024
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
8 changes: 3 additions & 5 deletions astroid/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _infer_stmts(
stmts: Iterable[InferenceResult],
context: InferenceContext | None,
frame: nodes.NodeNG | BaseInstance | None = None,
) -> collections.abc.Generator[InferenceResult, None, None]:
) -> collections.abc.Generator[InferenceResult]:
"""Return an iterator on statements inferred by each statement in *stmts*."""
inferred = False
constraint_failed = False
Expand Down Expand Up @@ -354,7 +354,7 @@ def infer_binary_op(
other: InferenceResult,
context: InferenceContext,
method: SuccessfulInferenceResult,
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
return method.infer_call_result(self, context)

def __repr__(self) -> str:
Expand Down Expand Up @@ -491,9 +491,7 @@ def _infer_builtin_new(
self,
caller: SuccessfulInferenceResult | None,
context: InferenceContext,
) -> collections.abc.Generator[
nodes.Const | Instance | UninferableBase, None, None
]:
) -> collections.abc.Generator[nodes.Const | Instance | UninferableBase]:
if not isinstance(caller, nodes.Call):
return
if not caller.args:
Expand Down
2 changes: 1 addition & 1 deletion astroid/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class InferenceError(ResolveError): # pylint: disable=too-many-instance-attribu
context: InferenceContext object.
"""

def __init__( # pylint: disable=too-many-arguments
def __init__( # pylint: disable=too-many-arguments, too-many-positional-arguments
self,
message: str = "Inference failed for {node!r}.",
node: InferenceResult | None = None,
Expand Down
2 changes: 1 addition & 1 deletion astroid/nodes/_base_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
InferenceContext,
InferenceContext,
],
list[partial[Generator[InferenceResult, None, None]]],
list[partial[Generator[InferenceResult]]],
]


Expand Down
4 changes: 2 additions & 2 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _is_const(value) -> bool:
]
InferBinaryOperation = Callable[
[_NodesT, Optional[InferenceContext]],
Generator[Union[InferenceResult, _BadOpMessageT], None, None],
Generator[Union[InferenceResult, _BadOpMessageT]],
]
InferLHS = Callable[
[_NodesT, Optional[InferenceContext]],
Expand Down Expand Up @@ -737,7 +737,7 @@ def __init__(
self.vararg_node = vararg_node
self.kwarg_node = kwarg_node

# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments, too-many-positional-arguments
def postinit(
self,
args: list[AssignName] | None,
Expand Down
2 changes: 1 addition & 1 deletion astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ def get_wrapping_class(node):
return klass


class ClassDef( # pylint: disable=too-many-instance-attributes
class ClassDef(
_base_nodes.FilterStmtsBaseNode, LocalsDictNodeNG, _base_nodes.Statement
):
"""Class representing an :class:`ast.ClassDef` node.
Expand Down
2 changes: 1 addition & 1 deletion astroid/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class AstroidManagerBrain(TypedDict):
"InferenceContext",
SuccessfulInferenceResult,
],
Generator[InferenceResult, None, None],
Generator[InferenceResult],
]


Expand Down
3 changes: 3 additions & 0 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ exclude-protected=_asdict,_fields,_replace,_source,_make
# Maximum number of arguments for function / method
max-args=10

# Maximum number of positional arguments for function / method.
max-positional-arguments=8

Comment on lines +310 to +312
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda bad that we're forcing everyone upgrading to add this. Should we use the max-args value by default ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And release it in 3.3.1 asap

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, seems presumptuous to me. There are several options, fixing it, disabling it, adding inline disables for egregious cases. Doesn't seem any different to me than the usual pylint minor upgrade where each new check has to be evaluated. We called out in the release note that this new check has its own setting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, defaulting one setting to the other is pretty bad: the max-positional-arguments default should always be strictly lower than max-args. It's already not great that the defaults are the same.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your point that the default should be less than max-args, but it seems like it's something that should be fixed in a major. If you already had max-args=12 in the code imo it means you wanted to disable all existing too-many-arguments while still guaranteeing that it's not getting worse either (i.e. your acceptable number of positional args is going to be high too). It also pretty much means that your going to have new too-many-positional-arguments raised when upgrading which is bad for a minor.
Also, too-many-positional-arguments is a refactor message: annoying to remove and probably not something that will be default when pylint become "sane" in 4.0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(i.e. your acceptable number of positional args is going to be high too)

I guess I don't think we can assume that.

I'm keeping an open mind, but I just think every pylint minor comes with estimating the cost of complying with every new message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

# Argument names that match this expression will be ignored. Default to name

# with leading underscore
Expand Down
Loading