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

Question: Ignore code linebreaks in html output #673

Closed
buhtz opened this issue Dec 23, 2022 · 3 comments
Closed

Question: Ignore code linebreaks in html output #673

buhtz opened this issue Dec 23, 2022 · 3 comments

Comments

@buhtz
Copy link
Contributor

buhtz commented Dec 23, 2022

I keep my code lines (including docstrings) less then 80 chars according to PEP8.
That makes problems in doc strings, e.g. when having long URLs in their.

See this real world example

class Foo:
    def _table_of_something(self, the_type: _ControlType):
        """Generic method to create a referene list (e.g. TOC).

        It is used for `table_of_contents()`.

        Credits ::

            The code is based on the following sources

            - ttps://stackoverflow.com/a/59170642/4865723
            - https://github.com/python-openxml/python-docx/issues/36
            - https://github.com/xiaominzhaoparadigm \
              /python-docx-add-list-of-tables-figures/blob/master/LOT.py

        """
        pass

You see the 3rd url in the doc string? I added a newline via \ (backslash). PyDoctor doesn't handle that. The output looks like this.
image

Is there a way to work around this without violating PEP8 or adding exceptional rules about line length to my code linter?

@tristanlatr
Copy link
Contributor

Hi @buhtz,

Pydoctor doesn’t have support for token information at this time. See #294. it reads the docstring (and other values) as given by the ast. So having special logic for the backslash character is not currently possible, because the ast does not contains this information.

It’s not gorgeous but you can probably do that:

class Foo:
    def _table_of_something(self, the_type: _ControlType):
        """Generic method to create a referene list (e.g. TOC).

        It is used for `table_of_contents()`.

        Credits ::

            The code is based on the following sources

            - ttps://stackoverflow.com/a/59170642/4865723
            - https://github.com/python-openxml/python-docx/issues/36
            - https://github.com/xiaominzhaoparadigm\
/python-docx-add-list-of-tables-figures/blob/master/LOT.py

        """
        pass

Tell me if it works as expected,

@buhtz
Copy link
Contributor Author

buhtz commented Dec 26, 2022

Thanks. This does work. Even flake8 is satisfied. ;)

@buhtz buhtz closed this as completed Dec 26, 2022
@buhtz
Copy link
Contributor Author

buhtz commented Jan 25, 2023

I just want to add another solution/workaround.

class Foo:
    def _table_of_something(self, the_type: _ControlType):
        """Generic method to create a referene list (e.g. TOC).

        It is used for `table_of_contents()`.

        Credits ::

            The code is based on the following sources

            - ttps://stackoverflow.com/a/59170642/4865723
            - https://github.com/python-openxml/python-docx/issues/36
            - https://github.com/xiaominzhaoparadigm\python-docx-add-list-of-tables-figures/blob/master/LOT.py

        """  # noqa
        pass

The # noqua deactivate the code checking of the pycodestyle linter (and maybe others).

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