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

add EdgeList.__contains__ #754

Closed
wants to merge 1 commit into from
Closed

Conversation

eric-wieser
Copy link
Contributor

Python dictionaries support indexing by tuples

@eric-wieser
Copy link
Contributor Author

Obviously has is public api, so can't be removed entirely

@@ -200,9 +203,9 @@ def __init__(self, start, end, label=''):
self.start = start
self.end = end
self.label = label
self.key = "%s|%s"%(self.start, self.label)
self.key = (self.start, self.label)
Copy link
Member

Choose a reason for hiding this comment

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

These slots are public API of an edge and therefore can't change their value like this.

Same for rkey below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the value of rkey itself is considered public api, not just the value of the expression edges_by_start[rkey]? Darn.

Copy link
Member

Choose a reason for hiding this comment

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

An Edge is basically like a struct. All member are public and likely being used by user land code..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Darn, I can't really argue with the fact that people might be relying on this. Is | a valid character in node or edge names? (ie, can I frame this as a bug, in which case breaking reliance of a bug is perhaps more ok)

Or should I just rebase this PR to just be the __contains__ above?

Copy link
Member

Choose a reason for hiding this comment

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

No, | is not a valid character in node or edge names. So it is safe to be used as a separator.

Yes, please update the PR - and squash the commits on this branch. The __contains__ is certainly the significant of this PR. The slightly easier implementation of __iter__ as well as the set initializations below are more cosmetic but you can keep those.

@dirk-thomas
Copy link
Member

@ros-pull-request-builder retest this please

@dirk-thomas
Copy link
Member

Please rebase the patch against current indigo-devel since it seems to contain an old patch which results in a syntax error.

@eric-wieser
Copy link
Contributor Author

Looks like you did a rewrite of published history there! Corrected now

@eric-wieser eric-wieser changed the title Cleanup to rosgraph Deprecate EdgeList.has in favor of EdgeList.__contains__ Jun 20, 2016
@dirk-thomas dirk-thomas changed the title Deprecate EdgeList.has in favor of EdgeList.__contains__ add EdgeList.__contains__ Jun 27, 2016
@dirk-thomas
Copy link
Member

dirk-thomas commented Jun 27, 2016

Thanks for the patch. I have applied a modified version to the kinetic-devel branch: 5de058a Since the has method is not actually deprecated I removed the comment. I also skipped the cleanup changes.

@eric-wieser
Copy link
Contributor Author

Since the has method is not actually deprecated

Part of this pull request was me requesting that it should be, in the same way that dict.has_key is. not assuming that it was.

If you think it shouldn't be, then that's fine - it's not my call to make.

Thanks for the merge!

@dirk-thomas
Copy link
Member

Personally I do agree with you that cleaning up the API is nice. But based on the amount of code using this API it is not worth "forcing" the people to update it. Sorry.

@eric-wieser
Copy link
Contributor Author

eric-wieser commented Jun 28, 2016

But based on the amount of code using this API it is not worth "forcing" the people to update it. Sorry.

Deprecation doesn't ever need to lead to forcing people to update it - my goal was to stop anyone ever using .has in new code.

Also, this strikes me as a rather internal API, so I'd be surprised if that much code actually uses it anyway.

At any rate, I half-assed this, and if I was going for deprecation should probably have included a DeprecationWarning, so rejecting the rest of the patch is the right thing to do

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

Successfully merging this pull request may close these issues.

None yet

2 participants