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

Block autopep off/on does not work for imports #770

Open
KubaO opened this issue Sep 11, 2024 · 1 comment
Open

Block autopep off/on does not work for imports #770

KubaO opened this issue Sep 11, 2024 · 1 comment

Comments

@KubaO
Copy link

KubaO commented Sep 11, 2024

autopep8 off/on doesn't work

Before formatting:

# autopep8: off
import sys
sys.dont_write_bytecode = True
# autopep8: on
import locale

After:

# autopep8: off
import locale
import sys
sys.dont_write_bytecode = True
# autopep8: on

The workaround is to add a semicolon and join the import line with the non-import line(s):

# autopep8: off
import sys; sys.dont_write_bytecode = True
# autopep8: on
import locale

Originally posted by @PlatonB in #460 (comment)

@Chris3606
Copy link

Chris3606 commented Sep 15, 2024

Similar issues appear to happen in docstrings. Something like this:

class A:
    # autopep8: off
    """Docstring
    
    .. code-block::python
      print(1)
      
      print (2)
    
    """
    # autopep8: on

autopep8 still insists on removing whitespace on the blank lines within the code example. This actually generates warnings/errors in documentation generators link Sphinx, and I don't have a workaround at the moment.

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