-
Notifications
You must be signed in to change notification settings - Fork 30
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
Using index() on the BlockBase.content
list does not work
#174
Comments
@rupertford, if you're happy with my suggested solution then I'm happy to take this one. |
I had a similar problem when integrating fparser2 into PSyclone for parsing the algorithm layer. Python 3 does not allow you to use an object as a dictionary key if it defines its own equals operator (but Python 2 does not care). My workaround was to avoid using an fparser2 instance as a dictionary key, but that obviously did not solve the underlying issue. |
I don't think I understand enough to know whether your suggested solution is good or not. The mixin class means that all equivalence operations for fparser2 are based on the values in the objects rather than the objects themselves being the same. I'm not sure if this is the behaviour we (or others) want, or expect. Do you have any thoughts? One option would be to remove the mixin class. I don't think it is required for fparser2 to function correctly. This would mean all equivalences would be based on whether the instances were the same or not. This is what I would expect to happen when traversing a tree of objects, so that would be my (perhaps naive) preference. |
Ah! I was assuming the mixin class was required. If it isn't then we should get rid of it! |
|
If I replace
Alternatively, if I change the implementation of |
Many of the test failures are because comparing two different instances of
As in the PSyIR, testing two nodes for equality could present some subtleties. |
I haven't looked into this in detail, so please disregard if this sounds stupid: |
I've fallen over this twice now. I think the problem occurs because
Base
(and thereforeBlockBase
) inherit fromComparableMixin
which re-defines the comparison operators. As a result, usingmy_node.content.index(other_node)
fails to findother_node
, even if it exists inmy_node.content
.A possible solution to this is to make
content
an instance of some custom list class that puts back the correctindex
functionality (e.g. usingis
to compare the search node with the members ofcontent
).The text was updated successfully, but these errors were encountered: