Skip to content
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 has a bunch of deprecated functions: let's decide what to do with them #113308

Closed
sobolevn opened this issue Dec 20, 2023 · 10 comments
Closed
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@sobolevn
Copy link
Member

sobolevn commented Dec 20, 2023

Feature or enhancement

uuid.py has several protected deprecated functions which are no longer in use:

cpython/Lib/uuid.py

Lines 591 to 594 in 4afa7be

def _load_system_functions():
"""[DEPRECATED] Platform-specific functions loaded at import time"""

cpython/Lib/uuid.py

Lines 567 to 575 in 4afa7be

def _ipconfig_getnode():
"""[DEPRECATED] Get the hardware address on Windows."""
# bpo-40501: UuidCreateSequential() is now the only supported approach
return _windll_getnode()
def _netbios_getnode():
"""[DEPRECATED] Get the hardware address on Windows."""
# bpo-40501: UuidCreateSequential() is now the only supported approach
return _windll_getnode()

And one unused module-level var:

_has_uuid_generate_time_safe = _uuid.has_uuid_generate_time_safe

The problem is that they were not deprecated with a warning. Only with docs.
But, right now they are deprecated since 2020.

This has a big history:

Some projects in the wild use _load_system_functions, despite the fact it is deprecated and was never documented and always was protected.

Examples:

So, what should we do?

  1. Add a proper warning, schedule it for removal in two versions
  2. Just remove them

I think that 1. is safer.
I would like to work on it after the decision is made.

Linked PRs

@sobolevn sobolevn added type-feature A feature request or enhancement stdlib Python modules in the Lib dir labels Dec 20, 2023
@sobolevn sobolevn self-assigned this Dec 20, 2023
@gpshead
Copy link
Member

gpshead commented Dec 20, 2023

I'd go with 1., add the warnings to start the clock.

@hugovk
Copy link
Member

hugovk commented Dec 20, 2023

1. sounds good, no rush.

Some projects in the wild use _load_system_functions, despite the fact it is deprecated and was never documented and always was protected.

Examples:

And the second one is an inactive fork of the third, I guess just for a PR.

Searching the top 8k PyPI projects, only freezegun and time-machine use any of these four functions:

python3 ~/github/misc/cpython/search_pypi_top.py -q . "_load_system_functions|_ipconfig_getnode|_netbios_getnode|_has_uuid_generate_time_safe"
./freezegun-1.2.2.tar.gz: freezegun-1.2.2/freezegun/api.py: uuid._load_system_functions()
./time_machine-2.13.0.tar.gz: time_machine-2.13.0/src/time_machine/__init__.py: uuid_idempotent_load_system_functions = (
./time_machine-2.13.0.tar.gz: time_machine-2.13.0/src/time_machine/__init__.py: uuid._load_system_functions  # type: ignore[attr-defined]
./time_machine-2.13.0.tar.gz: time_machine-2.13.0/src/time_machine/__init__.py: uuid_idempotent_load_system_functions()
./uuid-1.30.tar.gz: uuid-1.30/uuid.py: def _ipconfig_getnode():
./uuid-1.30.tar.gz: uuid-1.30/uuid.py: def _netbios_getnode():
./uuid-1.30.tar.gz: uuid-1.30/uuid.py: getters = [_windll_getnode, _netbios_getnode, _ipconfig_getnode]
./ptvsd-4.3.2.zip: ptvsd-4.3.2/src/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_uuid_old.py: def _ipconfig_getnode():
./ptvsd-4.3.2.zip: ptvsd-4.3.2/src/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_uuid_old.py: def _netbios_getnode():
./ptvsd-4.3.2.zip: ptvsd-4.3.2/src/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_uuid_old.py: getters = [_windll_getnode, _netbios_getnode, _ipconfig_getnode]

Ping @spulec and @adamchainz to give a heads-up.

@vstinner
Copy link
Member

If you start to emit a DeprecationWarning right now, you respect PEP 387, and so you will be able to remove the code in 2 releases (Python 3.15) in a safe way. You can also announce the removal at: https://docs.python.org/dev/whatsnew/3.13.html#pending-removal-in-python-3-15

@sobolevn
Copy link
Member Author

@serhiy-storchaka proposes to just remove these functions. I am fine with both versions, so I would like to get more votes :)

@serhiy-storchaka
Copy link
Member

PEP 387 only applies to public APIs. We are free not only remove private functions, but change them in breaking way, for example changing the order of parameters and changing their semantic. Exceptions can be made for old and widely used private APIs, but this is not the case.

@adamchainz
Copy link
Contributor

I agree, just remove them.

I’ve just made this PR to stop time-machine calling _load_system_functions() on Python 3.9+: adamchainz/time-machine#425 . Thanks for the heads up.

@hugovk
Copy link
Member

hugovk commented Mar 1, 2024

Fine by me too.

