Skip to content

Conversation

@py1sl
Copy link
Owner

@py1sl py1sl commented Jan 7, 2026

…in multiple files

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors string formatting across multiple Python files to use f-strings instead of string concatenation and the older % or + operators. The changes improve code readability and maintainability. Additionally, several bugs were fixed during the refactoring process, including a missing comma in a list, a typo in an attribute name, and incorrect units in a volume display.

Key changes:

  • Converted string concatenation using + operator to f-strings throughout the codebase
  • Fixed a critical bug where inputs.files_files was corrected to inputs.files_file
  • Fixed a missing comma in a list literal that would have caused string concatenation
  • Corrected volume units from "cm squared" to "cm^3"

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
r2s_cell.py Refactored string formatting to f-strings in multiple functions; fixed missing comma in list and typo in attribute name; improved None comparison
meshtal_analysis.py Refactored __str__ method to use f-strings with improved formatting; corrected volume units from cm² to cm³
mcnp_output_reader.py Updated __str__ methods in multiple tally classes to use f-strings
mcnp_input_reader.py Converted __str__ methods to f-strings across multiple classes; removed debug print statement
mcnp_analysis.py Extensively refactored HTML and CSV output generation to use f-strings; improved code structure with intermediate variables
fispact_fluxes_writer.py Refactored multi-line error message to use f-strings with improved line breaking

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

mcnp_analysis.py Outdated
Comment on lines 315 to 328
if tdat.tally_type == "4":
hlines.append(f"Number Cells: {len(tdat.cells)}")
cell_string = "".join(tdat.cells)
hlines.append(f"Cells: {cell_string}")
hlines.append(f"Volumes: {''.join(tdat.vols)}")
# add result plots
if tdat.eng and len(tdat.cells) == 1:
pname = "tally_" + str(tdat.number) + \
"_" + str(tdat.cells[0]) + ".png"
title = tdat.particle + \
" Spectra for cell " + str(tdat.cells[0])
plot_spectra(tdat, pname, title, sp="neutron")

hlines.append(
"<img src=" +
pname +
" alt=\"simulated spectrum\">")
if tdat.eng and len(tdat.cells) == 1:
pname = f"tally_{tdat.number}_{tdat.cells[0]}.png"
title = f"{tdat.particle} Spectra for cell {tdat.cells[0]}"
plot_spectra(tdat, pname, title, sp="neutron")

hlines.append(f"<img src={pname} alt=\"simulated spectrum\">")
else:
print("no energy bins or more than one cell")
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The indentation of this conditional block has been changed. The code for handling tally_type "4" is now nested inside the else block (when statistical test data is not found), which appears to be incorrect. This logic should execute regardless of whether statistical tests are present, so it should be at the same indentation level as the if/else block above it, not nested within the else clause.

Copilot uses AI. Check for mistakes.
r2s_cell.py Outdated
# TODO: need to get the groups number for the collapse
write_collapse(path+"/collapse.i")
write_array(path+"/array.i")
write_collapse(f"{path}/collapse.i")
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

Call to function write_collapse with too few arguments; should be no fewer than 2.

Suggested change
write_collapse(f"{path}/collapse.i")
write_collapse(f"{path}/collapse.i", None)

Copilot uses AI. Check for mistakes.
@py1sl py1sl merged commit 8bdc1d0 into master Jan 8, 2026
1 check passed
@py1sl py1sl deleted the best_practice_fstrings branch January 8, 2026 19:04
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.

2 participants