-
Notifications
You must be signed in to change notification settings - Fork 36
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
bug in _sorteddict.KeysView #41
Comments
Thanks for finding this problem and digging into it. Python allows a classmethod to be overridden with an instance method. Would the following work?
I agree that it's not clear what the caller expects when mixing sort keys. Probably it should raise an exception? In that case, it would be necessary to override |
I would not like an override for 2 reasons.
An alternative that doesn't suffer from these problems is to make So I like your second proposal the most: remove _from_iterable entirely,
If no good answer to that is available, perhaps just let this be a I'm asking a question about it on SO: If this can be done, ideally it should be done at construction (i.e., Max On Sat, Mar 31, 2012 at 11:29 AM, Daniel Stutzbach <
|
Checking if two functions have identical functionality is undecidable. It'd be safest and easiest to just check if the two key functions are the same function using the "is" operator. |
Well, it's undecidable in general, but it can be easily decided for the
The only time I might recommend doing anything other than "is" operator is
Finally, the sort key function could be a callable function, rather than a function; e.g., For the time being, I wouldn't worry about that, and just like you suggest, use Max On Apr 1, 2012 8:38 AM, "Daniel Stutzbach" <
|
Example:
fails with
AttributeError
. The culprit is the following method in_sorteddict.KeysView
:First, this method is probably meant to be
@classmethod
. Second, the call tosortedset
needsit
as the first argument. Third,_mapping
is only available from an instance, which we don't have here.After the (trivial) fix to address the first two issues, the code I showed above works fine.
However, if
sorteddict
instance uses a custom sort key, it is lost. I don't know how to fix this. Possibly it shouldn't be fixed; what sort key should be used if the two sorteddict have different sort keys? Using the one from the LHS is quite arbitrary, even if we could retrieve it. I really don't know what the right approach is here.The text was updated successfully, but these errors were encountered: