ronaldoussoren / pyobjc

The Python <-> Objective-C Bridge with bindings for macOS frameworks
https://pyobjc.readthedocs.io
553 stars 47 forks source link

`object_property` uses modified names for boolean getters #586

Closed Sbte closed 8 months ago

Sbte commented 9 months ago

Describe the bug

The getter of a _C_BOOL object_property is prefixed with is here but the setter is not. This means that when defining the condition object_property in my objective-c header as

@property BOOL isCondition;

the setIsCondition: selector will not be found when trying to set the property value.

This can be fixed by using

@property (setter=setCondition:) BOOL isCondition;

but in this case KVO is broken because KVO gets generated for condition, not isCondition.

What does work (for getting, setting and KVO) is implementing an isCondition object_property and then using

@property (getter=isIsCondition) BOOL isCondition;

But now I have this oddly named isIsCondition getter.

So in short, I'm not sure why the getter is prefixed with is, but it's causing issues with setters and KVO.

Edit: This also seems to break the depends_on parameter.

ronaldoussoren commented 9 months ago

The API is based on this pattern in system headers on macOS:

@property (readonly, getter=isRemote) BOOL remote

That is, the name of the property does not have the "is" prefix, only the getter method does.

Sbte commented 8 months ago

I fixed my issues by not using the @getter decorator, but instead defining the property after the getter and adding the getter to the property by calling the getter method manually. So the issues weren't caused by the modified names as I initially thought.

The actual issue with the @getter decorator seems to be that the property is defined twice if the name of the getter does not match the name of the property, and that that breaks the class definition.

Since this is probably a very niche use case and I'm not even completely sure what the actual issue is, I'm not sure if it's worth it to open a new issue for this.

Anyway, thanks for the fast initial reply.