Skip to content

os.statx() ignores follow_symlinks=False #158998

Description

@jjhelmus

Bug report

On Linux with Python 3.15, os.statx() follows symbolic links even when follow_symlinks=False is passed.

A small reproducer:

import os
import stat
import tempfile
from pathlib import Path

with tempfile.TemporaryDirectory() as directory:
    target = Path(directory) / "target"
    link = Path(directory) / "link"
    target.touch()
    link.symlink_to(target)

    result = os.statx(link, os.STATX_BASIC_STATS, follow_symlinks=False)
    assert stat.S_ISLNK(result.stx_mode), "statx followed the symlink"

The assert statement is triggered because statx follows the symlink:

# /opt/bin/python3.15 -V
Python 3.15.0rc3
# /opt/bin/python3.15 bug.py
Traceback (most recent call last):
  File "/root/Python-3.15.0rc3/bug.py", line 13, in <module>
    assert stat.S_ISLNK(result.stx_mode), "statx followed the symlink"
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
AssertionError: statx followed the symlink

AT_SYMLINK_NOFOLLOW should likely be added to the statx flags when follow_symlinks is falsely.

CPython versions tested on:

3.15

Operating systems tested on:

Linux

Linked PRs

Activity

  1. cmaloney commented on Oct 8, 2026

    @cmaloney
    Contributor
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    3.15bugs and security fixes
    on Oct 8, 2026
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.15bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions