python / cpython

The Python programming language
https://www.python.org
Other
63.34k stars 30.32k forks source link

dbm script #114576

Open erlend-aasland opened 9 months ago

erlend-aasland commented 9 months ago

Bug report

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

https://github.com/python/cpython/blob/841eacd07646e643f87d7f063106633a25315910/Lib/dbm/__init__.py#L188-L190

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:

Suggesting either to:

  1. remove the script
  2. promote it, by improving it (create __main__.py, add docs, add a simple argparse CLI, ...)
erlend-aasland commented 9 months ago

FTR, I suggest the latter: let's improve the CLI and promote it in the dbm docs.

erlend-aasland commented 9 months ago

bug/feature; hard to say :)