Skip to content

Can't decorate an overridden method #767

@msullivan

Description

@msullivan
import functools

class Foo:
    def f(self, x: int) -> int:
        return x

class Bar(Foo):
    @functools.lru_cache()
    def f(self, x: int) -> int:
        return x + 1

crashes with

  File "/home/sully/src/mypy/mypyc/irbuild/function.py", line 379, in handle_ext_method
    and not is_same_method_signature(class_ir.method_decls[name].sig,
over.py:8: KeyError: 'f'

Typically we don't put decorated functions in the vtable since we invoke them through the API. We should generate native glue wrappers that delegate to the decorated callable object, like we do when allowing interpreted subclasses.
(If we implement #481 (storing decorated functions in globals for faster lookup), we should just always use native wrappers to save a dict lookup.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcrashFailing compile-time asserts, unhandled exceptions, or generated C code that's blowing up.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions