Skip to content

Conversation

jdsgomes
Copy link
Contributor

@jdsgomes jdsgomes commented Feb 8, 2022

Attempt to make the __repr__ uniform across the repo by:

  • adding return type
  • using almost uniquely f-strings
  • removing the pattern s.format(**self.__dict__) and making the variables we want to use explicit in the f-string

jdsgomes and others added 30 commits October 29, 2021 10:32
Co-authored-by: Vasilis Vryniotis <datumbox@users.noreply.github.com>
@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Feb 8, 2022

💊 CI failures summary and remediations

As of commit febfd09 (more details on the Dr. CI page):


None of the CI failures appear to be your fault 💚



🚧 1 ongoing upstream failure:

These were probably caused by upstream breakages that are not fixed yet.


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

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

Thanks, definitely an improvement overall. There is a minor bug and 2 nit comments.

f"{f', translate={self.shear}' if self.shear is not None else ''}"
f"{f', translate={self.interpolation.value}' if self.interpolation != InterpolationMode.NEAREST else ''}"
f"{f', translate={self.fill}' if self.fill != 0 else ''}"
f"{f', translate={self.center}' if self.center is not None else ''}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Ouch! I don't think this makes the code more readable.

f", stride={self.stride}"
f"{f', padding={self.padding}' if self.padding != (0, 0) else ''}"
f"{f', dilation={self.dilation}' if self.dilation != (1, 1) else ''}"
f"{f', groups={self.groups}' if self.groups != 1 else ''}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Same here.

f"{f', padding={self.padding}' if self.padding != (0, 0) else ''}"
f"{f', dilation={self.dilation}' if self.dilation != (1, 1) else ''}"
f"{f', groups={self.groups}' if self.groups != 1 else ''}"
f"{', bias=False' if self.bias is None else ''}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you miss a nested f?

Suggested change
f"{', bias=False' if self.bias is None else ''}"
f"{f', bias=False' if self.bias is None else ''}"

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 this case there is no need because 'bias=False is just a string without placeholders

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yes, you are right. Let's go with @NicolasHug's proposal below to avoid nesting and make the code easier to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

missed this, but I already removed the nested fstrings (different from @NicolasHug proposal). Despite his proposal is more in line with the spirit of this PR I think we can merge as it is if you agree.

@NicolasHug
Copy link
Member

Thanks for the PR @jdsgomes ,

No strong opinion but we might be able to avoid the use of the use of double-f strings like

            f"{f', translate={self.interpolation.value}' if self.interpolation != InterpolationMode.NEAREST else ''}"

by using join()?

s = "".join([
    f"x={x} if x is not None" else "",
    f"y={y} if y is not None" else "",
....
])

@jdsgomes
Copy link
Contributor Author

jdsgomes commented Feb 9, 2022

Thanks for the PR @jdsgomes ,

No strong opinion but we might be able to avoid the use of the use of double-f strings like

            f"{f', translate={self.interpolation.value}' if self.interpolation != InterpolationMode.NEAREST else ''}"

by using join()?

s = "".join([
    f"x={x} if x is not None" else "",
    f"y={y} if y is not None" else "",
....
])

Thanks for the comment. I'm reverting this.

Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

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

LGTM!

@jdsgomes jdsgomes merged commit 93c85bb into pytorch:main Feb 9, 2022
@github-actions
Copy link

github-actions bot commented Feb 9, 2022

Hey @jdsgomes!

You merged this PR, but no labels were added. The list of valid labels is available at https://github.com/pytorch/vision/blob/main/.github/process_commit.py

@jdsgomes jdsgomes self-assigned this Feb 9, 2022
facebook-github-bot pushed a commit that referenced this pull request Feb 11, 2022
Summary:
* Consolidating __repr__ strings

Reviewed By: NicolasHug

Differential Revision: D34140258

fbshipit-source-id: c3fd233d3665d7310aacec9090e1e3d6a1dd2011

Co-authored-by: Vasilis Vryniotis <datumbox@users.noreply.github.com>
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.

4 participants