New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UUID docs should say how to get "standard form" #70455
Comments
Most real-world code that uses the UUID module wants either the standard format '{12345678-1234-5678-1234-567812345678}', or the same thing without the braces. There are a number of different documented accessors, but none of them give you either of these. The simplest way I can think of to guarantee the standard format from what's documented is '{%08x-%04x-%04x-%02x%02x-%12x}' % u.fields. It might be nice to add accessors for standard form and braceless standard form, but that probably isn't necessary--as long as there's documentation saying that __str__ returns the braceless standard form. The example code does say that, but I don't think people can trust that a comment in an example is binding documentation--plus, plenty of people don't read the examples looking for more information about things that aren't documented. And I've seen people come up with buggy versions of the format string that miss leading zeros, or horrible things like repr(u)[6:42]. |
The docs seem to clearly show a str(x) as the way to produce the desired form (without braces). https://docs.python.org/3/library/uuid.html#example |
Please read the last paragraph of the original message. |
Well, you seem to suggest we add something to documentation to accommodate people who don't read it in the first place. |
No, I suggest we add something for users who don't think that a comment in an example is the place to look for documentation, but do think that actual documentation of a class or method is. |
Andrew is right, this should be documented "properly". |
This patch adds documentation for the str(uuid) operator along with documenting the fact that UUID instances support comparisons with It also indents the attributes and descriptions to emphasize that they are part of the UUID instance, not the uuid module. I followed https://docs.python.org/3/library/stdtypes.html#set for documenting the operators, hope it's fine. |
Fixed the str() representation as per Evelyn's comment. |
Whoops, didn't export the patch properly there so it didn't get picked up by the review tool, this should fix it. |
Thanks for the patch, but please revert unrelated changes. |
Done. As a side question, are changes like those indentation problems tracked somewhere else/merged in bulk like spelling changes? |
I wouldn't consider it a problem since both forms are supported. Also note that you don't need to specify the "UUID." prefix when you use the indented form:
I don't think the benefit here is worth the amount of code churn. |
I've updated the patch to document the comparison operators in prose instead of with markup as requested. |
New changeset 1a25c639f81e by Berker Peksag in branch '3.5': New changeset c9e944cc6301 by Berker Peksag in branch '3.6': New changeset 8b19c2a1b197 by Berker Peksag in branch 'default': |
Thanks, Ammar. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: