Skip to content

super() raises TypeError in a ctypes.util.struct method #158418

Description

@fedonman

Bug description:

Zero-argument super() raises TypeError in a method of a class decorated with ctypes.util.struct:

from ctypes import c_int
from ctypes.util import struct

@struct
class Point:
    x: c_int
    y: c_int
    def __init__(self, x=0, y=0):
        super().__init__(x, y)

print(Point(1, 2).x)
TypeError: super(type, obj): obj (instance of Point) is not an instance or subtype of type (Point).

The same method on a plain Structure subclass works. __class__ in such a method also refers to the original class instead of the one the decorator returns.

Expected: super() and __class__ refer to the class returned by @struct, and the example prints 1.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

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

    3.16new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-ctypestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions