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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor - P4
    • Resolution: Fixed
    • None
    • 0.6
    • None
    • None

    Description

      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

      Attachments

        Issue Links

          Activity

            People

              jesse@mongodb.com A. Jesse Jiryu Davis
              jesse@mongodb.com A. Jesse Jiryu Davis
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: