Skip to content

fix % in to f String - #12405

Closed
Aditya3425-Fst wants to merge 3 commits into
mne-tools:mainfrom
Aditya3425-Fst:Replace_percent_format_with_format_specifiers
Closed

Aditya3425-Fst wants to merge 3 commits into
mne-tools:mainfrom
Aditya3425-Fst:Replace_percent_format_with_format_specifiers

Conversation

@Aditya3425-Fst

Copy link
Copy Markdown

#12360
Summary:
This pull request addresses the conversion of "%" symbols into f-strings for improved readability and maintainability.

Changes Made:

Replaced "%" formatting with f-strings for string interpolation.
Updated relevant code blocks to adhere to the Python 3.6 and later syntax.
Benefits:

Enhanced code clarity: f-strings provide a more concise and readable syntax for string formatting.
Improved maintainability: The use of f-strings aligns with modern Python practices, making the codebase more up-to-date.
Testing:

Ensured that the changes do not introduce any functional issues.
Conducted thorough testing to validate the correctness of the converted f-strings.
Additional Notes:

No changes to the logic or functionality of the code, only a syntactic enhancement.
Compatible with Python 3.6 and later versions.

Please review the changes, and feel free to provide feedback or ask for further clarification if needed.

@welcome

welcome Bot commented Jan 31, 2024

Copy link
Copy Markdown

Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴

@cbrnr

cbrnr commented Feb 2, 2024 •

Copy link
Copy Markdown
Contributor

Thanks for taking a stab! There are several things that should be addressed:

  1. Please remove the previous statements instead of commenting them out.
  2. Make sure no lines exceed 88 characters.
  3. If there is only one object to print, there is no need to keep the tuple (e.g. "%s" % (x,) should be f"{x}" and not f"{x,}").

@mscheltienne mscheltienne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking at the 2 first files, I'm spotting several typos in capital letters or spacing. Could you go through your proposed changes again and fix those first?

Comment thread mne/fixes.py
Comment on lines +269 to +270
# "Invalid parameter %s for estimator %s. "
f"Invalid parameter{name}for estimator{self}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# "Invalid parameter %s for estimator %s. "
f"Invalid parameter{name}for estimator{self}"
f"Invalid parameter {name} for estimator {self}. "

Comment thread mne/fixes.py
Comment on lines +197 to +198
# " %s with constructor %s doesn't "
f"{cls} with constructor {init_signature} doesn't follow this convention."

@mscheltienne mscheltienne Feb 5, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# " %s with constructor %s doesn't "
f"{cls} with constructor {init_signature} doesn't follow this convention."
f" {cls} with constructor {init_signature} doesn't follow this convention."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's also 2 spaces after "doesn't"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

fixed in the suggested change.

Comment thread mne/fixes.py
Comment on lines +102 to +103
# warn("SVD error (%s), attempting to use GESVD instead of GESDD" % (exp,))
warn(f"SVD error ({exp}), attempting to use GESVD instend of GESDD")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# warn("SVD error (%s), attempting to use GESVD instead of GESDD" % (exp,))
warn(f"SVD error ({exp}), attempting to use GESVD instend of GESDD")
warn(f"SVD error ({exp}), attempting to use GESVD instend of GESDD")

Comment thread mne/fixes.py
Comment on lines +280 to +281
# "Invalid parameter %s for estimator %s. "
f"Invalid parameter {key}for estimator{self.__class__.__name__} for estimator"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# "Invalid parameter %s for estimator %s. "
f"Invalid parameter {key}for estimator{self.__class__.__name__} for estimator"
f"Invalid parameter {key} for estimator {self.__class__.__name__}. "

Comment thread mne/fixes.py
Comment on lines +293 to +294
# return "%s(%s)" % (class_name, self.__class__.__name__)
return f"{class_name}({self.__class__.__name__})"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# return "%s(%s)" % (class_name, self.__class__.__name__)
return f"{class_name}({self.__class__.__name__})"
return f"{class_name}({params.read().strip()})"

Comment on lines +664 to +665
# msg = "Coil too close (dist = %g mm)" % (min_dist * 1000,)
msg = f"coil too close (dist = {(min_dist * 1000,)}mm)"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This one does not remove the trailing zeroes as %g does.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants