khal icon indicating copy to clipboard operation
khal copied to clipboard

add alarms-list output formats

Open DhruvaSambrani opened this issue 2 months ago • 4 comments

Adds --format and --json to list alarms. Semi-fixes #148, actual alarm implementation can be done externally.

DhruvaSambrani avatar Oct 17 '25 20:10 DhruvaSambrani

I am unable to see the failure of pre-commit.ci, I only see Internal Service error sent as json (??). Is this temporary or am I missing smthing?

DhruvaSambrani avatar Oct 20 '25 09:10 DhruvaSambrani

Interesting; it works with uBlock Origin for me; maybe something is interfering with full networking? Anyways, here is the output:

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check toml...............................................................Passed
check for added large files..............................................Passed
debug statements (python)................................................Passed
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

khal/khalendar/event.py:725: error: Incompatible types in assignment (expression has type "list[dict[str, object]]", target has type "str")  [assignment]
khal/controllers.py:329: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
Found 1 error in 1 file (checked 57 source files)

ruff (legacy alias)......................................................Failed
- hook id: ruff
- exit code: 1

E501 Line too long (101 > 100)
   --> khal/utils.py:202:101
    |
200 |             if 'alarms-list' in row and isinstance(row['alarms-list'], list):
201 |                 row['alarms-list'] = ", ".join(
202 |                     alarm['description']+"@"+alarm['delta-formatted'] for alarm in row['alarms-list']
    |                                                                                                     ^
203 |                 )
    |

E501 Line too long (166 > 100)
   --> tests/cli_test.py:498:101
    |
496 | …
497 | …
498 | …"", "delta-formatted": "-15m"}, {"delta": -3600.0, "description": "", "delta-formatted": "-1h"}]}]'
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
499 | …
500 | …
    |

Found 2 errors.

mathstuf avatar Oct 20 '25 11:10 mathstuf

@DhruvaSambrani sounds like a temporary glitch. You can also run these checks with pre-commit run locally.

WhyNotHugo avatar Oct 20 '25 11:10 WhyNotHugo

I can fix it either by typing the attributes dict explicitly, or serialize json to keep the same type.

If I change the type to dict[str, Union[str, list[dict[str, object]]]], it adds an error on line 694

khal/khalendar/event.py:694: error: No overload variant of "__add__" of "list" matches argument type "str"  [operator]
khal/khalendar/event.py:694: note: Possible overload variants:
khal/khalendar/event.py:694: note:     def __add__(self, list[dict[str, object]], /) -> list[dict[str, object]]
khal/khalendar/event.py:694: note:     def [_S] __add__(self, list[_S], /) -> list[_S | dict[str, object]]
khal/khalendar/event.py:694: note: Left operand is of type "str | list[dict[str, object]]"
khal/khalendar/event.py:694: error: Unsupported operand types for + ("str" and "list[dict[str, object]]")  [operator]
khal/khalendar/event.py:694: note: Both left and right operands are unions

This can also be fixed by typing it as dict[str, Any], but maybe that is too generically typed?

The other way is to use a TypedDict, but that seems too complicated for a pre-ci fix.

DhruvaSambrani avatar Oct 20 '25 11:10 DhruvaSambrani