pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.27k stars 1.13k forks source link

False positive ``abstract-class-instantiated`` with ``pandas.ExcelWriter`` #3060

Open mhooreman opened 5 years ago

mhooreman commented 5 years ago

Hello,

Steps to reproduce

Run pylint on the following code:

"""Lorem ipsum"""

import pandas as pd

def demo():
    """Demo for the false positive"""
    with pd.ExcelWriter("demo.xlsx") as writer:
        print(writer)

Current behavior

Pylint gives: abstract-class-instantiated(E0110): test.py:8:9: demo: Abstract class 'ExcelWriter' with abstract methods instantiated

Expected behavior

No issue

pylint --version output

Discussion

This ticket has originally been opened on pandas github: https://github.com/pandas-dev/pandas/issues/27634

According to the discussions there, it seems that pylint has issues with introspection of objects defining __new__

dasrequiem commented 5 years ago

I just ran into this exact issue.

PCManticore commented 5 years ago

Thanks for the report folks!

mhooreman commented 5 years ago

You're welcome. Thanks for your help.

Le ven. 16 août 2019 17:22, Claudiu Popa notifications@github.com a écrit :

Thanks for the report folks!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/PyCQA/pylint/issues/3060?email_source=notifications&email_token=ABYIHFTFNBN6FLJGJPQ6LQTQE3A4DA5CNFSM4ILLMDY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4O5E4Y#issuecomment-522048115, or mute the thread https://github.com/notifications/unsubscribe-auth/ABYIHFXN7REEB5LVEZYNEFDQE3A4DANCNFSM4ILLMDYQ .

lleeoo commented 5 years ago

To save y'all 10s here is the comment line to temporarily disable this error and point to this page: # https://github.com/PyCQA/pylint/issues/3060 pylint: disable=abstract-class-instantiated

gk2go commented 4 years ago

+1

drdDavi commented 4 years ago

Guys, this is driving me mad, could someone please tell me how to implement a temporary fix.

EdgarOrtegaRamirez commented 4 years ago

@UrAvgDeveloper this is what I did to disable this check globally, you need a .pylintrc file, look for [MESSAGES CONTROL] then for disable= and add abstract-class-instantiated image

usser123 commented 4 years ago

I encountered the same issue.

I get a pylint message on the line: writer = pd.ExcelWriter(output, engine='xlsxwriter')

'Abstract class ExcelWriter with abstract methods instantiated'

pandas==0.25.3

liamsuma commented 4 years ago

same issue as of today writer = pd.ExcelWriter('path to file') 'Abstract class 'ExcelWriter' with abstract methods instantiated'

grishagin commented 4 years ago

Same here. Used the following syntax as a temporary fix: with pd.ExcelWriter(outfile_name) as xl_writer: #pylint: disable=abstract-class-instantiated

Svestis commented 4 years ago

Same as of today: (abstract-class-instantiated)Abstract class 'ExcelWriter' with abstract methods instantiated

acamposc commented 4 years ago

+1 Abstract class 'ExcelWriter' with abstract methods instantiatedpylint(abstract-class-instantiated)

MattSom commented 4 years ago

For me as well: Abstract class 'ExcelWriter' with abstract methods instantiated

ffanderson commented 4 years ago

Me too :(

ffanderson commented 4 years ago

with pd.ExcelWriter(outfile_name) as xl_writer: #pylint: disable=abstract-class-instantiated

Doesn't this just thrown a line length error?

grishagin commented 4 years ago

with pd.ExcelWriter(outfile_name) as xl_writer: #pylint: disable=abstract-class-instantiated

Doesn't this just thrown a line length error?

Not in my case... I didn't change any of the pylint's defaults.
In any case, one can adjust that setting: https://stackoverflow.com/questions/52058886/visual-studio-code-with-pylint-and-autopep8-how-can-i-avoid-pylint-to-complain

aaronsmith1234 commented 2 years ago

I am still getting this on v2.12.2; not sure why! Same code, pandas.ExcelWriter

clavedeluna commented 1 year ago

@DanielNoord I started to look at this issue and I'm not totally convinced this is an astroid issue. The same thing can be reproduced with:

import abc

class Test(metaclass=abc.ABCMeta):
    def __new__(cls):
        pass

    @property
    @abc.abstractmethod
    def sheets(self):
        """Mapping of sheet names to sheet objects."""

    @property
    @abc.abstractmethod
    def book(self):
        """
        Book instance. Class type will depend on the engine used.
        This attribute can be used to access engine-specific features.
        """

test = Test()

and also without __new__ in the definition. In fact, the functional tests hint that raising this message is expected.

So is there something specific for pandas that needs to be done in astroid, or can we do something in pylint's _check_inferred_class_is_abstract to nope out if a __new__ method is defined? Just throwing ideas....

DanielNoord commented 1 year ago

Good find, although the check can't be that simple sadly. Consider:

import abc

class Test(metaclass=abc.ABCMeta):
    def __new__(cls):
        print("Test.__new__")
        return super().__new__(cls)

    @property
    @abc.abstractmethod
    def sheets(self):
        """Mapping of sheet names to sheet objects."""

    @property
    @abc.abstractmethod
    def book(self):
        """
        Book instance. Class type will depend on the engine used.
        This attribute can be used to access engine-specific features.
        """

test = Test()

Anyway, this is indeed something that should be fixed in pylint.

clavedeluna commented 1 year ago

So is the idea to fix this issue to not raise abstract-class-instantiated in the case the class has an implemented __new__ method?

DanielNoord commented 1 year ago

No, we should not raise it if there wouldn't be an exception raised. In the example I gave the code would still crash, so the message is valid.,

mhooreman commented 1 year ago

Hi Any update on this? I still have the issue with pd 2.0.2 Thanks