-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Make sequtils.zip return seq of anonymous tuples #12575
Conversation
cfb9d55
to
4cda53a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add a test that tests the behavior that you want. Test the assignment to a named tuple with some arbitrary names.
@krux02 That's a good idea. I'll get such a test in by tomorrow. |
I just want to mention that I was once bothered by the field names in the tuple as well. So thumbs up for this PR. |
4cda53a
to
94f453a
Compare
Thanks :) I have updated the tests. |
cda6efb
to
0e0aa60
Compare
0e0aa60
to
594f8ab
Compare
So anonymous tuples can be assigned to other anonymous tuples or to named tuples (i.e. structural typing) but named tuples can only be assigned to other named tuples (i.e. "string"/"identifier" typing). I think this part is underspecified. Also while we tuple destructuring works for both anonymous and named tuple, maybe a function or magic that anonymize named tuples is needed for function call chaining like the original case? |
No, named tuples can be assigned to named tuples with the exact name fields, or also to any anonymous tuple. |
Does this break backwards compatibility at all? |
@Varriount Yes, slightly, if someone is relying on inferred typing. E.g. this will break:
But this will not break:
|
Good point about the breaking behavior. We do have a backwards compatibility claim. But I am still positive for this change, since I really do like it. You should introduce a backwards compatibility branch. This is how you do it: when (NimMajor, NimMinor) <= (1, 0) # 1.0.x
# old declaration here
else:
# new declration here Of course you also need to have a test for the old version (reintroduce the broken tests into another file that is compiled with |
OK, I'll get to this later today. I have a question though.. Does the CI run all the tests with and without |
No and it's worse than that, right now |
Also, looks like Update: I'm not staying that that is bad. I am just confirming what I understand here. It's good that people get either all the old stuff in one go or all the new better stuff. If they choose to keep their code untouched and frozen in Nim 1.0, then this wouldn't make any difference to them. |
Yes, it applies to the whole core. |
Earlier the tuples had named fields "a" and "b" and that made it difficult to assign the zip returned seqs to other vars which expected seqs of tuples with field names other than "a" and "b".
594f8ab
to
576993f
Compare
576993f
to
c0b597c
Compare
I have redone the code change to make /cc @narimiran @PMunch Can you please review c0b597c ? |
* Make sequtils.zip return seq of anonymous tuples Earlier the tuples had named fields "a" and "b" and that made it difficult to assign the zip returned seqs to other vars which expected seqs of tuples with field names other than "a" and "b". * Make sequtils.zip backwards compatible with Nim 1.0.x
Earlier the tuples had named fields "a" and "b" and that made it
difficult to assign the zip returned seqs to other vars which expected
seqs of tuples with field names other than "a" and "b".