Skip to content
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

Astroid 2.0.1 Regression: Metaclass call no longer understood. #2335

Closed
kayhayen opened this issue Jul 23, 2018 · 6 comments
Closed

Astroid 2.0.1 Regression: Metaclass call no longer understood. #2335

kayhayen opened this issue Jul 23, 2018 · 6 comments
Labels
Bug 🪲 Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine

Comments

@kayhayen
Copy link

Steps to reproduce

class NodeCheckMetaClass(ABCMeta):
    kinds = {}

    # This is in conflict with either PyDev or Pylint 1.9.2 used fo Python2, it
    # should be "mcs" for one and "cls" for the other.
    # pylint: disable=I0021,bad-mcs-classmethod-argument

    def __new__(cls, name, bases, dictionary): # pylint: disable=I0021,arguments-differ
        _checkBases(name, bases)

        if "__slots__" not in dictionary:
            dictionary["__slots__"] = ()

        if "named_child" in dictionary:
            dictionary["__slots__"] += (intern("subnode_" + dictionary["named_child"]),)

        # Not a method:
        if "checker" in dictionary:
            dictionary["checker"] = staticmethod(dictionary["checker"])

        return ABCMeta.__new__(cls, name, bases, dictionary)

Current behavior

Warning is given:
nuitka/nodes/NodeMetaClasses.py:66 E1121 too-many-function-args
NodeCheckMetaClass.new Too many positional arguments for
classmethod call

Expected behavior

I would be really surprised if that new call got too many arguments for real. I expect no warning to be given of course. Maybe it has to do with bad-mcs-classmethod-argument which seemed to no longer be an issue with 2.0.0, which I currently do not use due to lack of Python3 support for 2.0.1

pylint --version output

python3.6 -m pylint --version
main.py 2.0.0
astroid 2.0.1
Python 3.6.3 (default, Mar 27 2018, 00:29:24)
[GCC 6.3.0 20170516]

@PCManticore
Copy link
Contributor

Hi @kayhayen Thanks for the report! Can you also add in the description how the call site looks like for that error you are getting? It seems it involves the __new__ method of NodeCheckMetaClass but having how the call site looks like will help us debug this further.

@PCManticore PCManticore added Bug 🪲 Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine labels Jul 23, 2018
@PCManticore PCManticore added this to the Next minor release milestone Jul 23, 2018
@kayhayen
Copy link
Author

I am not sure what you mean, with call site, I am not calling "new" myself.

I do something unusual with the metaclass afterwards:

# For Python2/3 compatible source, we create a base class that has the metaclass
# used and doesn't require making a syntax choice.
NodeMetaClassBase = NodeCheckMetaClass(
    "NodeMetaClassBase",
    (object,),
    {
        "__slots__" : ()
    }
)

@PCManticore
Copy link
Contributor

Yes, that's what I was interested in, thanks.

@cdeil
Copy link

cdeil commented Aug 22, 2018

I get a similar error when subclassing this class:

https://github.com/astropy/astropy/blob/ba8f644694d77865f7ba1376e7f0447fec5929b6/astropy/units/quantity.py#L196

With this example:

from astropy.units import Quantity


class Energy(Quantity):
    def __new__(cls, energy, unit=None, dtype=None, copy=True):
        self = super(Energy, cls).__new__(cls, energy, unit, dtype=dtype, copy=copy)
        return self

I get this error:

$ pylint -E test.py
************* Module test
test.py:6:15: E1124: Argument 'dtype' passed by position and keyword in classmethod call (redundant-keyword-arg)

The error makes no sense to me, on that line I pass dtype=dtype and it's not passed by position.

This is with astroid and pylint master from today.

$ pylint --version
pylint 2.2.0
astroid 2.0.4
Python 3.6.0 | packaged by conda-forge | (default, Feb 10 2017, 07:08:35) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]

If it's useful for you to have this in a separate issue, let me know and I'll copy this comment there.

@PCManticore
Copy link
Contributor

Thanks @cdeil ! Let's move this to a separate issue, it seems related but a bit different at the same time that it should be on its own.

@cdeil
Copy link

cdeil commented Aug 23, 2018

OK, I've opened #2441 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine
Projects
None yet
Development

No branches or pull requests

3 participants