10000 Calls to super inside pattern-matching classmethods do not work · Issue #728 · evhub/coconut · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Calls to super inside pattern-matching classmethods do not work #728
Closed
@yggdr

Description

@yggdr

A call to super inside a pattern-matching method that's defined as a classmethod fails with TypeError:

class A:
    @classmethod
    addpattern def method(cls, {'somekey': str()}) = True


class B(A):
    @classmethod
    addpattern def method(cls, {'someotherkey': int(), **rest}) =
        super().method(rest)


B().method({'somekey': 'string', 'someotherkey': 42})
Traceback (most recent call last):
    File "cococlassmethod.py", line 2074, in <module>
      B().method({'somekey': 'string', 'someotherkey': 42})
    File "cococlassmethod.py", line 2070, in method
      return (super().method(rest))
    File "cococlassmethod.py", line 29, in _coconut_super
      return _coconut_py_super(cls, self)
  TypeError: super(type, obj): obj must be an instance or subtype of type

It seems the code that's supposed to make parameterless super() possible on older python versions doesn't handle the pattern-matching part correctly. I looked into this a bit and it seems the part where the super-implementation tries to get the self it fetches some tuple instead.

frame.f_code.co_varnames[0] ==> '_coconut_match_args'
frame.f_locals[frame.f_code.co_varnames[0]] ==> (the-class-I-call-the-super-inside, the-dict-I-pass-into-the-function-to-be-pattern-matched)

What I'm a bit surprised by is that coconut compiles this super even on targets like 3.11 where parameterless super is supported.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0