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

Formatter: Doesn't format module docstrings #9701

Closed
MichaReiser opened this issue Jan 30, 2024 · 5 comments · Fixed by #9725
Closed

Formatter: Doesn't format module docstrings #9701

MichaReiser opened this issue Jan 30, 2024 · 5 comments · Fixed by #9725
Labels
bug Something isn't working formatter Related to the formatter good first issue Good for newcomers help wanted Contributions especially welcome

Comments

@MichaReiser
Copy link
Member

The formatter doesn't format the module's docstring.

See this example taken from the bokeh project playground

The code block of the module level docstring doesn't get formatted, but gets formatted just fine if it is a function-level docstring

""" Represent granular events that can be used to trigger callbacks.

Bokeh documents and applications are capable of supporting various kinds of
interactions. These are often associated with events, such as mouse or touch
events, interactive downsampling mode activation, widget or tool events, and
others. The classes in this module represent these different events, so that
callbacks can be attached and executed when they occur.

It is possible to respond to events with ``CustomJS`` callbacks, which will
function with or without a Bokeh server. This can be accomplished by passing
and event class, and a ``CustomJS`` model to the
:func:`~bokeh.model.Model.js_on_event` method. When the ``CustomJS`` is
executed in the browser, its ``cb_obj`` argument will contain the concrete
event object that triggered the callback.

.. code-block:: python

    from bokeh.events import ButtonClick
    from bokeh.models import Button, CustomJS

    button = Button(                 )

    button.js_on_event(ButtonClick, CustomJS(
        
        
        code='console.log("JS:Click")'))

Alternatively it is possible to trigger Python code to run when events
happen, in the context of a Bokeh application running on a Bokeh server.
This can accomplished by passing an event class, and a callback function
to the the :func:`~bokeh.model.Model.on_event` method. The callback should
accept a single argument ``event``, which will be passed the concrete
event object that triggered the callback.

.. code-block:: python

    from bokeh.events import ButtonClick
    from bokeh.models import Button

    button = Button()

    def callback(event         ):
        print('Python:Click')

    button.on_event(ButtonClick, callback)

.. note ::
    There is no throttling of events. Some events such as ``MouseMove``
    may trigger at a very high rate.

"""

def function():
    """ Represent granular events that can be used to trigger callbacks.

Bokeh documents and applications are capable of supporting various kinds of
interactions. These are often associated with events, such as mouse or touch
events, interactive downsampling mode activation, widget or tool events, and
others. The classes in this module represent these different events, so that
callbacks can be attached and executed when they occur.

It is possible to respond to events with ``CustomJS`` callbacks, which will
function with or without a Bokeh server. This can be accomplished by passing
and event class, and a ``CustomJS`` model to the
:func:`~bokeh.model.Model.js_on_event` method. When the ``CustomJS`` is
executed in the browser, its ``cb_obj`` argument will contain the concrete
event object that triggered the callback.

.. code-block:: python

    from bokeh.events import ButtonClick
    from bokeh.models import Button, CustomJS

    button = Button(                 )

    button.js_on_event(ButtonClick, CustomJS(
        
        
        code='console.log("JS:Click")'))

Alternatively it is possible to trigger Python code to run when events
happen, in the context of a Bokeh application running on a Bokeh server.
This can accomplished by passing an event class, and a callback function
to the the :func:`~bokeh.model.Model.on_event` method. The callback should
accept a single argument ``event``, which will be passed the concrete
event object that triggered the callback.

.. code-block:: python

    from bokeh.events import ButtonClick
    from bokeh.models import Button

    button = Button()

    def callback(event         ):
        print('Python:Click')

    button.on_event(ButtonClick, callback)

.. note ::
    There is no throttling of events. Some events such as ``MouseMove``
    may trigger at a very high rate.

"""
@MichaReiser MichaReiser added bug Something isn't working formatter Related to the formatter good first issue Good for newcomers help wanted Contributions especially welcome labels Jan 30, 2024
@MichaReiser MichaReiser added this to the Formatter: Stable milestone Jan 30, 2024
@Glyphack
Copy link
Contributor

I'll try to tackle this. Just writing to avoid double work. 😃

@charliermarsh
Copy link
Member

Awesome :)

@MichaReiser
Copy link
Member Author

@Glyphack awesome! The formatting of statements happens in suite.rs. There's already logic to format class and function docstrings, but it doesn't yet kick in at the top level. Let me know if you want more pointers.

@Glyphack
Copy link
Contributor

I found that the stringaLiteralKind is not set correctly. I'm planning to add a function to see if a node is first statement and then set the doc string kind for string literal. Will open the pr shortly. Thanks for your help.

@MichaReiser
Copy link
Member Author

There's already logic in suite.rs that tests if it's the first statement. I'm not at my computer so sharing the source is a bit difficult but search for the place where we identify docstrings for classes and functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working formatter Related to the formatter good first issue Good for newcomers help wanted Contributions especially welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants