Skip to content

Compatibility with PyPy #2

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

Closed
smuuf opened this issue Nov 29, 2023 · 2 comments
Closed

Compatibility with PyPy #2

smuuf opened this issue Nov 29, 2023 · 2 comments

Comments

@smuuf
Copy link

smuuf commented Nov 29, 2023

PyPy doesn't implement sys.getsizeof(...) and fails when it's used. Similarly to pandas-dev/pandas#17228.

Reference:

sys.getsizeof() always raises TypeError
https://doc.pypy.org/en/latest/cpython_differences.html

I'd would like to use this package, but I can't because of this - that's because even if I don't want to use the maxsize_bytes functionality,
CircularDict calls sys.getsizeof(...) in several places.

I think the solution could be to "hide" these calls behind a is maxsize_bytes specified? condition, for example something like this:

    def __setitem__(self, key: Any, value: Any):
        ...
-       item_size = sys.getsizeof(key) + sys.getsizeof(value)

        # If the element could not fit in the empty dictionary, raise an error
        if self.maxsize_bytes is not None:
+           item_size = sys.getsizeof(key) + sys.getsizeof(value)
            if item_size > self.maxsize_bytes:
                raise MemoryError(f"Item size {item_size} is larger than maxsize {self.maxsize_bytes}")

        ...

That way this package could be also used in PyPy - if one sacrifices the maxsize_bytes functionality when using PyPy.

What do you think? :)

@Eric-Canas
Copy link
Owner

Hi!

Sorry for the late response, I didn't notice the issue.

I didn't know about that problem, and the solution you propose sounds actually good.

I'll do it this way.

Thanks!

@Eric-Canas
Copy link
Owner

Solved in version 1.8.

Already updated on PyPi

Thanks for the suggestion!

Please reopen it if you still find any incorrect behaviour.

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

No branches or pull requests

2 participants