Skip to content
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

Fix some deprecation warnings on core24 #2067

Merged
merged 4 commits into from
Aug 30, 2024

Conversation

ogayot
Copy link
Member

@ogayot ogayot commented Aug 27, 2024

On oracular, this PR makes make unit produce 59 warnings instead of 146. The remaining warnings (emitted multiple times) are:

  • DeprecationWarning: 'crypt' is deprecated and slated for removal in Python 3.13
  • /usr/lib/python3/dist-packages/bson/init.py:116: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    -> should be addressed with https://launchpad.net/ubuntu/+source/pymongo/4.7.3-1 (won't be addressed for core24 probably though)
  • /usr/lib/python3/dist-packages/cloudinit/config/schema.py:554: DeprecationWarning: Passing a schema to Validator.iter_errors is deprecated and will be removed in a future release. Call validator.evolve(schema=new_schema).iter_errors(...) instead.
    -> to be investigated
  • /usr/lib/python3/dist-packages/urwid/widget/wimp.py:693: DeprecationWarning: Don't use user_arg argument, use user_args instead.
  • /usr/lib/python3/dist-packages/urwid/widget/wimp.py:264: DeprecationWarning: Don't use user_arg argument, use user_args instead.
    -> internal to urwid, when using on_press or on_state_change. Won't be fixed anytime soon.

urwid deprecated the user of the user_arg parameter of connect_signal
(and might get dropped sometime).  Instead, the suggested approach is to
use user_args (plural!) as a kw-only argument.

We have to change the signature of callbacks functions because
`user_args` is passed as an argument at the beginning ; whereas
`user_arg` is passed as an argument at the end.

Signed-off-by: Olivier Gayot <[email protected]>
urwid deprecated AttrWrap in favor of AttrMap. It is pretty easy to
replace one with the other and is backward compatible with urwid from
core22.

Signed-off-by: Olivier Gayot <[email protected]>
urwid from core24 raises deprecation notices when using set_focus on
widgets. In core24, one can use the `container.focus = widget` setter
property or `container.focus_position = index` setter property. However,
in core22, the `container.focus` property is read-only.

`container.focus_position` is available in core22 and core24 and does
not produce deprecation warnings ; so let's use it.

Signed-off-by: Olivier Gayot <[email protected]>
Although ListBox.get_focus() is deprecated, using ListWalker.get_focus()
through ListBox.body.get_focus() is not.

However, the ListBox.focus property exists and makes it easy to access
the underlying focused widget ; so use it instead of dereferencing the
ListWalker object.

Signed-off-by: Olivier Gayot <[email protected]>
Copy link
Collaborator

@mwhudson mwhudson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The argument order change when you switch from user_arg to user_args is unfortunate!

Should we stop using on_press / on_state_change?

@ogayot
Copy link
Member Author

ogayot commented Aug 28, 2024

Should we stop using on_press / on_state_change?

That sounds like a lot of work! We're using on_press everywhere.

Maybe we subclass urwid.Button, and do something like:

class Button(urwid.Button):
    def __init__(self, *args, on_press=None, user_args=(), **kwargs) -> None:
        if "user_data" in kwargs:
             raise ValueError("For this implementation, use user_args instead")
        super().__init__(*args, **kwargs)
        if on_press is not None:
            connect_signal(self, "click", on_press, user_args=list(user_args))

and then adjust the argument order.

Something for another day, I guess :)

@mwhudson
Copy link
Collaborator

Something for another day, I guess :)

Oh definitely, nothing for this branch!!

@mwhudson
Copy link
Collaborator

Maybe we subclass urwid.Button, and do something like:

Looking at most of our actual uses, having a wrapper that discarded the 'sender' argument to the callback would be useful ....

@ogayot ogayot merged commit 7090443 into canonical:main Aug 30, 2024
12 checks passed
@ogayot ogayot deleted the urwid-core24-deprecations branch August 30, 2024 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants