Skip to content

Empty lines in the output when using LazyImport #59

@A13xs

Description

@A13xs

Environment

  • Operating System: Linux
  • Python Version: 3.10
  • How did you install pyforest: pip install pyforest

Description of Issue

  • What did you expect to happen?
    Lazy loading of a library should not produce blank lines in the output.
  • What happened instead?
    A line break occurs when executing an instruction that must load the referenced library.

Reproduction Steps

  1. Run code
from pyforest import LazyImport

pd = LazyImport("import pandas as pd")

def prueba(df: pd.DataFrame) -> None:
    pass

What steps have you taken to resolve this already?

I think the problem is in this code block of _importable.py
If statements arrives empty, it will print the "\n".

Anything else?

A possible solution would be not to call the display function if there are no elements in statements.

  if len(statements) > 0:
        display(
            Javascript(
                """
            if (window._pyforest_update_imports_cell) {{ window._pyforest_update_imports_cell({!r}); }}
        """.format(
                    "\n".join(statements)
                )
            )
        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions