Skip to content

False Positive for too-many-function-args when subclassing __new__ #10670

@Redoubts

Description

@Redoubts

Bug description

I subclass datetime.datetime for some specific needs, but with the new 4.0 version of pylint, I see E1121 when I try the following:

import datetime
from typing import Self


class MyDateTime(datetime.datetime):

    def __new__(
        cls,
        firstArg: object,
        month: int | None = None,
        day: int | None = None,
        hour: int = 0,
        minute: int = 0,
        second: int = 0,
        microsecond: int = 0,
    ) -> Self:
        return super().__new__(
            cls, firstArg, month, day, hour, minute, second, microsecond
        )

I think this is pretty valid (I tried to strip out as much as I could to repro), and this instantiates fine

In [3]: MyDateTime(1,1,1)
Out[3]: MyDateTime(1, 1, 1, 0, 0)

Am I misreading the issue, or is something off with pylint's interpretation

Configuration

Command used

pylint --rcfile /dev/null --disable all --enable E1121 x.py

Pylint output

************* Module x
x.py:17:15: E1121: Too many positional arguments for classmethod call (too-many-function-args)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 8.89/10, -8.89)

Expected behavior

"10/10, would lint again"

Pylint version

pylint 4.0.1
astroid 4.0.1
Python 3.11.13

OS / Environment

Debian

Additional dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs triage 📥Just created, needs acknowledgment, triage, and proper labelling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions