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

Distinction between FunctionType closure using PyCell and TypedCell is confusing #419

Open
braxtonmckee opened this issue Jan 19, 2023 · 0 comments
Labels
compiler Issue that does not affect the un-compiled subset of typed_python

Comments

@braxtonmckee
Copy link
Collaborator

I wrote this code:

from typed_python import TypeFunction, Class, Final, Member, Entrypoint

class Callback(Class):
    def execute(self) -> None:
        raise NotImplementedError(self)


@TypeFunction
def TypedCallback(T):
    class TypedCallback(Callback, Final, __name__=f"TypedCallback({T.__name__})"):
        callback = Member(T)

        def __init__(self, callback):
            self.callback = callback

        def execute(self):
            self.callback()

    return TypedCallback

@Entrypoint
def makeCallback(callback):
    return TypedCallback(type(callback))(callback)

x = ListOf(int)()

@Entrypoint
def f():
    x.append(10)

c = makeCallback(f)

Depending on whether i have 'Entrypoint' on makeCallback, I get completely different behavior because with the Entrypoint I get a FunctionType that has typed closures, and without it I get one with PyCell (which we can't compile).

We need to tighten up the way we handle lambdas so that we can use them like this with coherent semantics.

@braxtonmckee braxtonmckee added the compiler Issue that does not affect the un-compiled subset of typed_python label Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Issue that does not affect the un-compiled subset of typed_python
Projects
None yet
Development

No branches or pull requests

1 participant