| ▲ | seanwilson 7 hours ago | |||||||||||||
> The real story is that Python is designed to be maximally dynamic -- you can monkey-patch methods at runtime, replace builtins, change a class's inheritance chain while instances exist -- and that design makes it fundamentally hard to optimize. ... > 4 bytes of number, 24 bytes of machinery to support dynamism. a + b means: dereference two heap pointers, look up type slots, dispatch to int.__add__, allocate a new PyObject for the result (unless it hits the small-integer cache), update reference counts. Would Python be a lot less useful without being maximally dynamic everywhere? Are there domains/frameworks/packages that benefit from this where this is a good trade-off? I can't think of cases in strong statically typed languages where I've wanted something like monkey patching, and when I see monkey patching elsewhere there's often some reasonable alternative or it only needs to be used very rarely. | ||||||||||||||
| ▲ | bloaf 6 hours ago | parent | next [-] | |||||||||||||
I've always thought the flexibility should allow python to consume things like gRPC proto files or OpenAPI docs and auto-generate the classes/methods at runtime as opposed to using codegen tools. But as far as I know, there aren't any libraries out there actually doing that. | ||||||||||||||
| ||||||||||||||
| ▲ | NeutralForest 6 hours ago | parent | prev | next [-] | |||||||||||||
There are some use cases for very dynamic code, like ORMs; with descriptors you can add attributes + behavior at runtime and it's quite useful. Anyways, breaking metaprogramming and more dynamic features would mean python 4 and we know how 2 -> 3 went. I also don't think it's where the core developers are going. Also also, there are other things I'd change before going after monkey patching like some scoping rules, mutable defaults in function attributes, better async ergonomics, etc. | ||||||||||||||
| ▲ | LtWorf 7 hours ago | parent | prev [-] | |||||||||||||
I've used a library that patches the zipfile module to add support for zstd compression in zipfiles. In python3.14 the support is there, but 2 years ago you could just import this library and it would just work normally. | ||||||||||||||