Skip to content

Document the fact that shutil.Error is a subclass of OSError #141045

@ShaiAvr

Description

@ShaiAvr

Documentation

When I looked at the docs of the shutil module, I noticed that it doesn't mention that shutil.Error is a subclass of OSError. running shutil.Error.mro() reveals that indeed shutil.Error subclasses OSError and it can also be seen in the code. I think it would be nice to document this fact, so I know that if I do multiple operations which could raise other subclasses of OSError like shutil.copy, then I can use:

try:
    ... # Use shutil.copytree which raises shutil.Error and/or shutil.copy/shutil.copy2 which raises OSError
except OSError as e:
    ... # Handle any error that occured.

instead of:

try:
    ...
except (OSError, shutil.Error) as e:  # The docs don't mention that shutil.Error and OSError are related, so I need to catch both of them
    ...

If it's intentionally not documented since it's an implementation detail, then I still think the docs should mention that and say that it could change, and users shouldn't rely on shutil.Error being a subclass of OSError.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc direasy

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions