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

Don't check for ops in reverseOps before removing it, just try it. #469

Merged
merged 1 commit into from
Mar 6, 2015

Conversation

bcroq
Copy link
Contributor

@bcroq bcroq commented Mar 5, 2015

No description provided.

@joernhees joernhees added this to the rdflib 4.2.1 milestone Mar 5, 2015
try:
self.reverseOps.remove((s, p, o, ctxId, 'add'))
except ValueError:
pass
Copy link
Member

Choose a reason for hiding this comment

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

not so much a comment for this change, but for my understanding: is this to "compress" the reverseOps only?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In add() there was a bug: it checks if (s, p, o, ctxId, 'remove') is in self.reverseOps and if it is found it removes (s, p, o, context, 'add')

Then, it is generally a bad idea to check if an element is in a list before removing it. Just try to remove and deal with the ValueError exception.

if x in l:
    l.remove(x)
else:
    l.add(y)

becomes:

try:
    l.remove(x)
except ValueError:
    l.add(y)

It saves an uneeded call to __contains__

joernhees added a commit that referenced this pull request Mar 6, 2015
Don't check for ops in reverseOps before removing it, just try it.
@joernhees joernhees merged commit a33537b into RDFLib:master Mar 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants