Skip to content

is_file no longer throws an exception on Python 3.14 #144525

@intentionally-left-nil

Description

@intentionally-left-nil

Bug report

Bug description:

Hello, when faced with a file in a folder the user cannot read, there is a behavior change between python 3.13 and 3.14. In the script below, you can see that is_file() returns different results:

import sys
import tempfile
from pathlib import Path


print(f"Python {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")
with tempfile.TemporaryDirectory() as tmp:
    root = Path(tmp)
    child = root / "child"
    child.mkdir()
    path_under_child = child / "nonexistent"
    try:
        child.chmod(0o000)
        try:
            result = path_under_child.is_file()
            print(f"  (child/nonexistent).is_file() = {result}  (no exception)")
        except OSError as e:
            print(f"  (child/nonexistent).is_file() raised: {type(e).__name__}: {e}")
        finally:
            child.chmod(0o755)
    except OSError as e:
        print(f"  chmod failed: {e}")
print("Done")

Here are the results:

Python 3.13.11
  (child/nonexistent).is_file() raised: PermissionError: [Errno 13] Permission denied: '/tmp/tmpc2x6rhs9/child/nonexistent'
Done

and for 3.14:

Python 3.14.2
  (child/nonexistent).is_file() = False  (no exception)
Done

Is this an expected change? If so, it's not mentioned in the What's New section: https://docs.python.org/3/whatsnew/3.14.html#pathlib

or is it an unexpected breaking change? It's not the end of the world, but it means adding more logic to work for both codepaths

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs and security fixespendingThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directorytopic-pathlibtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions