-
Notifications
You must be signed in to change notification settings - Fork 21
Type information and datetime improvements #63
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
Conversation
|
|
||
| def int_formatter(val, chars, delta, left): | ||
| return '{:{}{}}'.format(int(val), '<' if left else '>', chars) | ||
| return "{:{}{}}".format(int(val), "<" if left else ">", chars) |
Check warning
Code scanning / CodeQL
Unused argument in a formatting call Warning
"{:{}{}"
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
In general, to fix “unused argument in a formatting call” you either remove the surplus argument or adjust the format string so that every argument is actually referenced by a placeholder. Here the function int_formatter(val, chars, delta, left) is clearly intended to format val as an integer with left or right alignment and a width of chars. The current format string "{:{}{}}" has only two fields: the first is the value to format, and the second fills the entire format spec; chars is never referenced, making it unused and breaking the intended behavior.
The best fix without changing external behavior is to update the format string on line 54 so that it uses both the alignment character and the width. This is done by including a second nested replacement field for chars in the format specification: "{:{}{}{}}".format(int(val), "<" if left else ">", chars). Here:
- Outer
{}: formatted value (int(val)). - Inner
{}{}inside the format spec: first{}is the alignment ("<"or">"), second{}is the width (chars).
No imports or other definitions are required; we only update the single return statement in int_formatter in examples/logo_example.py.
-
Copy modified line R54
| @@ -51,7 +51,7 @@ | ||
|
|
||
|
|
||
| def int_formatter(val, chars, delta, left): | ||
| return "{:{}{}}".format(int(val), "<" if left else ">", chars) | ||
| return "{:{}{}{}}".format(int(val), "<" if left else ">", chars) | ||
|
|
||
|
|
||
| def logo(): |
issues with pypy
| def __init__(self): | ||
| self.formatters = OrderedDict() | ||
| class Formatter(Protocol): | ||
| def __call__(self, val: Any, chars: int, delta: Any, left: bool) -> str: ... |
Check notice
Code scanning / CodeQL
Statement has no effect Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
In general, to fix a “statement has no effect” issue where an ellipsis (...) is used as a standalone expression, replace it with an appropriate construct that clearly expresses the intent: usually pass for “do nothing”, or raising NotImplementedError if the method must not be called directly.
Here, Formatter is a Protocol specifying the call signature; its __call__ body is never meant to run and is only present to satisfy the type checker. The minimal, behavior-preserving fix is to replace the ellipsis expression with pass inside the method body. This keeps the method abstract in practice (since Protocol methods aren’t normally invoked on the protocol itself), but removes the no-op expression and the warning. No new imports, methods, or other definitions are required.
Concretely: in plotille/_input_formatter.py, at the definition of class Formatter(Protocol):, change the body of __call__ from ... to pass on line 42 (keeping the signature unchanged).
-
Copy modified lines R42-R43
| @@ -39,7 +39,8 @@ | ||
|
|
||
|
|
||
| class Formatter(Protocol): | ||
| def __call__(self, val: Any, chars: int, delta: Any, left: bool) -> str: ... | ||
| def __call__(self, val: Any, chars: int, delta: Any, left: bool) -> str: | ||
| pass | ||
|
|
||
|
|
||
| Converter = Callable[[Any], int | float | datetime] |
| def _num_formatter( | ||
| val: int | float, chars: int, delta: int | float, left: bool = False | ||
| ) -> str: |
Check notice
Code scanning / CodeQL
Explicit returns mixed with implicit (fall through) returns Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
In general, to fix mixed implicit/explicit returns you add an explicit return (or raise) on all paths so the function never silently falls through. For _num_formatter, the function’s contract is to return a str for valid numeric inputs or raise an error otherwise. The cleanest fix that preserves behavior is to replace the “unreachable” fall-through with an explicit TypeError for any value that passes the first isinstance but is neither int nor float according to the later checks. This keeps the semantics consistent: unsupported values trigger an exception instead of returning None.
Concretely, in plotille/_input_formatter.py around lines 162–167, we keep the existing return statements for int and float, but replace the # unreachable comment and the implicit fall-through with a raise TypeError(...) that clearly indicates an unsupported numeric type. No new imports are needed; TypeError is built in. All other lines in the snippet remain unchanged.
-
Copy modified lines R166-R169
| @@ -163,7 +163,10 @@ | ||
| return _int_formatter(val, chars, left) | ||
| elif isinstance(val, float): | ||
| return _float_formatter(val, chars, left) | ||
| # unreachable | ||
| raise TypeError( | ||
| "Only accepting numeric (int/long/float) " | ||
| f'types, not "{val}" of type: {type(val)}' | ||
| ) | ||
|
|
||
|
|
||
| def _float_formatter(val: float, chars: int, left: bool = False) -> str: |
only store float and metadata internally
No description provided.