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

slots #21

Open
byteface opened this issue Aug 14, 2021 · 4 comments
Open

slots #21

byteface opened this issue Aug 14, 2021 · 4 comments
Labels
help wanted Extra attention is needed
Projects

Comments

@byteface
Copy link
Owner

I read something about these improving performance but also heard they make your thing immutable. i then figured i could extend a slotted object? and the extended one wouldn't?. i put the placeholders in for slots on the html tag and commented them out for later testing and consideration but stil haven't read and understood enough about them tbh. So this will have to be something I come back to or take advice on.

@byteface byteface created this issue from a note in dom (To do) Aug 14, 2021
@byteface byteface added the help wanted Extra attention is needed label Aug 14, 2021
@Jordan-Cottle
Copy link
Contributor

Jordan-Cottle commented Aug 21, 2021

If you are referring to __slots__, then you can probably safely start using it without worrying about making an object immutable.

It's useful for explicitly declaring instance attributes to avoid creating a __dict__ attribute that allows for dynamically assigning new attributes to objects. Since no __dict__ needs to be created, you save memory, and since no __dict__ lookups happen, attribute access also tends to be faster. All at the expense of just telling a class what attributes its instances will/should have up-front rather than waiting until the __init__ method is called to assign the attributes.

For more info you can read the data model docs at https://docs.python.org/3/reference/datamodel.html#object.__slots__

From a brief look at your tag class it looks like just __slots__ = ["args", "kwargs", "__content", "__attributes"] should work for you.

I opened a small PR that adds __slots__ to the tag class where the comment was.

@byteface
Copy link
Owner Author

This ticket was closed with a great example. But I'm leaving open so we can identify and apply slots to other classes.

Please do create a ticket for a given class if you want to make a __slots__ PR. So I can leave this one open until I feel we have enough of them covered.

@byteface
Copy link
Owner Author

a good pointer for slot useage exmples is the existing minidom.

@byteface
Copy link
Owner Author

byteface commented Dec 4, 2021

thought i'd give an update on the status of slots. seems after version 8 we destroy the tag class in favour of just using Node but this the increased the methods on Node. since then pypy3 has an inssue i think with deepcopy in a slot or something and when i push if fails for pypy only.. so slots are commented off for now on Node until that gets resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
dom
To do
Development

No branches or pull requests

2 participants