Skip to content

Publicly expose Lib/dbm/__init__.py::__main__ as a script #114576

Open
@erlend-aasland

Description

@erlend-aasland

Bug report

Lib/dbm/__init__.py contains a tiny if __name__ == "__main__" section that repeatedly calls dbm.whichdb on each of the given arguments:

cpython/Lib/dbm/__init__.py

Lines 188 to 190 in 841eacd

if __name__ == "__main__":
for filename in sys.argv[1:]:
print(whichdb(filename) or "UNKNOWN", filename)

Test session:

$ python3
Python 3.13.0a3+ (heads/main-dirty:841eacd076, Jan 26 2024, 00:39:26) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbm
>>> import dbm.gnu
>>> import dbm.ndbm
>>> import dbm.dumb
>>> dbm.gnu.open("gnu.db", "c").close()
>>> dbm.ndbm.open("ndbm.db", "c").close()
>>> dbm.dumb.open("dumb.db", "c").close()
$ python3 -m dbm gnu.db ndbm.db dumb.db other.db
python3: No module named dbm.__main__; 'dbm' is a package and cannot be directly execute
$ python3 -m dbm.__init__ gnu.db ndbm.db dumb.db other.db
dbm.dumb dumb.db
dbm.gnu gnu.db
dbm.ndbm ndbm.db
UNKNOWN other.db

Some observations:

  • there is no __main__.py; we must execute __init__.py in order to run the script
  • there is no real CLI; just a list of arguments

Suggesting either to:

  1. remove the script
  2. promote it, by improving it (create __main__.py, add docs, add a simple argparse CLI, ...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtriagedThe issue has been accepted as valid by a triager.type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy