Skip to content

PytzUsageWarning: The localize method is no longer necessary, #1196

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

Closed
garyemiller opened this issue Oct 15, 2022 · 11 comments
Closed

PytzUsageWarning: The localize method is no longer necessary, #1196

garyemiller opened this issue Oct 15, 2022 · 11 comments

Comments

@garyemiller
Copy link

Installed the Gentoo khal package. Seems to work fine, but I get these warnings:

kong ~ $ khal calendar
/usr/lib/python3.10/site-packages/khal/controllers.py:256: PytzUsageWarning: The localize method is no longer necessary, as this time zone supports the fold attribute (PEP 495). For more details on migrating to a PEP 495-compliant implementation, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
  original_start = conf['locale']['local_timezone'].localize(start)
/usr/lib/python3.10/site-packages/khal/controllers.py:177: PytzUsageWarning: The localize method is no longer necessary, as this time zone supports the fold attribute (PEP 495). For more details on migrating to a PEP 495-compliant implementation, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
  start_local = locale['local_timezone'].localize(start)
/usr/lib/python3.10/site-packages/khal/controllers.py:178: PytzUsageWarning: The localize method is no longer necessary, as this time zone supports the fold attribute (PEP 495). For more details on migrating to a PEP 495-compliant implementation, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
  end_local = locale['local_timezone'].localize(end)
