refactor: complete_filename to reduce cognitive complexity - #177
Open
bhagathkrishnacdac wants to merge 1 commit into
Open
refactor: complete_filename to reduce cognitive complexity#177bhagathkrishnacdac wants to merge 1 commit into
bhagathkrishnacdac wants to merge 1 commit into
Conversation
Signed-off-by: bhagathkrishnacdac <bhagath.krishna@cdac.in>
There was a problem hiding this comment.
Pull request overview
This PR refactors complete_filename in bessctl/commands.py to reduce cognitive complexity by extracting the visibility rules and filename pattern/suffix handling into helper functions, while keeping the main function focused on path resolution and iteration.
Changes:
- Added
_visible_candidate()to centralize dotfile visibility andis_allowed_filename()filtering. - Added
_process_file_match()to encapsulatefnmatchmatching plus optional suffix stripping. - Simplified
complete_filename()to orchestrate directory scanning and candidate construction.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+174
to
+175
| def complete_filename(partial_word, start_dir='', suffix='', skip_suffix=False): | ||
| """Refactored complete_filename with Cognitive Complexity < 10.""" |
gab-arrobo
requested changes
Aug 3, 2026
gab-arrobo
left a comment
Contributor
There was a problem hiding this comment.
Same here, I get empty trailing whitespaces
pr.patch:20: trailing whitespace.
pr.patch:47: trailing whitespace.
pr.patch:50: trailing whitespace.
pr.patch:59: trailing whitespace.
pr.patch:76: trailing whitespace.
warning: 5 lines add whitespace errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors commands.py to address code quality and cognitive complexity. This specific change modularizes the filename auto-completion logic used by the CLI.
Key Changes