Skip to content

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