Skip to content

gh-90889: Deprecate pathlib methods when required functions are missing. #101505

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

Conversation

barneygale
Copy link
Contributor

@barneygale barneygale commented Feb 1, 2023

Emit a deprecation warning (in addition to raising NotImplementedError) if a pathlib method is called that relies on a missing function. Affects:

  • Path.readlink() (when os.readlink() is missing)
  • Path.symlink_to() (when os.symlink() is missing)
  • Path.hardlink_to() (when os.link() is missing)
  • Path.owner() (when pwd.getpwuid() is missing)
  • Path.group() (when grp.getgrgid() is missing)

From Python 3.14, these methods will only be present if their required low-level functions are present, which will allow users to perform feature detection: if hasattr(p, 'symlink_to'): p.symlink_to(...)

To support versions prior to Python 3.14, users can first check for the low-level functions, like: if hasattr(os, 'symlink'): p.symlink_to(...).

… missing.

Emit a deprecation warning (in addition to raising `NotImplementedError`)
if a pathlib method is called that relies on a missing function. Affects:

- `Path.readlink()` (when `os.readlink()` is missing)
- `Path.symlink_to()` (when `os.symlink()` is missing)
- `Path.hardlink_to()` (when `os.link()` is missing)
- `Path.owner()` (when `pwd.getpwuid()` is missing)
- `Path.group()` (when `grp.getgrgid()` is missing)

From Python 3.14, these methods will only be present if their required
low-level functions are present, which will allow users to perform feature
detection: `if hasattr(p, 'symlink_to'): p.symlink_to(...)`

To support versions prior to Python 3.14, users can first check for the
low-level functions, like: `if hasattr(os, 'symlink'): p.symlink_to(...)`.
@barneygale
Copy link
Contributor Author

barneygale commented Feb 1, 2023

Maybe this is OTT. Some other options:

  1. Just change the exception type to AttributeError and document it?
  2. Define class _AttributeError(AttributeError, NotImplementedError): pass and raise that for a while?

@barneygale barneygale closed this Mar 10, 2023
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.

2 participants