Allow printing limit to be None, remove deprecated print_pattern#460
Conversation
This commit: - updates `Pattern` methods (`to_ascii`, `to_unicode`, `to_latex`) and `pattern_to_str` to allow `limit` to be `None`. - removes the deprecated `print_pattern` function.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #460 +/- ##
==========================================
+ Coverage 88.85% 88.89% +0.04%
==========================================
Files 44 44
Lines 6533 6530 -3
==========================================
Hits 5805 5805
+ Misses 728 725 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| truncated = len(command_list) > limit | ||
| short_command_list = command_list[: limit - 1] if truncated else command_list | ||
| truncated = limit is not None and len(command_list) > limit | ||
| short_command_list = command_list[: limit - 1] if limit is not None and truncated else command_list |
There was a problem hiding this comment.
| short_command_list = command_list[: limit - 1] if limit is not None and truncated else command_list | |
| short_command_list = command_list[: limit - 1] if truncated else command_list |
Here truncated is enough,
right?
There was a problem hiding this comment.
You're right: logically the test is redundant because truncated already implies limit is not None. However, mypy does not track implications across boolean variables, so it won't narrow the type of limit without the explicit check. I added the following comment in commit 9249f0e:
# Note: The redundant test `limit is not None` is required for mypy
# to narrow the type of `limit` in the then-branch.There was a problem hiding this comment.
I see thanks, for the clarification and adding the comment
| if output == OutputFormat.LaTeX: | ||
| result = f"\\({result}\\)" | ||
| if truncated: | ||
| if limit is not None and truncated: |
There was a problem hiding this comment.
| if limit is not None and truncated: | |
| if truncated: |
| and an ellipsis is added at the end to indicate that some commands have been elided. | ||
| If ``limit=None``, there is no limit on the number of printed commands. | ||
| target: Container[command.CommandKind], optional | ||
| If set, only commands of kinds specified in ``target`` are printed. |
There was a problem hiding this comment.
To make it searchable when the docs are updated, I think it would be good to explicitly mention here something like For example, you can print only measurements with ``command.M`` or X corrections with ``command.X`` .
There was a problem hiding this comment.
I added runnable (and pytest-checked) examples.
This commit:
Patternmethods (to_ascii,to_unicode,to_latex) andpattern_to_strto allowlimitto beNone.print_patternfunction.