Skip to content

[Bug]: _csv.Reader and _csv.Writer are named Reader and Writer instead of reader and writer #1259

Open

Description

@jseop-lim

Describe the bug

The types of csv.reader() and csv.writer() objects report themselves as _csv.Reader and _csv.Writer. In CPython they are named _csv.reader and _csv.writer and are only exported under the attributes Reader and Writer.

Operating system

macOS

CPU architecture

ARM64

GraalPy version

master a3009f9 (Python 3.13.14); also reproduced on 25.1.3 (Python 3.12.8)

JDK version

No response

Context configuration

No response

Steps to reproduce

import csv
print(type(csv.reader([])))

GraalPy master:

<class '_csv.Reader'>

Expected behavior

CPython 3.13.14 (same on 3.12.13):

<class '_csv.reader'>

Stack trace

Additional context

__name__, __qualname__ and repr() of the objects differ the same way, and type(csv.writer(f)) is <class '_csv.Writer'> instead of <class '_csv.writer'>. type(csv.reader([])) is _csv.Reader holds on both.

Root Cause

PythonBuiltinClassType declares CSVReader("Reader", ...) and CSVWriter("Writer", ...) with publishInModule("_csv") (PythonBuiltinClassType.java#L1317-L1318), so one string is both the module attribute and the type name. CPython names the types _csv.reader and _csv.writer (_csv.c#L1055, #L1508) and adds them to the module as Reader and Writer (#L1752-L1762).

Fix Suggestion

Name the types reader and writer with moduleName("_csv") instead of publishInModule("_csv"), which would shadow the reader() and writer() functions, and add the Reader and Writer aliases in CSVModuleBuiltins.initialize (CSVModuleBuiltins.java#L114-L125), as SocketModuleBuiltins does for SocketType.

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions