kayak / pypika

PyPika is a python SQL query builder that exposes the full richness of the SQL language using a syntax that reflects the resulting query. PyPika excels at all sorts of SQL queries but is especially useful for data analysis.
http://pypika.readthedocs.io/en/latest/
Apache License 2.0
2.5k stars 295 forks source link

Problem in Abstract class #767

Open realxoman opened 11 months ago

realxoman commented 11 months ago

I have a strange problem with PyPika when I use abstract classes.

from abc import ABC

class Test(ABC):
   pass

class Message(Test):
   LIST_QUERY = Query.from_('messages')

a = Message()

TypeError: Can't instantiate abstract class Message with abstract method LIST_QUERY

When I remove Test from class args it work correctly. What is the problem?

wd60622 commented 11 months ago

Seems like the Message gets LIST_QUERY as an abstract method. i.e. Message.__abstractmethods__

This provides the same error. Might be related somehow

from abc import ABC, abstractmethod

class Test(ABC): 
    @abstractmethod
    def LIST_QUERY(self): 
        pass

class Message(Test):
    pass

a = Message()

Diving into the abc source code a bit: https://github.com/python/cpython/blob/main/Lib/abc.py