Skip to content

Conversation

Aniketsy
Copy link
Contributor

@Aniketsy Aniketsy commented Sep 16, 2025

This PR updates the documentation for platform.machine() in platform.rst to clarify that the output is system-dependent and may differ in casing and naming conventions across platforms.
For example, on Apple Silicon macOS it may return 'arm64' (lowercase), while on Windows-on-ARM it may return 'ARM64' (uppercase).

Please let me know if my approach or fix needs any improvements . I’m open to feedback and happy to make changes based on suggestions.
Thankyou !


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

@bedevere-app bedevere-app bot added awaiting review docs Documentation in the Doc dir skip news labels Sep 16, 2025
@github-project-automation github-project-automation bot moved this to Todo in Docs PRs Sep 16, 2025
@Aniketsy Aniketsy changed the title gh -138952: Document platform.machine() output casing inconsistency across platforms gh-138952: Document platform.machine() output casing inconsistency across platforms Sep 16, 2025
Comment on lines 61 to 64
The output of :func:`platform.machine` is system-dependent and may differ in casing
and naming conventions across platforms. For example, on Apple Silicon macOS it may
return ``'arm64'`` (lowercase), while on Windows-on-ARM it may return ``'ARM64'`` (uppercase).
If you need consistent results, normalize the output in your code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap to 79 characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I’ve updated it.

@python-cla-bot
Copy link

python-cla-bot bot commented Sep 16, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@ned-deily
Copy link
Member

See my comment on the issue suggesting any wording added here should not imply that the platform string can be parsed consistently for things like CPU architectures.

@juj
Copy link

juj commented Sep 16, 2025

What codebase generates those strings? Is it somehow the underlying native system?

If Python docs recommend users to normalize the strings, shouldn't Python by itself Just Do It for the user? If not, why shouldn't it? I.e. this seems a bit like documenting/validating a bug as intended behavior, without an apparent reason of why that bug should be a feature in the first place.

When ned mentions that platform string should not be parsed to find the current CPU architecture, then that is fine, and like ned pointed out in the ticket, that would be then good to be mentioned in documentation. It also then raises the obvious question of what should users utilize to detect the CPU architecture, if platform.machine() is not it?

I.e. instead of documenting "This function should not be used to detect CPU architecture", a good documentation would state "This function should not be used to detect CPU architecture, because of X. To detect the CPU architecture, see Y instead."

@Aniketsy
Copy link
Contributor Author

@ned-deily Thanks! for the feedback.
Should it look like this?

.. note::

   The output of :func:`platform.machine` is system-dependent and may differ
   in casing and naming conventions across platforms. The returned string is
   intended for direct equality checks only and should not be parsed or used
   to infer architecture or platform details, as its format may be ambiguous
   or vary between platforms.

Please let me know if I’ve misunderstood your suggestion.

Comment on lines 61 to 65
The output of :func:`platform.machine` is system-dependent and may differ
in casing and naming conventions across platforms. For example, on Apple
Silicon based macOS it may return ``'arm64'`` (lowercase), while on Windows-on-ARM
it may return ``'ARM64'`` (uppercase). If you need consistent results,
normalize the output in your code.
Copy link
Member

@StanFromIreland StanFromIreland Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, I think this whole section is a little excessive, I think just this would be fine:

.. function:: machine()

   Returns the machine type, e.g. ``'AMD64'``. An empty string is returned if the
   value cannot be determined.

   The output is platform-dependent and may differ in casing and naming
   conventions.

If we do want to stay with the note, please remove the link to the function, it is unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I update the changes as per your suggestions and remove the note section?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @StanFromIreland's suggestion here. @Aniketsy, it would be nice if you could update the PR accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ned-deily I’ve updated the PR as suggested.

@ned-deily ned-deily merged commit dd15a2e into python:main Sep 17, 2025
27 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs Sep 17, 2025
@ned-deily ned-deily added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Sep 17, 2025
@miss-islington-app
Copy link

Thanks @Aniketsy for the PR, and @ned-deily for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @Aniketsy for the PR, and @ned-deily for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 17, 2025
…ncy across platforms (pythonGH-138962)

(cherry picked from commit dd15a2e)

Co-authored-by: Aniket <[email protected]>
Co-authored-by: AN Long <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 17, 2025
…ncy across platforms (pythonGH-138962)

(cherry picked from commit dd15a2e)

Co-authored-by: Aniket <[email protected]>
Co-authored-by: AN Long <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Sep 17, 2025

GH-139045 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Sep 17, 2025
@bedevere-app
Copy link

bedevere-app bot commented Sep 17, 2025

GH-139046 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Sep 17, 2025
ned-deily pushed a commit that referenced this pull request Sep 17, 2025
…ency across platforms (GH-138962) (#139046)

(cherry picked from commit dd15a2e)

Co-authored-by: Aniket <[email protected]>
Co-authored-by: AN Long <[email protected]>
AA-Turner pushed a commit that referenced this pull request Oct 7, 2025
…ency across platforms (GH-138962) (#139045)

gh-138952:  Document platform.machine() output casing inconsistency across platforms (GH-138962)
(cherry picked from commit dd15a2e)

Co-authored-by: Aniket <[email protected]>
Co-authored-by: AN Long <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants