Skip to content

fix: os module value access generates undefined 'os' identifier #200

@noahgift

Description

@noahgift

Problem

When Python code accesses os module functions/attributes, the transpiled Rust generates references to an undefined os value:

import os
path = os.path.join("a", "b")  # E0425: cannot find value `os` in this scope
cwd = os.getcwd()              # E0425: cannot find value `os` in this scope

Impact

16 files in the reprorusted-python-cli corpus fail due to this issue.

Suggested Fix

Map common os module functions to Rust equivalents:

Python Rust
os.getcwd() std::env::current_dir()
os.path.join(a, b) std::path::Path::new(a).join(b)
os.path.exists(p) std::path::Path::new(p).exists()
os.path.dirname(p) std::path::Path::new(p).parent()
os.path.basename(p) std::path::Path::new(p).file_name()
os.environ.get(k) std::env::var(k)
os.listdir(p) std::fs::read_dir(p)

Corpus Evidence

From reprorusted-python-cli error analysis:

  • E0425 (cannot find value) accounts for 10.0% of all compilation errors
  • 16 examples specifically fail on os module access

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions