Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AliasProperty and tests #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leonwilly
Copy link

Added an AliasProperty similar to Kivy but without the kv language specific attributes. This required refactoring the __new__ method of the Dispatcher class. The bind argument to AliasProperty requires properties to _add_instance in declaration order. The builtin dir() method doesn't list attributes in declaration order. Now the __dict__ property of the class is used for detecting properties. I also changed the iteration of base classes to use the __mro__ since that is the correct inheritance order already unraveled.

@coveralls
Copy link

Coverage Status

Coverage decreased (-3.6%) to 94.298% when pulling ca0a48d on gabewillen:master into 030941b on nocarryr:master.

@coveralls
Copy link

coveralls commented Dec 12, 2020

Coverage Status

Coverage decreased (-2.3%) to 95.63% when pulling ca0a48d on gabewillen:master into 030941b on nocarryr:master.

@nocarryr
Copy link
Owner

I like the concept, and the updated introspection in __new__. Definitely worth having.

Do you mind removing the unrelated changes from this PR though? Your code editor included quite a bit of PEP8 corrections and while I don't disagree with a little linting, I'd rather it be separate from this change (makes it less clear what you've actually altered).

@leonwilly
Copy link
Author

I like the concept, and the updated introspection in __new__. Definitely worth having.

Do you mind removing the unrelated changes from this PR though? Your code editor included quite a bit of PEP8 corrections and while I don't disagree with a little linting, I'd rather it be separate from this change (makes it less clear what you've actually altered).

About the linting I apologize I even read your contributing guide and was trying to keep things styled the same. PyCharm automatically refactors the code and I forgot to disable that. I'll remove the linting applied by PyCharm and update the pull request.

class AliasProperty(Property):
"""Property with a getter method and optional setter method. Behaves similar to Pythons builtin properties.

Args:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a description for bind here?

Copy link
Author

@leonwilly leonwilly Dec 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

self.__setter = setter
self.__bindings = dict((prop, self._on_change) for prop in bind) if bind is not None else {}

def _on_change(self, obj, *args, **kwargs):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it would be better to use a separate callback for bound properties instead of overriding _on_change.

Seems like there could be a lot of added method calls with all of the extra bindings. It would also be cleaner without having to inspect the source Property, calls to super(), etc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree I originally added an _trigger_change callback. But I didn't want to add to much bloat. I wanted to keep additions limited.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an additional method specific to AliasProperty would be just fine. Doesn't really add bloat and would make intent much clearer.

Maybe something like _on_bound_prop_change? I'm not the best at naming things, but you get the idea.

class A(Dispatcher):
test_prop = Property('default')
name = Property('')
something = Property()

def get_name_something(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test for the setter?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test for the setter?

I must of forgot to commit this. I already have the setter added here locally I'll fix the other issues and re-commit.

@nocarryr
Copy link
Owner

About the linting I apologize I even read your contributing guide and was trying to keep things styled the same. PyCharm automatically refactors the code and I forgot to disable that. I'll remove the linting applied by PyCharm and update the pull request.

No worries. I also noticed you're working off of the master branch of your fork. This will cause headaches for you later on if you try to keep things in sync with this repo (I made the same mistake for my first PR).

Not sure if you want to deal with that now (would be easier for you, but it'd be a separate PR) or later (would require some git rebase and force push magic).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants