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

Closure computation fails in Jupyter Notebooks #88

Open
willbakst opened this issue Dec 23, 2024 · 2 comments
Open

Closure computation fails in Jupyter Notebooks #88

willbakst opened this issue Dec 23, 2024 · 2 comments
Assignees
Labels
bug Something isn't working lilypad

Comments

@willbakst
Copy link
Contributor

Description

Not sure how feasible this is, but we should definitely work towards making it possible to use Lilypad inside of a Jupyter Notebook since many developers work there.

@willbakst willbakst added the enhancement New feature or request label Dec 23, 2024
@willbakst willbakst added bug Something isn't working lilypad and removed enhancement New feature or request lilypad labels Dec 23, 2024
@willbakst willbakst self-assigned this Dec 23, 2024
@willbakst willbakst assigned koxudaxi and willbakst and unassigned willbakst and koxudaxi Jan 7, 2025
@koxudaxi
Copy link
Collaborator

@willbakst
I investigated this issue and found that implementing Jupyter Notebook support would be quite challenging.

The key technical issues:

  1. When executing Closure.from_fn(fn)) in Jupyter Notebooks, it fails because code runs in __main__ as a virtual module.

  2. While we can access the code and user namespace through module.In and module.get_ipython().user_ns, we can't get the source code. Our code uses inspect.getsource(getattr(self.module, node.id, None))) to extract source code from modules, but modules in Jupyter's user_ns don't provide source-related information like __code__ or __file__. This makes it impossible to extract the actual code for target objects.

To solve this, we would need to:

  • Resolve referenced names (ast.Name) during AST traversal
  • Extract corresponding code for those references

This would require either:

  • Using third-party libraries for AST traversal
  • Or implementing our own reference resolution table

Due to the complexity of these changes, I decided not to implement this solution at this time.

@willbakst
Copy link
Contributor Author

Ok, let's put this on hold for the time being then. We can take a deeper look and evaluate later how much time we're willing to spend on this / possible other paths that could be easier to implement but sacrifice completeness.

My gut feeling is that we'll want to implement our own solution if feasible.

@willbakst willbakst assigned willbakst and unassigned koxudaxi Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lilypad
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants