-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Readability and branching Improvements #264
Readability and branching Improvements #264
Conversation
Hi @kokroo, this looks great! Adding to the changelog would be helpful, like this:
|
@danielfromearth Hey Daniel, I added a line in the changelog under "changes". The tests are still passing even after merging the latest changes. Cheers and happy holidays! |
The Path() constructor already handles both str and Path types effectively.
Added a check to ensure the provided suffix starts with a dot (.), which is standard for file extensions. This prevents the creation of invalid file paths with malformed suffixes (e.g., .txt vs txt). Path(should_be_path).with_suffix(suffix) is directly applied, reducing the number of steps.
Combined checks for str, int, and tuple into a single isinstance call using a tuple of types. This reduces redundancy, improves clarity and performance . The TypeError is preserved to handle unsupported types. Added the correct return type (str).
This function is no longer needed.
The intersection() method can deal with arbitrary objects but it is not needed here since we coerce everything into a string. The & operator works at a lower level and is faster and sufficient for strings
Improvements: Avoid unnecessary double conversions to sets: Previously, set(a_sorted) and set(b_sorted) were resorted. The optimized code directly converts sequence_a and sequence_b into sets for fast lookups, creates a union using the low level "|" operator and then creates a sorted set. Sorting is performed only once on the union of the sets (a_set | b_set), rather than sorting a_sorted, b_sorted, and their combined union separately. Simplified membership checking: The if conditions now directly check the presence of an item in the sets instead of redundant checks. Removed unreachable error check: The raise ValueError condition is unnecessary since all items in all_items are guaranteed to come from either a_set or b_set. The input-output behavior remains consistent while achieving faster execution.
c4e6177
to
1abedb8
Compare
947bf47
into
nasa:feature/kokroo-code-improvements
Description
There are several commits in this PR that improve code readability and reduce branching done by the CPU.
I would suggest going through each commit individually and then looking at the entire file as a whole.
Local test steps
I have run the test suite using "pytest tests" and they all pass. I have not altered the functionality of any code.
PR Acceptance Checklist
CHANGELOG.md
updated@danielfromearth I read the contributor guidelines thoroughly and I am not sure if I actually need to add new tests or modify the changelog. I am using the standard test suite since I am not changing the input/output of the code. If anything should be added to the changelog, I'd be happy to do it :)
📚 Documentation preview 📚: https://ncompare--264.org.readthedocs.build/en/264/