4 ms·
Some of this looks excellent. E.g. I occasionally add features like the kwargs delegate in my own code, and there are plenty of places in scipy where that would
by hansvm 6y ago
Some of this looks excellent. E.g. I occasionally add features like the kwargs delegate in my own code, and there are plenty of places in scipy where that would be an improvement.
Other bits of it aren't drastically better than the standard library. Their typeddispatch is undeniably useful, but functools.singledispatch covers most use cases, and it'd be a shame to pull in all of fastcore for a single feature that's probably covered by another library (e.g. the multipledispatch library).
Some of this is horrifying. There's nothing wrong with the PrePostInitMeta per se....but I guarantee that's going to be a footgun down the line, and IMO if somebody isn't able to comfortably write that metaclass themselves they probably shouldn't be using it.
- olejorgenb 6y ago@delegate would be very neat if IDEs understood it. Unfortunately doesn't seem to be the case for pycharm.
- hansvm 6y agoAgreed (though it should still work with tooling like Sphinx and would definitely work in a REPL, notebook, or debugger). That touches on a slightly bigger issue too. IDEs only approximate the language and usually fail miserably if you, e.g., do anything nontrivial with PEP-263. They'll whine when new language features like async or assignment expressions come out, they have the damnedest time inferring the type of inner functions, and so on. An IDE typically offers support for a (hopefully useful) subset of your favorite language.
- jph00 6y agoPrePostInitMeta is just adding what's already in the stdlib dataclasses, but making it available to other classes too.
- nemetroid 6y agoDataclasses have __post_init__, but they don't have a __pre_init__, do they? From what I can tell, PrePostInitMeta adds a completely new __dunder__ method with pre_init.
- hansvm 6y agoAgreed (mostly...it looks more powerful than dataclasses afaict). It looks like it could have a ton of use cases. My concern is that it seems easy to get started, but metaclass hackery is hard to get right if you do much of it. Maybe that fear is unfounded; have you found that people tend to use it responsibly? As a small side-note, on the surface I'm not seeing any reason it couldn't be implemented with something more composable like __init_subclass__, and that might be a nice touch.