Uploaded image for project: 'Motor'
  1. Motor
  2. MOTOR-104

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

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 0.6
    • Affects Version/s: None
    • Component/s: 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:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: