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

ValueError: Cell is empty with very specific code #589

Closed
smarie opened this issue Oct 21, 2019 · 0 comments
Closed

ValueError: Cell is empty with very specific code #589

smarie opened this issue Oct 21, 2019 · 0 comments
Labels

Comments

@smarie
Copy link
Contributor

smarie commented Oct 21, 2019

Consider this horrible and useless code:

@attr.s(slots=True)
class C(object):
    field = attr.ib()

    def f(self, a):
        super(C, self).__init__()

You get a nice error:

        # The following is a fix for
        # https://github.com/python-attrs/attrs/issues/102.  On Python 3,
        # if a method mentions `__class__` or uses the no-arg super(), the
        # compiler will bake a reference to the class in the method itself
        # as `method.__closure__`.  Since we replace the class with a
        # clone, we rewrite these references so it keeps working.
        for item in cls.__dict__.values():
            if isinstance(item, (classmethod, staticmethod)):
                # Class- and staticmethods hide their functions inside.
                # These might need to be rewritten as well.
                closure_cells = getattr(item.__func__, "__closure__", None)
            else:
                closure_cells = getattr(item, "__closure__", None)
    
            if not closure_cells:  # Catch None or the empty list.
                continue
            for cell in closure_cells:
>               if cell.cell_contents is self._cls:
E               ValueError: Cell is empty

..\src\attr\_make.py:639: ValueError

I'll push a PR right away

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

No branches or pull requests

2 participants