Skip to content

Add DirectoryNotEmptyError subclass of OSError #77028

Closed as not planned
Closed as not planned

Description

@warsaw
BPO 32847
Nosy @warsaw, @pitrou, @vstinner, @eryksun, @nanjekyejoannah
PRs
  • bpo-32847: Add DirectoryNotEmptyError subclass of OSError #15496
  • 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:

    assignee = None
    closed_at = None
    created_at = <Date 2018-02-15.03:11:57.657>
    labels = ['3.9']
    title = 'Add DirectoryNotEmptyError subclass of OSError'
    updated_at = <Date 2019-09-12.09:50:46.365>
    user = 'https://github.com/warsaw'

    bugs.python.org fields:

    activity = <Date 2019-09-12.09:50:46.365>
    actor = 'vstinner'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2018-02-15.03:11:57.657>
    creator = 'barry'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32847
    keywords = ['patch']
    message_count = 6.0
    messages = ['312192', '350778', '350783', '350785', '352083', '352084']
    nosy_count = 5.0
    nosy_names = ['barry', 'pitrou', 'vstinner', 'eryksun', 'nanjekyejoannah']
    pr_nums = ['15496']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue32847'
    versions = ['Python 3.9']

    Activity

    1. warsaw commented on Feb 15, 2018

      @warsaw
      MemberAuthor

      I just ran across errno 39 (Directory not empty) when using Path.rename(newdir) when newdir already existed and was not empty. I realized that OSError exceptions don't have a DirectoryNotEmptyError subclass. Maybe we should add one?

      Probably not important or common enough to add for 3.7 given we're in beta now.

    2. added
      3.9 (EOL)
      and removed
      3.8 (EOL)
      on Aug 26, 2019
    3. vstinner commented on Aug 29, 2019

      @vstinner
      Member

      Maybe we should add one?

      I don't think that we need to add an *builtin* exception for every single possible errno. On Linux with Python 3.7, I count 133 different error numbers:

      >>> len([name for name in dir(errno) if name.startswith("E")])
      133

      PEP-3151 explains the rationale for added OSError subclasses.

      I think that we should focus on the most common ones, especially the ones which are available on all platforms.

      I have no opinion about "errno 39 (Directory not empty)". Is it a "common" error?

    4. eryksun commented on Aug 29, 2019

      @eryksun
      Contributor

      I have no opinion about "errno 39 (Directory not empty)".
      Is it a "common" error?

      Python's code base never specifically handles ENOTEMPTY. On the other hand, in terms of basic operations on files and directories, I think implementing DirectoryNotEmptyError follows naturally from the existing set: FileNotFoundError, FileExistsError, NotADirectoryError, and IsADirectoryError.

    5. pitrou commented on Aug 29, 2019

      @pitrou
      Member

      According to POSIX, the only system calls that can fail with ENOTEMPTY are rmdir(), rename() and unlinkat().

    6. vstinner commented on Sep 12, 2019

      @vstinner
      Member

      Copy of my comment on the review:
      #15496 (review)

      I'm not excited by adding a new builtin symbol: IMHO this module already exists too many symbols.

      I'm not convinced that it's worth it. There is exactly 0 line of code in CPython code base which expects ENOTEMPTY errno. So it looks like an artifical use case.

      I recall that when PEP-3151 was implemented, the implementation replaced a lot of code using "except OSError as exc: if exc.errno == XXX: ... else: raise" with "except : ..." which was neat.

      But again, I don't see any usage of ENOTEMPTY in the Python stdlib.

      Are you aware of 3rd party code expecting ENOTEMPTY? How many projects?

      Adding a builtin symbol is a significant change, it should be well motived.

    7. vstinner commented on Sep 12, 2019

      @vstinner
      Member

      Python's code base never specifically handles ENOTEMPTY.

      Right, so this use case looks artificial to me.

      On the other hand, in terms of basic operations on files and directories, I think implementing DirectoryNotEmptyError follows naturally from the existing set: FileNotFoundError, FileExistsError, NotADirectoryError, and IsADirectoryError.

      Again, I consider that we must not add one exception per errno, since the Python errno module contains 133 error codes on Linux. Many are very rare and don't deserve to add a new symbol to the builtins module.

      I suggest to close this issue.

      If later someone wants to get DirectoryNotEmptyError, please open a new issue with statistics of how many 3rd party projects use ENOTEMPTY.

    8. transferred this issue fromon Apr 10, 2022
    9. added
      interpreter-core
      on Nov 23, 2023
    10. vstinner commented on Apr 7, 2026

      @vstinner
      Member

      I close the issue.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.9 (EOL)interpreter-core

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions