Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I read your blog post and TBH I'm not really sure what extension types are, I've never used rust. But I tried this solution in python and am curious is this is something you tried?

    >>> class A:
    ...    def foo(self):
    ...        print('foo')
    ...
    >>> class B:
    ...    def bar(self):
    ...        print('bar')
    ...
    >>> A.bar = B.bar
    >>> A().bar()
    bar
Functions in python are objects as well. So while you can't do this to built in python types, there is a high likelihood you can do this to most objects in python libraries.


The problem with your code is that it won't type check. It runs just fine because CPython doesn't care about type checking. But if you run mypy on it it will not understand.


Oh I see, yea you are correct




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: