Can't use Motor object as property of class that inherits from ABC

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Minor - P4
    • 0.6
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Python 3 has an Abstract Base Class that declares abstract methods. An ABC subclass must implement all abstract methods, or it cannot be constructed.

      ABC somehow thinks that Motor objects are unimplemented abstract base class methods:

      from abc import ABC
      from motor.motor_asyncio import AsyncIOMotorClient
      
      db = AsyncIOMotorClient().test
      
      class C(ABC):
          db = db
      
      # TypeError: Can't instantiate abstract class C with abstract methods db
      c = C()
      

      This would be an odd pattern, and easy to avoid, like so:

      class C(ABC):
          @property
          def db(self):
              return db
      

      Nevertheless, I'll investigate what it is about Motor's metaprogramming that confuses ABC.

      First reported here:

      https://github.com/KeepSafe/aiohttp/issues/805

              Assignee:
              A. Jesse Jiryu Davis
              Reporter:
              A. Jesse Jiryu Davis
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: