hardwareprofile: drop ancient python2 compatibility libraries: "future" and "simplejson" #838
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Two commits:
This uses the requests module and converts requests responses to json using requests' own
.json()
method on responses. For incomprehensible reasons, requests has spent about a decade using either simplejson or the standard library's json module more or less at will, and returning either one or the other exception types. They don't know why they use simplejson, we don't know why they use simplejson. In requests 3 (which will be released in the Year Of The Linux Desktop or when pigs fly, whichever one comes later) simplejson is dropped entirely.There are innumerable issues discussing the problem on the requests bugtracker, with the general consensus being that it's better to randomly return either one of two different libraries and two different library return types in errors -- because it was historically done that way and people might be depending on it. ??????
Bugs:
psf/requests#710
psf/requests#2516
psf/requests#3052
psf/requests#4169
psf/requests#4842
psf/requests#5794
psf/requests#6084
The awkward workaround is to guarantee that requests' silent behavior of using simplejson if it is installed is forcibly triggered by forcibly depending on simplejson, and then catching the simplejson exception.
The better solution here is pretty simple: do not rely on the requests module's automatic json conversion, this is as simple as using the already-imported json module and calling json.loads() on the retrieved content.
Fixes: 1df343e
Reimplements: bb154a8
Ironically, for a package that was intended to provide portability between python2 and python3, it is broken with python 3.12. A better library to use in all cases is "six".
However, mythtv requires python 3.8 for a while now. Using "future.standard_library" is a no-op other than costing a pointless import and being troublesome to actually install.
The hacky copy of six.with_metaclass included in "future" is rewritten to use the pure python3 form of a metaclass.
Part of #824