Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsupported class decorator #110

Closed
ijustlovemath opened this issue Dec 14, 2022 · 4 comments
Closed

Unsupported class decorator #110

ijustlovemath opened this issue Dec 14, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@ijustlovemath
Copy link

ijustlovemath commented Dec 14, 2022

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

@inumanag
Copy link
Contributor

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.

@inumanag inumanag added the enhancement New feature or request label Dec 18, 2022
@ijustlovemath
Copy link
Author

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!

@ShalokShalom
Copy link

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. 😢

@inumanag
Copy link
Contributor

inumanag commented Nov 8, 2024

Please see #606 to track the implementation progress.

@inumanag inumanag closed this as completed Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants