Skip to content

[BUG] pushd context manager doesn't restore original directory #792

@jph00

Description

@jph00

Description:

The pushd context manager in nbdime/utils.py uses os.curdir instead of os.getcwd() to save the current directory. Since os.curdir is the constant string '.', the directory is never actually restored on exit.

Minimal Reproduction:

import os, tempfile
from nbdime.utils import pushd

original = os.getcwd()
with tempfile.TemporaryDirectory() as td:
    with pushd(td): pass
    print(f"Expected: {original}")
    print(f"Actual:   {os.getcwd()}")
    print(f"Match: {original == os.getcwd()}")

Expected: Current directory restored to original after exiting context.

Actual: Current directory remains changed.

Fix:

Change line 269 in utils.py from:

old = os.curdir

to:

old = os.getcwd()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions