codon
codon copied to clipboard
Unsupported class decorator
Saw this project on HN and wanted to try it out! In my application there's a class used to keep track of other eligible classes using a decorator. This is great for automatically adding new functionality by just plopping a decorator onto a class, but it's not supported.
Using codon 0.15.2
Here's a minimal example:
a.py
class Keeper:
stuff = []
@classmethod
def register(cls, thing):
cls.stuff.append(thing)
return thing
@Keeper.register
class Car:
pass
@Keeper.register
class Boat:
pass
for thing in Keeper.stuff:
print(thing.__name__)
When run, I get the following output:
% codon build a.py
a.py:9:2-17: error: unsupported class decorator
I ran this from WSL Debian, but that hopefully shouldn't matter. Let me know if you need any other information
Codon does not yet support class decorators and metaclasses (with some very limited exceptions; e.g., dataclass
).
No ETA is available at the moment as it's not a trivial fix. If there's a widespread interest in this feature, however, we'll prioritize it.
Sounds good! I think I'm probably not alone in my love of class decorators, they let you do some nice Pythonic things. Totally understand that they're probably hell to fit into a static typing system, though. Metaclasses are a little beyond where I've ever needed to go, so if there's a happy medium, you'd definitely cover my use case.
Thanks for your work on this project!
This fails for me for dataclass. This seems to be unintended?
P.S: I think @final, and generally custom decorators (with @wrap, or renamed ones, like
data = partial(dataclass, slots=True, frozen=typing.TYPE_CHECKING)
is an important area as well.
I like to implement a tagged union, and hope that would be supported by Codon. 😢