Skip to content

fix: accept raw UUID strings as --namespace argument in uuid CLI#148934

Closed
Jah-yee wants to merge 2667 commits intopython:mainfrom
Jah-yee:fix/uuid-cli-namespace
Closed

fix: accept raw UUID strings as --namespace argument in uuid CLI#148934
Jah-yee wants to merge 2667 commits intopython:mainfrom
Jah-yee:fix/uuid-cli-namespace

Conversation

@Jah-yee
Copy link
Copy Markdown

@Jah-yee Jah-yee commented Apr 23, 2026

Good day

The python -m uuid CLI previously rejected raw UUID strings for the --namespace argument, only accepting the four predefined namespace names (@dns, @url, @oid, @x500). The existing code path at line 987 that calls UUID(namespace) as a fallback was never reached because argparse rejected the value upfront.

Root cause

The -n/--namespace argument used choices=["any UUID", *namespaces.keys()], which means argparse validated against the literal string "any UUID" rather than accepting any arbitrary UUID value.

Fix

Replaced the choices restriction with a custom type function that:

  1. Accepts predefined namespace names (e.g. @dns) directly
  2. Attempts to parse the input as a UUID — if valid, passes it through unchanged
  3. Raises ArgumentTypeError for invalid strings

Example

Before:

$ python -m uuid --uuid uuid5 --namespace 0d6a16cc-34a7-47d8-b660-214d0ae184d2 --name user
error: argument -n/--namespace: invalid choice: '0d6a16cc-...' (choose from ...)

After:

$ python -m uuid --uuid uuid5 --namespace 0d6a16cc-34a7-47d8-b660-214d0ae184d2 --name user
a32f4562-2058-5b20-8055-5f38b28285b6

Fixes #148740

Thank you for your work on this project. I hope this small fix is helpful. Please let me know if there's anything to adjust.

Warmly,
RoomWithOutRoof


📚 Documentation preview 📚: https://cpython-previews--148934.org.readthedocs.build/

mdickinson and others added 30 commits February 26, 2023 12:34
…1826) (python#102150)

* [3.10] pythongh-97786: Fix compiler warnings in pytime.c (pythonGH-101826)

Fixes compiler warnings in pytime.c..
(cherry picked from commit b1b375e)

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>

* Add comment about the casts

---------

Co-authored-by: Gregory P. Smith <greg@krypto.org>
…onGH-102278)

[doc] Improve grammar/fix missing word (pythonGH-102060)
(cherry picked from commit 6daf42b)

Co-authored-by: VMan <vayidm@users.noreply.github.com>
…ython#102280)

Fix missing 'is' in cmath.log() docstring.
(cherry picked from commit 71f614e)

Co-authored-by: Owain Davies <116417456+OTheDev@users.noreply.github.com>
…2283)

(cherry picked from commit 8d0f09b)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 101a12c)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
pythonGH-102297)

(cherry picked from commit 0db6f44)

Co-authored-by: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com>
Automerge-Triggered-By: GH:AlexWaygood
Refactor DynOptionMenu's initializer to not copy  kwargs dict and use subscripting;
improve its htest.

(cherry picked from commit c41af81)

