Factor out shared functions in mongo.py and mongo_printers.py

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Server Programmability
    • Programmability 2023-03-30
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      mongo.py has a confusing import guarded by if not gdb (shown below). mongo_printers.py has something similar.

      if not gdb:
          sys.path.insert(0, str(Path(os.path.abspath(__file__)).parent.parent.parent))
          from buildscripts.gdb.mongo_printers import absl_get_nodes, get_bytes, get_unique_ptr
      

      This is because .gdbinit sources both mongo.py and mongo_printers.py, so there's no need for them to import from each other when running under gdb. Indeed, they can't import from each other as importing those modules has side effects, so the .gdbinit will effectively import them twice and execute the side effects twice. But, linters don't understand that situation and complain about unknown names, so the confusing guarded import exists.

      There's no good reason for absl_get_nodes (for example) to be in mongo_printers.py rather than mongo.py, or vice versa. It really should be in a separate library accessible from both. The same goes for all of the functions these modules are importing from each other. By moving them into a separate module, we can get rid of the confusing linter-satisfying include guard and clean things up slightly.

            Assignee:
            Ryan Berryhill
            Reporter:
            Ryan Berryhill
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: