-
Notifications
You must be signed in to change notification settings - Fork 89
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
refactor!: disable iteration of records #1725
Conversation
First, what's the exclamation point for? The "Lint PR" test accepts it as an okay prefix. From a Scheme context, I'd think it's allowing mutation (which all PRs do...). |
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.
Yes, we should prevent all iteration on Records. (I remember that conversation.)
The way you do this is new to me: I assume that __iter__ = None
is different from not defining an __iter__
method (Python apparently doesn't try to call None
as a function). I suppose it prevents Python from assuming an iteration algorithm using __getitem__
? But then, if Python is going to assume iteration using __getitem__
, how does it know what keys/indexes it can pass to __getitem__
are? With Record as it is currently defined and without __iter__
, does it try to iterate?
Huh—this is interesting:
>>> class Something:
... def __getitem__(self, index):
... return index
...
>>> for x in Something():
... print(x)
...
0
1
2
3
4
5
... (forever)
And __iter__ = None
prevents that? Is the error message any better than "iteration on None is not allowed?" Maybe it would be better to define an __iter__
that immediately raises a good error message.
Codecov Report
Additional details and impacted files
|
The
Yes: >>> iter(record)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 iter(record)
TypeError: 'Record' object is not iterable |
I'm going to auto-merge this, because you've approved the change, and I'm confident that you'd support following the Python docs in using |
Sorry @jpivarski, I missed this comment. It implies that the commit / PR contains a breaking change. It's really a case where you're removing a feature, rather than just refactoring internal code that won't really affect the user. |
Fixes #1582 by making
ak.highlevel.Record
non-iterable. Nothing else is changed, as the v2builder_from_iter
supports anything that implements ato_list
ortolist
method, such asak.Record
andak.record.Record