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

Python bindings: accessing deprecated code should emit DeprecationWarning #5967

Open
AllSeeingEyeTolledEweSew opened this issue Feb 10, 2021 · 5 comments
Milestone

Comments

@AllSeeingEyeTolledEweSew
Copy link
Contributor

Warnings in python are soft errors, which can be configured at runtime to either be ignored, raise an exception, or print a message to stderr.

There are a few built-in classes of warnings. DeprecationWarning is ignored by default, but are printed when encountered by unit test runners, which makes it a good choice for complaining to developers about using deprecated functions, while not annoying users.

I think all deprecated code in the python bindings should emit DeprecationWarning. Adding warnings isn't expected to break any usage, so it should be reasonable to emit new warnings in all branches, even in a point release.

Ideally, even getting a deprecated attribute would emit the warning. That is, it should be emitted by both of these:

my_func = libtorrent.get_http_category
my_value = libtorrent.get_http_category()

The functions to emit warnings from python C API are PyErr_WarnEx() and friends.

@latot
Copy link

latot commented Feb 14, 2021

Yes please!, this would be great :)

@arvidn arvidn added this to the 1.2.14 milestone Apr 8, 2021
@arvidn
Copy link
Owner

arvidn commented Apr 9, 2021

I think this ought to cover some of it at least. I haven't come up with a good way of reporting this for properties yet.
would anyone mind giving it a try?

#6123

@AllSeeingEyeTolledEweSew
Copy link
Contributor Author

I found #6123 broke some things:

fprint = lt.fingerprint("AB", 1, 2, 3, 4)
self.assertEqual(fprint.major_version, 1)
"""
TypeError: No Python class registered for C++ class deprecate_visitor<int libtorrent::fingerprint::*>
"""

@AllSeeingEyeTolledEweSew
Copy link
Contributor Author

There's also a quirk: with deprecated functions enabled, parse_magnet_uri(...) always returns an empty "url" item, session.add_torrent(parse_magnet_uri(...)) will always raise DeprecationWarning due to this. I think this is fine in view of #5992, but maybe it wasn't what you intended

@AllSeeingEyeTolledEweSew
Copy link
Contributor Author

With #6335, I think the only outstanding work is to raise DeprecationWarning stuff that gets bound with .attr(...), class_(...), enum_(...) or enum_(...).value(...).

My C++ isn't strong enough to figure out a nice way to get these things to raise DeprecationWarning though, I'll need some help.

@arvidn arvidn modified the milestones: 1.2.15, 1.2.16 Dec 27, 2021
@arvidn arvidn modified the milestones: 1.2.16, 1.2.17 Apr 17, 2022
@arvidn arvidn modified the milestones: 1.2.17, 1.2.19 Apr 10, 2023
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

No branches or pull requests

3 participants