Skip to content

Commit bcd8166

Browse files
Frechdachsjaseg
authored andcommitted
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.
1 parent ee8316a commit bcd8166

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mpv.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,8 @@ def _get_list(self, prefix, props):
620620

621621
def bindproperty(MPV, name, proptype, access):
622622
def getter(self):
623-
return proptype(_ensure_encoding(_mpv_get_property_string(self.handle, name.encode())))
623+
value = _ensure_encoding(_mpv_get_property_string(self.handle, name.encode()))
624+
return proptype(value) if value is not None else value
624625
def setter(self, value):
625626
_mpv_set_property_string(self.handle, name.encode(), str(proptype(value)).encode())
626627
def barf(*args):

0 commit comments

Comments
 (0)