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

Implement __slots__ in model.py #235

Open
mrbermell opened this issue May 17, 2022 · 1 comment
Open

Implement __slots__ in model.py #235

mrbermell opened this issue May 17, 2022 · 1 comment
Labels
good first issue Good for newcomers

Comments

@mrbermell
Copy link
Collaborator

mrbermell commented May 17, 2022

The special attribute slots allows you to explicitly state which instance attributes you expect your object instances to have, with the expected results:

  • faster attribute access.
  • space savings in memory.

Full stack overflow post here

By doing below (on every class that's often used), we can get a significant performance increase!

@immutable_after_init
class Square:
    __slots__ = 'x', 'y', '_out_of_bounds'   # only new thing
    x: int
    y: int
    _out_of_bounds: Optional[bool]

    def __init__(self, x: int, y: int, _out_of_bounds=None):
        self.x = x
        self.y = y
        self._out_of_bounds = _out_of_bounds
    ...

This is a good first issue for anyone who want to contribute, just make the update and make sure all tests pass! ☺️

@mrbermell mrbermell added the good first issue Good for newcomers label May 17, 2022
@IanWorley
Copy link

IanWorley commented May 17, 2022

I would like to work on this issue.

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

No branches or pull requests

2 participants