3 ms·
I personally consider code generation an anti-pattern in Python. With its dynamic nature and the two-step execution model, Python is essentially its own macro l
by BerislavLopac 4y ago
I personally consider code generation an anti-pattern in Python. With its dynamic nature and the two-step execution model, Python is essentially its own macro language, and any generation can be done at runtime.
- zzzeek 4y agounfortunately pep-484 changed all that. now you have to use static generation for basically anything that used to be at runtime previously, if you want it to have any kind of compatibility with mypy, pylance, etc.
- xapata 4y agoMyPy doesn't require everything to be type-hinted. It's fine to sprinkle in hints where you want them.
- zzzeek 4y agowhen people using your library need pylance type hinting to show up for all your public methods, and those public methods are in fact generated as proxies for some other object. This was trivial as a dynamic runtime thing before, now must be statically generated. I can share examples if you'd like.
- BerislavLopac 4y agoSo the only problem is type hinting in IDEs. That's a small price to pay.