summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrechdachs <Frechdachs@users.noreply.github.com>2016-02-12 12:40:19 +0100
committerjaseg <code@jaseg.net>2016-02-12 14:09:21 +0100
commitbcd81668291931c344dd8d605ef74048c96d42a7 (patch)
treefd56519f77306939557ee7e2abef560f693f441d
parentee8316a282d0fed860a98b0edb481739f801c6c6 (diff)
downloadpython-mpv-bcd81668291931c344dd8d605ef74048c96d42a7.tar.gz
python-mpv-bcd81668291931c344dd8d605ef74048c96d42a7.tar.bz2
python-mpv-bcd81668291931c344dd8d605ef74048c96d42a7.zip
Fix property getter for non-available properties
Properties which are not currently available weren't handled properly: The getter for a property that is not available with proptype 'str' would return "None" (as a string) instead of None. Trying to retrieve a non-available property with proptype 'int' would raise a TypeError, because the getter tries to call 'int(None)'. An alternative would be to raise some kind of exception for non-available properties, but I would prefer the getter to return None. For example None should be a valid value for the property 'path' if no video is loaded yet.
-rw-r--r--mpv.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/mpv.py b/mpv.py
index 0fa43a2..3916462 100644
--- a/mpv.py
+++ b/mpv.py
@@ -620,7 +620,8 @@ ALL_PROPERTIES = {
def bindproperty(MPV, name, proptype, access):
def getter(self):
- return proptype(_ensure_encoding(_mpv_get_property_string(self.handle, name.encode())))
+ value = _ensure_encoding(_mpv_get_property_string(self.handle, name.encode()))
+ return proptype(value) if value is not None else value
def setter(self, value):
_mpv_set_property_string(self.handle, name.encode(), str(proptype(value)).encode())
def barf(*args):