Skip to content

Implement basic functionality for cat command with line numbering - #19

Open
matthewjustice wants to merge 1 commit into
mainfrom
reviewer-test/cat-implementation
Open

matthewjustice wants to merge 1 commit into
mainfrom
reviewer-test/cat-implementation

Conversation

@matthewjustice

@matthewjustice matthewjustice commented Oct 26, 2026 •

Copy link
Copy Markdown

This PR is for testing the cyf-ai-code-reviewer

@matthewjustice matthewjustice added NotCoursework Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 26, 2026
Comment on lines +16 to +24
for filename in args.files:
line_number = 1
try:
with Path(filename).open(encoding="utf-8", newline="") as source:
for line in source:
number_line = args.n or (args.b and bool(line.strip()))
if number_line:
sys.stdout.write(f"{line_number:6}\t")
line_number += 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In your current implementation, line_number is defined and initialized inside the for filename in args.files: loop. That means line_number is reset to 1 for each file, so numbering starts over for every new file in a multi-file invocation.

On both common cat implementations (GNU on Linux and BSD on macOS), when you use -n or -b with multiple files, the line numbers continue increasing across files rather than restarting at 1 for each file. Since your README says this tool should act the same as cat when run from this directory, resetting line_number per file will give different output from the real cat in multi-file cases.

Would you consider where line_number needs to live so that it can persist across the whole run instead of being recreated for each file? Moving it to a scope that spans all files would let numbering continue correctly across files while still letting you increment it inside the inner loop.

To "like" or "dislike" this comment, please follow this link

@@ -0,0 +1,34 @@
"""Concatenate files, optionally numbering their lines."""

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The module docstring on line 1 explains what the script does at a high level. In many small scripts, the combination of the filename (cat.py), the function/argument names, and the argument help texts already make the intent very clear. In those cases, an extra docstring can end up repeating information without adding much new context.

It might be worth asking yourself: Does this comment tell a future reader anything they couldn’t already infer from the code and CLI help? If the answer is no, you could either drop the docstring or expand it to include non-obvious behavior (for example, how -n and -b interact, or how errors are handled). That way, any comment you keep is clearly pulling its weight.

To "like" or "dislike" this comment, please follow this link

@cyf-ai-code-reviewer cyf-ai-code-reviewer Bot added Reviewed and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 26, 2026
@cyf-ai-code-reviewer

Copy link
Copy Markdown

The CYF AI review has left comments. It will only review a PR one time. When you have addressed these comments, please request review again and a volunteer will take a look.

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.

1 participant