You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
First, I love what you are doing with this library. There is just one thing holding me back from using it. I would like to name the fields, rather than access them with positional indexing. Something like what I am showing below.
@adtclassExampleADT:
EMPTY: CaseINTEGER: Case[int]
STRING_PAIR: Case[foo: str, bar: str]
The accessor method could return a NamedTuple instead of just a Tuple.
defstring_pair(self) ->Tuple[str, str]:
# unpacks strings and returns them in a tuple
The text was updated successfully, but these errors were encountered:
I too would really like to do something like this. Unfortunately, we are ultimately constrained by the syntax of the language and what is observable through mypy, so I'm not sure how to make the example as written (Case[foo: str, bar: str]) valid.
One workaround could be to define a separate type which names the fields you care about—e.g.:
A possibility here could be to permit a "special" initial value for the field, which names the arguments—something like:
@adtclassExampleADT:
STRING_PAIR=NamedCase(foo: str, bar: str)
If our mypy plugin would be able to extract str, str from this, then we should still have enough type information to check that the Cases are being used correctly. I haven't thought about it a whole lot, though. 😄
If you or anyone would like to take a stab at something like this, I'd be happy to help and/or review the code—just let me know!
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
First, I love what you are doing with this library. There is just one thing holding me back from using it. I would like to name the fields, rather than access them with positional indexing. Something like what I am showing below.
The accessor method could return a
NamedTuple
instead of just aTuple
.The text was updated successfully, but these errors were encountered: