-
-
Notifications
You must be signed in to change notification settings - Fork 9.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
BUG: check_api_dict does not correctly handle tuple values #8911
Conversation
093b3da
to
9feda1d
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.
Is it just me, or did the original code make no sense at all...? If we did have fully duplicate indices, wouldn't that be silently discarded before we ever made it into this function?
I ended up finding this because the code was detecting a duplicate index, but then crashed when trying to tell me which one it was. So the old code did work, and clearly didn't go with the transition to |
numpy/core/code_generators/genapi.py
Outdated
Same index has been used twice in api definition: %s | ||
""" % ['index %d -> %s' % (index, names) for index, names in doubled.items() \ | ||
if len(names) != 1] | ||
msg = "Same index has been used twice in api definition: {}".format( |
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.
Might look better if this was broken into a fmt
and val
, and then ValueError(fmt.format(val))
or some such.
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.
Problem is, the format is sort of contained in val
as well:
fmt = "Same index has been used twice in api definition: {}"
val = ''.join(
'\n\tindex {} -> {}'.format(index, names)
for index, names in doubled.items() if len(names) != 1
)
raise ValueError(fmt.format(val))
I don't think that fmt
and val
are useful names here, because both contain format strnigs
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.
I guess I could do:
dupes = {index: names for index, names in doubled.items() if len(names) != 1}
raise ValueError("Same index has been used twice in api definition: {}".format(
''.join(
'\n\tindex %d -> %s' % (index, names)
for index, names in dupes.items()
)
)
Although this is really bikeshedding, and I don't really want to switch working tree again...
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.
Nothing wrong with bikeshedding, code clarity is part of the process...
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.
Do you have a preference between the one in this PR and the two alternatives above?
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.
I rather like the first. Probably put the closing )
for val
at the end of the preceding line there.
LGTM, maybe a style nit. |
Need to finish this up. |
It seems that at some point we augmented the indices with extra data. But this data should not be included when determining uniqueness. Previously, this would crash if there actually was a collision, rather than printing a useful message
As requested by @charris
9feda1d
to
6dbaf77
Compare
@charris: Done |
@charris: Ping - ball is in your court now |
Tnanks Eric. |
It seems that at some point we augmented the indices with extra data. But this
data should not be included when determining uniqueness.
Previously, this would crash if there actually was a collision, rather than
printing a useful message