Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

[Feature Request] Add functionality like @classmethod to enforce conditional conformance on struct static methods #3305

Closed
1 task done
martinvuyk opened this issue Jul 25, 2024 · 1 comment
Labels
enhancement New feature or request mojo-repo Tag all issues with this label

Comments

@martinvuyk
Copy link
Contributor

martinvuyk commented Jul 25, 2024

Review Mojo's priorities

What is your request?

Add functionality like @classmethod to enforce conditional conformance on struct static methods

What is your motivation for this change?

Being able to constraint the calling of a static method according to struct parameters

    @classmethod
    fn create_server(
        cls: Socket[SockFamily.AF_INET, SockType.SOCK_STREAM, *_],
        address: IPv4Addr,
        *,
        backlog: Optional[Int] = None,
        reuse_port: Bool = False,
    ) raises -> __type_of(cls):
        ...

Any other details?

I don't think it would be a good idea to call them @classmethod like Python because it would tie the implementations together (I have no idea what the dynamism of Classes will entail but I imagine it won't be a good idea to mix them together) and be confusing conceptually like @gryznar pointed out in issue #2010 , but I wouldn't remove the method part either. I think just calling them @structmethod and making the first arg stc (convention, but can call them whatever) will be easy to explain to python devs.

@martinvuyk martinvuyk added enhancement New feature or request mojo-repo Tag all issues with this label labels Jul 25, 2024
Copy link
Collaborator

Mogball commented Aug 14, 2024

This should already work. Please give it a try again!

@Mogball Mogball closed this as completed Aug 14, 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 mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

2 participants