GNOME Bugzilla – Bug 781582
Throw an error if require_version is not passed a string
Last modified: 2017-04-26 10:01:31 UTC
I spend some time earlier wondering why gi.require_version("Gtk", 3.0) didn't work. Adding in a simple test that the version is a string and throwing a ValueError otherwise could save some hassle for people in the future.
Created attachment 350195 [details] [review] Make sure version information passed to require_version is a string. This simply makes it easier for someone to find an error in cases where a floating point is passed by accident. The test simply checks for the type to be str which should be good in both python2 and python3 but is not quite ideal in python2 as it misses unicode strings.
Review of attachment 350195 [details] [review]: A test checking for the ValueError would be nice (in test_import_machinery.py for example) ::: gi/__init__.py @@ +109,3 @@ repository = Repository.get_default() + if not isinstance(version, str): Under Python 2 we should check for basestring as currently both str and unicode work there (unicode can also occur unintentionally if someone uses "from __future__ import unicode_literals" etc.)
Created attachment 350316 [details] [review] Make sure version information passed to require_version is a string. This simply makes it easier for someone to find an error in cases where a floating point is passed by accident.
Review of attachment 350316 [details] [review]: ::: tests/test_import_machinery.py @@ +152,3 @@ + + # Test that unicode strings work in python 2 + if sys.version_info[0] < 2: <=
Created attachment 350317 [details] [review] Ooops. Changed both places to "<= 2" to make it more consistent. Make sure version information passed to require_version is a string. This simply makes it easier for someone to find an error in cases where a floating point is passed by accident.
Review of attachment 350317 [details] [review]: lgtm
The following fix has been pushed: 9cbf370 Make sure version information passed to require_version is a string.
Created attachment 350444 [details] [review] Make sure version information passed to require_version is a string. This simply makes it easier for someone to find an error in cases where a floating point is passed by accident.