/usr/lib/python3.10/site-packages/khal/khalendar/event.py:546: PytzUsageWarning: The localize method is no longer necessary, as this time zone supports the fold attribute (PEP 495). For more details on migrating to a PEP 495-compliant implementation, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
  day_start = self._locale['local_timezone'].localize(
/usr/lib/python3.10/site-packages/khal/khalendar/event.py:549: PytzUsageWarning: The localize method is no longer necessary, as this time zone supports the fold attribute (PEP 495). For more details on migrating to a PEP 495-compliant implementation, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
  day_end = self._locale['local_timezone'].localize(
    Mo Tu We Th Fr Sa Su     Tuesday, 2022-10-18
[...]
@mschilli87
Copy link

Can you successfully modify the time of an existing event?

@garyemiller
Copy link
Author

Since I am new to khal, I don't know how to do that. Can you please provide an example?

Since this is a warning about a deprecated method, I would expect it to work, until the method is removed. Until then, annoying.

@mschilli87
Copy link

Sorry for not being precise:

  1. Open the interactive khal interface:
    ikhal
  2. Navigate to a day with an existing event and press return.
  3. Navigate to the event and press return.
  4. Press return again to start editing the event.
  5. Navigate to the From: (or To:) field and modify the time. I'd expect the above warning to pollute the screen at this stage.
  6. Navigate to the Save field and press return.

Do you get back to the event overview or does ikhal crash?

@garyemiller
Copy link
Author

Nice instructions. Thanks!

Navigate to the From: (or To:) field and modify the time. I'd expect the above warning to pollute the screen at this stage.

Yup.

Do you get back to the event overview or does ikhal crash?

Crash.

kong ~ $ ikhal 
/usr/lib/python3.10/site-packages/khal/khalendar/khalendar.py:153: PytzUsageWarning: The localize method is no longer necessary, as this time zone supports the fold attribute (PEP 495). For more details on migrating to a PEP 495-compliant implementation, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
  localized_events = self.get_localized(localize(start), localize(end))
/usr/lib/python3.10/site-packages/khal/khalendar/event.py:546: PytzUsageWarning: The localize method is no longer necessary, as this time zone supports the fold attribute (PEP 495). For more details on migrating to a PEP 495-compliant implementation, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
  day_start = self._locale['local_timezone'].localize(
/usr/lib/python3.10/site-packages/khal/khalendar/event.py:549: PytzUsageWarning: The localize method is no longer necessary, as this time zone supports the fold attribute (PEP 495). For more details on migrating to a PEP 495-compliant implementation, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
  day_end = self._locale['local_timezone'].localize(
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/khal/ui/__init__.py", line 1359, in start_pane
    loop.run()
  File "/usr/lib/python3.10/site-packages/urwid/main_loop.py", line 287, in run
    self._run()
  File "/usr/lib/python3.10/site-packages/urwid/main_loop.py", line 385, in _run
    self.event_loop.run()
  File "/usr/lib/python3.10/site-packages/urwid/main_loop.py", line 790, in run
    self._loop()
  File "/usr/lib/python3.10/site-packages/urwid/main_loop.py", line 827, in _loop
    self._watch_files[fd]()
  File "/usr/lib/python3.10/site-packages/urwid/raw_display.py", line 416, in <lambda>
    wrapper = lambda: self.parse_input(
  File "/usr/lib/python3.10/site-packages/urwid/raw_display.py", line 515, in parse_input
    callback(processed, processed_codes)
  File "/usr/lib/python3.10/site-packages/urwid/main_loop.py", line 412, in _update
    self.process_input(keys)
  File "/usr/lib/python3.10/site-packages/urwid/main_loop.py", line 513, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
  File "/usr/lib/python3.10/site-packages/urwid/wimp.py", line 651, in keypress
    return self._current_widget.keypress(size, key)
  File "/usr/lib/python3.10/site-packages/urwid/container.py", line 1135, in keypress
    return self.body.keypress( (maxcol, remaining), key )
  File "/usr/lib/python3.10/site-packages/urwid/container.py", line 2316, in keypress
    key = w.keypress((mc,) + size[1:], key)
  File "/usr/lib/python3.10/site-packages/khal/ui/editor.py", line 530, in keypress
    return super().keypress(size, key)
  File "/usr/lib/python3.10/site-packages/khal/ui/widgets.py", line 376, in keypress
    key = super().keypress(size, key)
  File "/usr/lib/python3.10/site-packages/urwid/listbox.py", line 968, in keypress
    key = focus_widget.keypress((maxcol,),key)
  File "/usr/lib/python3.10/site-packages/urwid/container.py", line 2316, in keypress
    key = w.keypress((mc,) + size[1:], key)
  File "/usr/lib/python3.10/site-packages/urwid/wimp.py", line 543, in keypress
    self._emit('click')
  File "/usr/lib/python3.10/site-packages/urwid/widget.py", line 461, in _emit
    signals.emit_signal(self, name, self, *args)
  File "/usr/lib/python3.10/site-packages/urwid/signals.py", line 265, in emit
    result |= self._call_callback(callback, user_arg, user_args, args)
  File "/usr/lib/python3.10/site-packages/urwid/signals.py", line 295, in _call_callback
    return bool(callback(*args_to_pass))
  File "/usr/lib/python3.10/site-packages/khal/ui/editor.py", line 510, in save
    self.collection.update(self.event)
  File "/usr/lib/python3.10/site-packages/khal/khalendar/khalendar.py", line 172, in update
    event.etag = self._storages[event.calendar].update(event.href, event, event.etag)
  File "/usr/lib/python3.10/site-packages/khal/khalendar/vdir.py", line 251, in update
    if not isinstance(item.raw, str):
  File "/usr/lib/python3.10/site-packages/khal/khalendar/event.py", line 382, in raw
    timezone = create_timezone(tzinfo, self.start)
  File "/usr/lib/python3.10/site-packages/khal/khalendar/event.py", line 858, in create_timezone
    for one, two in iter(tz._tzinfos.items())
AttributeError: '_PytzShimTimezone' object has no attribute '_tzinfos'

@mschilli87
Copy link

mschilli87 commented Oct 18, 2022

In that case can confirm the behaviour. This is on Gentoo as well tough, so I cannot help ruling out a packaging bug.
But my hunch is that this is simply #1092. In that case, the long term fix would be to update khal which will be possible on Gentoo after https://bugs.gentoo.org/866503. So you might want to follow (or even vote for) that bug over on Gentoo's side. AFAICT tell, downgrading tzlocal by adding >dev-python/tzlocal-2.1 to /etc/portage/package.mask followed by a world update would be an intermediate solution but it seems Gentoo remove all ebuilds for older tzlocal version from the portage tree already. I don't know how comfortable you are with Gentoo, but your best solution probably would be to locally bump the app-misc/khal version via a local overlay. Let me know if you need further help.


edit: I found gentoo/gentoo#27809 linked at https://bugs.gentoo.org/866503 and tested it via my local overlay. It did indeed fix the issue. Before I could report this back to Gentoo, it was already merged. So all you should have run a world update with the latest portage tree (maybe after unmasking =app-misc/khal via /etc/portage/package.accept_keywords) to get emerge to update khal to a version compatible with the tzlocal version installed by Gentoo. Either way, please consider closing this issue since there is nothing left to do for the khal developers to fix this problem.

@garyemiller
Copy link
Author

I just found khal, so I'm not worried it has some failure modes. I'll just wait it out, and hope it gets better, before I find another app I like better for calendaring.

@mschilli87
Copy link

It will get better on the next update and from mz experience you won't find any better tool. If you do, let me know but I ended up comfortable with khal + vdirsyncer after a long search.

@geier
Copy link
Member

geier commented Oct 19, 2022

Hi and thanks for reporting this issues.

Can you tell us which version of khal you are using and share your config file?

@mschilli87
Copy link

@geier: As I wrote above, this was khal v0.10.4 and it appears fixed in 0.10.5.

@geier
Copy link
Member

geier commented Oct 19, 2022

Great, thanks for getting back so quickly. I'll close the issue, feel free to re-open this (or another one) if you have still any issues.

@geier geier closed this as completed Oct 19, 2022
@garyemiller
Copy link
Author

kong ~ $ khal -V
Usage: khal [OPTIONS] COMMAND [ARGS]...
Try 'khal --help' for help.

Error: No such option: -V

kong ~ $ khal --version
khal, version 0.10.5

kong ~ $ khal calendar
    Mo Tu We Th Fr Sa Su     Wednesday, 2022-10-26
[...]

It is indeed fixed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants