Skip to content

feat: __dict__ major simplification #477

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

Merged
merged 7 commits into from
Dec 21, 2020
Merged

feat: __dict__ major simplification #477

merged 7 commits into from
Dec 21, 2020

Conversation

henryiii
Copy link
Member

@henryiii henryiii commented Nov 26, 2020

This removes the whole facade and just really makes this a __dict__ class. You can now manipulate dict directly, it's completely natural, and C++ just caries a pointer to it. If you need to clear the dict, set it, etc., you can.

@github-actions github-actions bot added the needs changelog Might need a changelog entry label Nov 26, 2020
@henryiii
Copy link
Member Author

@HDembinski I need to implement this on all axes types, but before I do, does this look reasonable? It makes the "this is a normal __dict__ class" facade more believable and makes it much easier to do things like remove all metadata by clearing __dict__.

@HDembinski
Copy link
Member

Looks ok to me.

@henryiii henryiii marked this pull request as draft November 30, 2020 22:46
@henryiii henryiii added this to the 1.0.0 milestone Dec 7, 2020
@github-actions github-actions bot removed the needs changelog Might need a changelog entry label Dec 18, 2020
@henryiii henryiii changed the title feat: __dict__ (WIP) feat: __dict__ major simplification Dec 19, 2020
@henryiii
Copy link
Member Author

henryiii commented Dec 19, 2020

Major simplification in last commit (please look at it by itself, you can't get a full sense for how much this simplified without a direct comparison with matching features!) I came across a mention in the Python docs that you can have a mixed __slots__ and __dict__ class simply by adding "__dict__" to your __slots__! So very simple, and works perfectly for us. The __slots__ part is not in the __dict__, so no issues with recursiveness!

This fixed a bug with __slots__ missing on Category axes, causing them to misbehave when assigning metadata - but now it's all moot anyway because you can forget __slots__ and it still works!

@henryiii henryiii marked this pull request as ready for review December 19, 2020 05:43

def __getattr__(self, item):
if item == "_ax":
return Axis.__dict__[item].__get__(self)
Copy link
Member Author

Choose a reason for hiding this comment

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

This sort of thing is no longer needed! :)

@@ -553,7 +592,9 @@ def _repr_args(self):
@set_module("boost_histogram.axis")
@register({ca.category_int, ca.category_int_growth})
class IntCategory(BaseCategory):
@inject_signature("self, categories, *, metadata=None, growth=False")
__slots__ = ()
Copy link
Member Author

@henryiii henryiii Dec 19, 2020

Choose a reason for hiding this comment

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

This was a bug (missing __slots__). But it wouldn’t be anymore!

@henryiii
Copy link
Member Author

@HDembinski You've already agreed to the basic idea, so I'll merge at some point if I need to to work on the next PR without diverging too much - but feel free to let me know if I need to change / pull / add anything even after merging if needed!

@henryiii
Copy link
Member Author

I'm going to try to work on #476 today, and axis changes (if there are any) might interact with this. So merging!

@henryiii henryiii merged commit ca298e7 into develop Dec 21, 2020
@henryiii henryiii deleted the feat/__dict__ branch December 21, 2020 17:15
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.

2 participants