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

TypeError: set_css() takes 0 positional arguments but 1 was given #205

Open
msusol opened this issue Aug 1, 2024 · 2 comments
Open

TypeError: set_css() takes 0 positional arguments but 1 was given #205

msusol opened this issue Aug 1, 2024 · 2 comments

Comments

@msusol
Copy link

msusol commented Aug 1, 2024

source: notebooks/llmu/Introduction_to_RAG.ipynb

#@title Enable text wrapping in Google Colab

from IPython.display import HTML, display

def set_css():
    display(HTML('''
    <style>
        pre {
            white-space: pre-wrap;
        }
    </style>
    '''))

get_ipython().events.register('pre_run_cell', set_css)

running the notebook in IntelliJ yields

Error in callback <function set_css at 0x1042df380> (for pre_run_cell), with arguments args (<ExecutionInfo object at 10425b500, raw_cell="from IPython.display import HTML, display

def set.." store_history=True silent=False shell_futures=True cell_id=None>,),kwargs {}:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
TypeError: set_css() takes 0 positional arguments but 1 was given
@msusol
Copy link
Author

msusol commented Aug 1, 2024

I see in another notebook in LLMU #@title Enable text wrapping in Google Colab and I need to clarify I am using IntelliJ to run the notebooks. No issues when running in Colab.

@ai-yann
Copy link
Collaborator

ai-yann commented Oct 23, 2024

Sorry for that issue and thanks for mentioning it.

The error you're seeing probably happens because IntelliJ's Jupyter implementation passes a cell execution event object to the callback function, but the current set_css() function doesn't accept any parameters.

Try changing the set_css() function to accept an optional parameter:

from IPython.display import HTML, display

def set_css(*args):  # Accept variable arguments
    display(HTML('''
    <style>
        pre {
            white-space: pre-wrap;
        }
    </style>
    '''))

get_ipython().events.register('pre_run_cell', set_css)

This way it should work both in Colab (where no argument is passed) and IntelliJ (where an execution event object is passed). The `*args` syntax allows the function to accept any number of positional arguments without raising an error, even if we don't use them.

Please let me know if that works for you, if you don't mind testing that for me in IntelliJ, and I'll make the change in this repo. Let me know if you have any questions!

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

No branches or pull requests

2 participants