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

mut-invariance #7

Open
rymiel opened this issue Jul 3, 2022 · 0 comments
Open

mut-invariance #7

rymiel opened this issue Jul 3, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@rymiel
Copy link
Member

rymiel commented Jul 3, 2022

Simple getters may want to return a mutable reference to a field if the object being accessed is mutable, but an immutable one otherwise. This would cause code duplication, which, although mild for the "simple getter" case, is still duplication, and can be seen in languages like C++ where writing const overloads is a requirement.

I propose a qualifier like mut*, which will declare two methods, one of which is mut and the other isn't, but otherwise with the same body, for example:

def Foo.get_something(self mut*) Bar mut* = ...

when Foo.get_something is called with Foo mut, the result is Bar mut, but if it is instead called with Foo, the result is simply Bar.

I am unsure how far this feature should extend, since i only see a real use case for them in the "self" argument case, so the feature may initially be restricted to only the self argument and the return type, however it is also way too early to say since this is still merely an idea

@rymiel rymiel added missing-feature enhancement New feature or request and removed missing-feature labels Jul 3, 2022
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

1 participant