Skip to content
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

implement stricter 1-to-1 checking #26

Closed
wants to merge 26 commits into from
Closed

implement stricter 1-to-1 checking #26

wants to merge 26 commits into from

Conversation

jab
Copy link
Owner

@jab jab commented Nov 28, 2015

  • raise ValueExistsException on insert new key associated with existing value
  • stifled by forceput just like CollapseException was
  • ValueExistsException replaces CollapseException since it's more general
  • rename collapsingbidict loosebidict now that ValueExistsException has replaced CollapseException
  • add forceupdate method for bulk forceput
  • update docs and tests

- raise ValueExistsException on insert new key associated with existing value
- stifled by forceput just like CollapseException
- rename collapsingbidict loosebidict now that it's loose in both cases
- add forceupdate method for bulk forceput
- ValueExistsException and CollapseException inherit from new base class BidictException
@jab
Copy link
Owner Author

jab commented Dec 1, 2015

@lordmauve thinking of merging this, but will wait if you're still interested in giving feedback first.

@lordmauve
Copy link
Collaborator

lordmauve commented Dec 2, 2015 via email

@jab
Copy link
Owner Author

jab commented Dec 2, 2015

Great, thanks for taking a look, and looking forward to hearing what you think.

A mutable bidict which always uses forcing put operations
so that it never raises :class:`ValueExistsException`.
"""
def _put(self, key, val):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny performance optimisation, but

_put = bidict.forceput

would remove function call overhead without increasing code duplication. I imagine _put() will get called a lot in loops, so this adds up.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally had that but changed it in favor of dynamic method lookup for more extensibility. Worth it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. We shouldn't make changes like this unless we've profiled what the possible speedups might be.

@lordmauve
Copy link
Collaborator

Generally, this looks superb!

@jab
Copy link
Owner Author

jab commented Dec 9, 2015

@lordmauve Thanks for reviewing and for all the great additional suggestions. (And apologies for not responding sooner, some more time-sensitive work came up.) The latest version of this branch incorporates all your feedback. Would you like to take another look before I merge?

@jab
Copy link
Owner Author

jab commented Dec 9, 2015

https://bidict.readthedocs.org/en/strict/ has also been updated with the latest.

@jab
Copy link
Owner Author

jab commented Dec 9, 2015

btw I think I also improved the code in the course of implementing these changes (see the new kwargs and factoring of BidirectionalMapping._put and the way it's now called)

@jab
Copy link
Owner Author

jab commented Dec 15, 2015

Hey @lordmauve, would like to merge this and get a release out tomorrow if possible. But can wait till you can 👍 if you think you can get to it this week?

@lordmauve
Copy link
Collaborator

Looking now...

return
if oldval is not _missing:
if overwrite_val:
del self._bwd[oldval]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there the potential here that this del will happen, and then the ValueExistsException gets raised in the other leg, leaving the map inconsistent?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent catch @lordmauve, thank you. Added tests to catch this and fixed this bug (and a couple others the tests turned up!) in 3d8bb18.

<3 u hypothesis /cc @DRMacIver ;)

@jab
Copy link
Owner Author

jab commented Dec 18, 2015

@lordmauve I think this is finally ready to merge! Thanks so much for all your helpful review. I just rebased the entire branch onto master as a single patch, new PR in #28. Will merge and cut a new release tomorrow. If you'd like to take one last look before I do, would love your final 👍. And thanks again for all your great suggestions, this next release of bidict will definitely be the best yet.

@jab jab closed this Dec 18, 2015
@lordmauve
Copy link
Collaborator

Great work! I'll have a look properly later.

@jab
Copy link
Owner Author

jab commented Dec 18, 2015

Awesome, thanks @lordmauve! Looking forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants