Skip to content

Segmentation fault with custom TypeTraverserVisitor #8360

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
mkurnikov opened this issue Feb 3, 2020 · 2 comments · Fixed by #9248
Closed

Segmentation fault with custom TypeTraverserVisitor #8360

mkurnikov opened this issue Feb 3, 2020 · 2 comments · Fixed by #9248
Assignees

Comments

@mkurnikov
Copy link
Contributor

I'm trying to copy methods from one class into the other, need to add some imports to other class' module.
https://github.com/django/django/blob/b9cf764be62e77b4777b3a75ec256f6209a57671/django/db/models/manager.py#L101

I'd like to use custom TypeTraverserVisitor for that

signature_node: FuncDef

def import_symbol_from_source(name: str) -> None:
    if name in source_symbols['__builtins__'].node.names:
        return
    sym = source_symbols[name].copy()
    self.semanal_api.add_imported_symbol(name, sym, context=self.semanal_api.cur_mod_node)

class UnimportedTypesVisitor(TypeTraverserVisitor):
    def visit_instance(self, t: Instance) -> None:
        super().visit_instance(t)
        if isinstance(t.type, FakeInfo):
            return
        type_name = t.type.name
        sym = currently_imported_symbols.get(type_name)
        if sym is None:
            import_symbol_from_source(type_name)

signature_node.type.accept(UnimportedTypesVisitor())

Compiled version of mypy segfaults for me, when I'm trying to use code like this. The plain Python version runs just fine.

@msullivan msullivan self-assigned this Feb 3, 2020
@msullivan
Copy link
Collaborator

Could you try to produce a standalone test case for me to run somehow?

msullivan added a commit that referenced this issue Aug 2, 2020
This prevents a bunch of segfaults

Closes #9001. Closes #8360.  It doesn't close either of them in a
satisfactory way, though. Really they would like actual support, which
I've opened as mypyc/mypyc#754.

Related to mypyc/mypyc#655. (At some point there used to be working
dynamic checks for at least one of these cases. Not sure when that
broke.)
@msullivan
Copy link
Collaborator

There are two issues here: that we don't support what this code does, and that it segfaults. I've opened mypyc/mypyc#754 for the former and submitted #9248 for the latter.

The specific problem is that we don't support subclassing compiled traits from interpreted code. We could create a concrete subclass of TypeTraverserVisitor in complied code, though, and you could subclass that?
(Eventually we want to actually support this, of course, but we don't yet.)

JukkaL pushed a commit that referenced this issue Aug 3, 2020
This prevents a bunch of segfaults.

Closes #9001. Closes #8360.  It doesn't close either of them in a
satisfactory way, though. Really they would like actual support, which
I've opened as mypyc/mypyc#754.

Related to mypyc/mypyc#655. (At some point there used to be working
dynamic checks for at least one of these cases. Not sure when that
broke.)
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 a pull request may close this issue.

2 participants