Co-authored-by: JosephSBoyle <48555120+JosephSBoyle@users.noreply.github.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
…honGH-101319) (python#102322)

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Co-authored-by: Brad Wolfe <brad.wolfe@gmail.com>
Co-authored-by: Furkan Onder <furkanonder@protonmail.com>
Fix erroneous doc links in the sys module (python#101319)
…hon#102377)

Fix typos in documentation and comments (pythonGH-102374)

Found some duplicate `to`s in the documentation and some code comments and fixed them.

[Misc/NEWS.d/3.12.0a1.rst](https://github.com/python/cpython/blob/ed55c69ebd74178115cd8b080f7f8e7588cd5fda/Misc/NEWS.d/3.12.0a1.rst) also contains two duplicate `to`s, but I wasn't sure if it's ok to touch that file.  Looks auto generated.  I'm happy to amend the PR if requested. :)

Automerge-Triggered-By: GH:AlexWaygood

Co-authored-by: Michael K <michael-k@users.noreply.github.com>
…to uppercase (pythonGH-101840)

(cherry picked from commit 4e7c0cb)

Co-authored-by: Owain Davies <116417456+OTheDev@users.noreply.github.com>
… state… (python#102235)

[3.10] pythonGH-102126: fix deadlock at shutdown when clearing thread states (pythonGH-102222).
(cherry picked from commit 5f11478)
…ll exhausts the iterator (pythonGH-101896) (python#102422)

pythongh-101892: Fix `SystemError` when a callable iterator call exhausts the iterator (python#101896)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
(cherry picked from commit 705487c)

Co-authored-by: Raj <51259329+workingpayload@users.noreply.github.com>
pythonGH-102180) (python#102419)

* pythongh-102179: Fix `os.dup2` error reporting for negative fds (pythonGH-102180)
(cherry picked from commit c2bd55d)

Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
(cherry picked from commit e4609cb)

Co-authored-by: Dustin Rodrigues <dust.rod@gmail.com>
…nGH-102426)

Add thrashcan macros to the deallocator of the filter objects to protect against deeply nested destruction of chains of nested filters.
(cherry picked from commit 66aa78c)

Co-authored-by: Marta Gómez Macías <mgmacias@google.com>
…ument of add_argument() were dropped (pythonGH-102318)

(cherry picked from commit 9a478be)

Co-authored-by: Yeojin Kim <yeojin.dev@gmail.com>
As part of investigation issue python#102433, I discovered what I believe to be an error where two classes `CI` and `DI` are not being used. The assertions beneath them act on `C` and `D`, duplicating existing assertions in this test.
(cherry picked from commit 7894bbe)

Co-authored-by: JosephSBoyle <48555120+JosephSBoyle@users.noreply.github.com>
Automerge-Triggered-By: GH:AlexWaygood
(cherry picked from commit 3222054)

Co-authored-by: Partha P. Mukherjee <ppm.floss@gmail.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
…1989)

(cherry picked from commit d959bcd)

Co-authored-by: Rémi Lapeyre <remi.lapeyre@lenstra.fr>
…pythongh-102485) (pythonGH-102489)

(cherry picked from commit f9cdeb7)

Co-authored-by: Ned Deily <nad@python.org>
…ndling (pythonGH-102399) (python#102527)

pythonGH-102397: Fix segfault from race condition in signal handling (pythonGH-102399)
(cherry picked from commit 1a84cc0)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
pythonGH-102526)

(cherry picked from commit 1f557f9)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
…ith `isinstance()` checks on `typing.runtime_checkable` protocols (pythonGH-102449)

(cherry picked from commit 5ffdaf7)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Carl Meyer <carl@oddbird.net>
…st (pythonGH-102538)

It is possible but unlikely for the `python_tzpath_context` function to fail between the start of the `try` block and the point where `os.environ.get` succeeds, in which case `old_env` will be undefined. In this case, we want to take no action.

Practically speaking this will really only happen in an error condition anyway, so it doesn't really matter, but we should probably do it right anyway.
(cherry picked from commit 64bde50)

Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
)

(cherry picked from commit 78e4e6c)

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
(cherry picked from commit 9a8b66b)

Co-authored-by: 谭九鼎 <109224573@qq.com>
…lost after longlist (python#101674) (python#102633)

pythonGH-101673: Fix pdb bug where local variable changes are lost after longlist (python#101674)

(cherry picked from commit 5d677c5)

Co-authored-by: gaogaotiantian <gaogaotiantian@hotmail.com>
(cherry-picked from commit f6ca71a)

With grep utility found some duplicated words

Co-authored-by: Виталий Дмитриев <vitaldmit@bk.ru>
miss-islington and others added 14 commits February 3, 2026 14:29
…nprefix

pythongh-74453: Add stronger security warning to os.path.commonprefix (pythonGH-144401)
(cherry picked from commit 4e15b8d)

Co-authored-by: Seth Michael Larson <seth@python.org>
pythongh-144484: Warn users not to use wsgiref in production
(cherry picked from commit 7e777c5)

Co-authored-by: Seth Michael Larson <seth@python.org>
…onGH-145359) (python#145407)

pythongh-100538: Add workflow to verify bundled libexpat (pythonGH-145359)

Add workflow to verify bundled libexpat.
(cherry picked from commit c9a5d9a)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
…pythonGH-119343) (python#142151)

Reading a specially prepared small Plist file could cause OOM because file's
read(n) preallocates a bytes object for reading the specified amount of
data. Now plistlib reads large data by chunks, therefore the upper limit of
consumed memory is proportional to the size of the input file.
(cherry picked from commit 694922c)
…() fails (pythonGH-144843) (python#144862)

pythongh-144833: Fix use-after-free in SSL module when SSL_new() fails (pythonGH-144843)

In newPySSLSocket(), when SSL_new() returns NULL, Py_DECREF(self)
was called before _setSSLError(get_state_ctx(self), ...), causing
a use-after-free. Additionally, get_state_ctx() was called with
self (PySSLSocket*) instead of sslctx (PySSLContext*), which is
a type confusion bug.

Fix by calling _setSSLError() before Py_DECREF() and using
sslctx instead of self for get_state_ctx().
(cherry picked from commit c91638c)

Co-authored-by: Ramin Farajpour Cami <ramin.blackhat@gmail.com>
…45140)

pythongh-143916: Allow HTAB in wsgiref header values
(cherry picked from commit 66da7bf)

Co-authored-by: Seth Michael Larson <seth@python.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
…ythonGH-143936) (python#144350)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson seth@python.org
Co-authored-by: Denis Ledoux dle@odoo.com

- Issue: Fix folding of long comments of unfoldable characters in email headers python#143935

Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
Co-authored-by: Seth Michael Larson <seth@python.org>
…ommands (pythonGH-145457) (python#145489)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
@python-cla-bot
Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix UUID's CLI for custom namespaces for v3/v5