5 ms·
I'll take almost any cost for extension traits. Going back to Python this is part of what I miss most. There is no way to add methods to a type in Python that
by staticassertion 5y ago
I'll take almost any cost for extension traits. Going back to Python this is part of what I miss most.
There is no way to add methods to a type in Python that mypy understands. You have to create a new type. This leads to code that is very difficult to extend and pushes you towards inheritance.
I talk a bit about this here:
https://insanitybit.github.io/2020/07/19/intersection-types-in-python https://insanitybit.github.io/2020/07/19/intersection-types-...
For me, this became a huge problem when I was building a plugin system in Python. I wanted types to only own their own logic, but I also wanted types to be able to tell other types about themselves. For example, we have a Process and a File. I want to be able to go from Process to File with only one of those knowing about the other. Without extensions you are forced to create ugly workarounds.
Also, I've never had a problem with intellij and extension traits. I kind of wonder why you'd stick with a tool that's a bad experience.
- animal_spirits 5y agoI 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.
- staticassertion 5y agoThe 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.
- animal_spirits 5y agoOh I see, yea you are correct