@terryjreedy @gpshead Any objections to just removing these internal functions? They appear to be very rarely used, now by only one in the top 8k.

@gpshead
Copy link
Member

gpshead commented Mar 2, 2024

Go for it, they're private. I sent a PR for the freezegun code (spulec/freezegun#534), and the time-machine code is already a conditional call based on Python version.

If we encounter any issues with these during the beta period we can re-add the no-op with an actual DeprecationWarning.

@sobolevn
Copy link
Member Author

sobolevn commented Mar 2, 2024

Changing my PR, thanks everyone :)

inmantaci referenced this issue in inmanta/inmanta-core Mar 4, 2024
Bumps [time-machine](https://github.com/adamchainz/time-machine) from 2.13.0 to 2.14.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/adamchainz/time-machine/blob/main/CHANGELOG.rst">time-machine's changelog</a>.</em></p>
<blockquote>
<h2>2.14.0 (2024-03-03)</h2>
<ul>
<li>
<p>Fix <code>utcfromtimestamp()</code> warning on Python 3.12+.</p>
<p>Thanks to Konstantin Baikov in <code>PR [#424](adamchainz/time-machine#424) &lt;https://github.com/adamchainz/time-machine/pull/424&gt;</code>__.</p>
</li>
<li>
<p>Fix class decorator for classmethod overrides.</p>
<p>Thanks to Pavel Bitiukov for the reproducer in <code>PR [#404](adamchainz/time-machine#404) &lt;https://github.com/adamchainz/time-machine/pull/404&gt;</code>__.</p>
</li>
<li>
<p>Avoid calling deprecated <code>uuid._load_system_functions()</code> on Python 3.9+.</p>
<p>Thanks to Nikita Sobolev for the ping in <code>CPython Issue [#113308](https://github.com/adamchainz/time-machine/issues/113308) &lt;https://github.com/python/cpython/issues/113308&gt;</code>__.</p>
</li>
<li>
<p>Support Python 3.13 alpha 4.</p>
<p>Thanks to Miro Hrončok in <code>PR [#409](adamchainz/time-machine#409) &lt;https://github.com/adamchainz/time-machine/pull/409&gt;</code>__.</p>
</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/adamchainz/time-machine/commit/8d4c9c078f00f761a676012ad984e01622c7e9ed"><code>8d4c9c0</code></a> Version 2.14.0</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/d4881aaa5b658dc138b023762ff151faafbc48ac"><code>d4881aa</code></a> Add Python 3.13 to the CI infrastructure, fix for 3.13.0a2+ (<a href="https://redirect.github.com/adamchainz/time-machine/issues/409">#409</a>)</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/3fbd386e6c576ef8edd48b480e3c84a6ef6feb55"><code>3fbd386</code></a> Fix class decorator for classmethod overrides (<a href="https://redirect.github.com/adamchainz/time-machine/issues/404">#404</a>)</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/46c66afbea82f163e1281cef55295382ce0c3eda"><code>46c66af</code></a> Fix utcfromtimestamp() deprecation warning (<a href="https://redirect.github.com/adamchainz/time-machine/issues/424">#424</a>)</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/2eda5ad3013dabaa7b0afe0dcd1f85310073a77d"><code>2eda5ad</code></a> Avoid calling uuid._load_system_functions() on Python 3.9+. (<a href="https://redirect.github.com/adamchainz/time-machine/issues/425">#425</a>)</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/4bd96a2ff28e2cf01c201ee9e5f93b498090b606"><code>4bd96a2</code></a> [pre-commit.ci] pre-commit autoupdate (<a href="https://redirect.github.com/adamchainz/time-machine/issues/423">#423</a>)</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/5f35ec33825005de7bcf2a1918b312d6d97d009d"><code>5f35ec3</code></a> Use isort to sort imports</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/21036d16415b9b1cd9feea50db4975af1b295631"><code>21036d1</code></a> [pre-commit.ci] pre-commit autoupdate (<a href="https://redirect.github.com/adamchainz/time-machine/issues/422">#422</a>)</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/1f3cbfcb0171056b7c92cb01cd131555de1cfa38"><code>1f3cbfc</code></a> Upgrade requirements (<a href="https://redirect.github.com/adamchainz/time-machine/issues/421">#421</a>)</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/36901fe51db82d7855ce8c3557c42d22e0519c26"><code>36901fe</code></a> [pre-commit.ci] pre-commit autoupdate (<a href="https://redirect.github.com/adamchainz/time-machine/issues/420">#420</a>)</li>
<li>Additional commits viewable in <a href="https://github.com/adamchainz/time-machine/compare/2.13.0...2.14.0">compare view</a></li>
</ul>
</details>
<br />

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=time-machine&package-manager=pip&previous-version=2.13.0&new-version=2.14.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

</details>
inmantaci referenced this issue in inmanta/inmanta-core Mar 6, 2024
Bumps [time-machine](https://github.com/adamchainz/time-machine) from 2.13.0 to 2.14.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/adamchainz/time-machine/blob/main/CHANGELOG.rst">time-machine's changelog</a>.</em></p>
<blockquote>
<h2>2.14.0 (2024-03-03)</h2>
<ul>
<li>
<p>Fix <code>utcfromtimestamp()</code> warning on Python 3.12+.</p>
<p>Thanks to Konstantin Baikov in <code>PR [#424](adamchainz/time-machine#424) &lt;https://github.com/adamchainz/time-machine/pull/424&gt;</code>__.</p>
</li>
<li>
<p>Fix class decorator for classmethod overrides.</p>
<p>Thanks to Pavel Bitiukov for the reproducer in <code>PR [#404](adamchainz/time-machine#404) &lt;https://github.com/adamchainz/time-machine/pull/404&gt;</code>__.</p>
</li>
<li>
<p>Avoid calling deprecated <code>uuid._load_system_functions()</code> on Python 3.9+.</p>
<p>Thanks to Nikita Sobolev for the ping in <code>CPython Issue [#113308](https://github.com/adamchainz/time-machine/issues/113308) &lt;https://github.com/python/cpython/issues/113308&gt;</code>__.</p>
</li>
<li>
<p>Support Python 3.13 alpha 4.</p>
<p>Thanks to Miro Hrončok in <code>PR [#409](adamchainz/time-machine#409) &lt;https://github.com/adamchainz/time-machine/pull/409&gt;</code>__.</p>
</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/adamchainz/time-machine/commit/8d4c9c078f00f761a676012ad984e01622c7e9ed"><code>8d4c9c0</code></a> Version 2.14.0</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/d4881aaa5b658dc138b023762ff151faafbc48ac"><code>d4881aa</code></a> Add Python 3.13 to the CI infrastructure, fix for 3.13.0a2+ (<a href="https://redirect.github.com/adamchainz/time-machine/issues/409">#409</a>)</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/3fbd386e6c576ef8edd48b480e3c84a6ef6feb55"><code>3fbd386</code></a> Fix class decorator for classmethod overrides (<a href="https://redirect.github.com/adamchainz/time-machine/issues/404">#404</a>)</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/46c66afbea82f163e1281cef55295382ce0c3eda"><code>46c66af</code></a> Fix utcfromtimestamp() deprecation warning (<a href="https://redirect.github.com/adamchainz/time-machine/issues/424">#424</a>)</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/2eda5ad3013dabaa7b0afe0dcd1f85310073a77d"><code>2eda5ad</code></a> Avoid calling uuid._load_system_functions() on Python 3.9+. (<a href="https://redirect.github.com/adamchainz/time-machine/issues/425">#425</a>)</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/4bd96a2ff28e2cf01c201ee9e5f93b498090b606"><code>4bd96a2</code></a> [pre-commit.ci] pre-commit autoupdate (<a href="https://redirect.github.com/adamchainz/time-machine/issues/423">#423</a>)</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/5f35ec33825005de7bcf2a1918b312d6d97d009d"><code>5f35ec3</code></a> Use isort to sort imports</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/21036d16415b9b1cd9feea50db4975af1b295631"><code>21036d1</code></a> [pre-commit.ci] pre-commit autoupdate (<a href="https://redirect.github.com/adamchainz/time-machine/issues/422">#422</a>)</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/1f3cbfcb0171056b7c92cb01cd131555de1cfa38"><code>1f3cbfc</code></a> Upgrade requirements (<a href="https://redirect.github.com/adamchainz/time-machine/issues/421">#421</a>)</li>
<li><a href="https://github.com/adamchainz/time-machine/commit/36901fe51db82d7855ce8c3557c42d22e0519c26"><code>36901fe</code></a> [pre-commit.ci] pre-commit autoupdate (<a href="https://redirect.github.com/adamchainz/time-machine/issues/420">#420</a>)</li>
<li>Additional commits viewable in <a href="https://github.com/adamchainz/time-machine/compare/2.13.0...2.14.0">compare view</a></li>
</ul>
</details>
<br />

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=time-machine&package-manager=pip&previous-version=2.13.0&new-version=2.14.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

</details>
sobolevn added a commit that referenced this issue Mar 14, 2024
@sobolevn
Copy link
Member Author

I merged #115934 🎉
Thanks everyone, I hope that this will be smooth!

vstinner pushed a commit to vstinner/cpython that referenced this issue Mar 20, 2024
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 25, 2024
gpshead added a commit to gpshead/cpython that referenced this issue Apr 13, 2024
The do nothing private ``uuid._load_system_functions()`` function has
been restored to appease a PyPI library that calls it to unblock 3.13
testing by others.  It now triggers a :exc:`DeprecationWarning` instead.
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

6 participants