mojo
mojo copied to clipboard
[Feature Request] Add functionality like `@classmethod` to enforce conditional conformance on struct static methods
Review Mojo's priorities
- [X] I have read the roadmap and priorities and I believe this request falls within the 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.