diff options
author | Frechdachs <Frechdachs@users.noreply.github.com> | 2016-02-12 12:40:19 +0100 |
---|---|---|
committer | jaseg <code@jaseg.net> | 2016-02-12 14:09:21 +0100 |
commit | bcd81668291931c344dd8d605ef74048c96d42a7 (patch) | |
tree | fd56519f77306939557ee7e2abef560f693f441d /mpv.py | |
parent | ee8316a282d0fed860a98b0edb481739f801c6c6 (diff) | |
download | python-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.
Diffstat (limited to 'mpv.py')
-rw-r--r-- | mpv.py | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -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): |