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

Restore the standard behaviour of reversed(Lattice) #589

Merged
merged 1 commit into from
Apr 3, 2023
Merged

Conversation

lfarv
Copy link
Contributor

@lfarv lfarv commented Apr 2, 2023

This PR restores the standard behaviour of the reversed() iterator for Lattice objects: the behaviour introduced in #573 could be confusing, since it was iterating on copies of the elements instead of element themselves.

As a consequence, the only way to build reversed lattices by swapping entrance and exit faces is to use the Lattice.reversed() method.

@lfarv lfarv added the Python For python AT code label Apr 2, 2023
@lfarv lfarv requested a review from swhite2401 April 2, 2023 15:33
Copy link
Contributor

@swhite2401 swhite2401 left a comment

Choose a reason for hiding this comment

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

I don't understand why you have systematically changed the docstrings of the keyword argument copy

Parameters:
idx (SupportsIndex): index at which the lement is inserted
elem (Element): AT element to be inserted in the lattice
copy_elements(bool): Default :py:obj:`True`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't copy_elements a keyword argument?

Parameters:
elems (Iterable[Element]): Sequence of AT elements to be
appended to the lattice
copy_elements(bool): Default :py:obj:`True`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment

@@ -359,8 +352,6 @@ def append(self, elem: Element, copy_elements=False):

Parameters:
elem (Element): AT element to be appended to the lattice

Keyword Arguments:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment

lattice are used for the repetition
Parameters:
n (int): number of repetition
copy_elements(bool): Default :py:obj:`True`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment

@@ -427,8 +416,6 @@ def concatenate(self, *lattices: Iterable[Element],
lattices: :py:obj:`Iterables[Element]` to be concatenanted
to the Lattice, several lattices are allowed
(see example)

Keyword Arguments:
copy_elements(bool): Default :py:obj:`False`. If :py:obj:`True`
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment for these 2

>>> newring = ring.reverse(copy=True)

Keyword Arguments:
Parameters:
copy(bool): Default :py:obj:`False`. If :py:obj:`True`
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to keep them as keywords, but I get lots of warnings in PyCharm about arguments missing in docstrings: apparently for Sphinx, every argument mentioned in he parameter list must be mentioned in the "Args:" section, "Keyword Args:" is reserved for those in kwargs

I can live with warnings, but they may hide important ones… I like to keep the "Problems" tab empty.

Copy link
Contributor Author

@lfarv lfarv Apr 3, 2023

Choose a reason for hiding this comment

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

By the way, I got a similar problem with the "Usage:" section: "Usage:" is not a valid section for sphinx, and it was not formatted properly as python code in the output. That's why I converted it to an "Example:" section…

return Lattice(elem_generator, elems, iterator=self.attrs_filter)
else:
reversed_list = list(reversed(self))
reversed_list = list(elems)
Copy link
Contributor

Choose a reason for hiding this comment

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

Doing this you copy the elements. Is it possible and would it make sense to return the elements themselves by using copy=copy in the elems generator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No copy is a problem: if the same element is used twice in the ring, it will be swapped twice, and the second one in the reversed lattice will be wrong.

@swhite2401 swhite2401 self-requested a review April 3, 2023 07:09
@swhite2401
Copy link
Contributor

Ok thanks for the clarification, all good for me!

@lfarv lfarv merged commit 6d87179 into master Apr 3, 2023
@lfarv lfarv deleted the reverse_lattice branch April 3, 2023 09:28
@lfarv lfarv mentioned this pull request Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Python For python AT code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants