question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Comments containing '?' are continuously shifted to the right if occurring in function body

See original GitHub issue

Checklist prior to opening an issue

  • I have followed fully the installation steps laid out in the documentation site.
  • I have restarted jupyterlab.
  • I have read the FAQ section in the documentation site.

Describe the bug

Python comments occurring in the body of a function definition are indented further with each formatting run using Black. This happens only when the comment contains a question mark ?. I’ll include a couple of screenshots below.

I’ve reinstalled the plugin in a clean conda environment. No other extensions are enabled. I’ve tested using both Python 3.8.8 and Python 3.9.2. Same result. The problem doesn’t seem to be due to Black, which manages to format the same piece of code correctly when it’s passed in as a Python module.

Diagnostic commands

  • pip freeze
packaging @ file:///home/conda/feedstock_root/build_artifacts/packaging_1612459636436/work
pandocfilters==1.4.2
parso @ file:///home/conda/feedstock_root/build_artifacts/parso_1607618318316/work
pathspec @ file:///home/conda/feedstock_root/build_artifacts/pathspec_1605120834673/work
pexpect @ file:///home/conda/feedstock_root/build_artifacts/pexpect_1602535608087/work
pickleshare @ file:///home/conda/feedstock_root/build_artifacts/pickleshare_1602536217715/work
prometheus-client @ file:///home/conda/feedstock_root/build_artifacts/prometheus_client_1605543085815/work
prompt-toolkit @ file:///home/conda/feedstock_root/build_artifacts/prompt-toolkit_1616432837031/work
ptyprocess @ file:///home/conda/feedstock_root/build_artifacts/ptyprocess_1609419310487/work/dist/ptyprocess-0.7.0-py2.py3-none-any.whl
pycparser @ file:///home/conda/feedstock_root/build_artifacts/pycparser_1593275161868/work
Pygments @ file:///home/conda/feedstock_root/build_artifacts/pygments_1615243893546/work
pyOpenSSL @ file:///home/conda/feedstock_root/build_artifacts/pyopenssl_1608055815057/work
pyparsing==2.4.7
pyrsistent @ file:///home/conda/feedstock_root/build_artifacts/pyrsistent_1610146801554/work
PySocks @ file:///home/conda/feedstock_root/build_artifacts/pysocks_1610291451001/work
python-dateutil==2.8.1
pytz @ file:///home/conda/feedstock_root/build_artifacts/pytz_1612179539967/work
pyzmq @ file:///home/conda/feedstock_root/build_artifacts/pyzmq_1614611691549/work
regex @ file:///home/conda/feedstock_root/build_artifacts/regex_1616104404007/work
requests @ file:///home/conda/feedstock_root/build_artifacts/requests_1608156231189/work
Send2Trash==1.5.0
six @ file:///home/conda/feedstock_root/build_artifacts/six_1590081179328/work
sniffio @ file:///home/conda/feedstock_root/build_artifacts/sniffio_1610318319523/work
terminado @ file:///home/conda/feedstock_root/build_artifacts/terminado_1617048651963/work
testpath==0.4.4
toml @ file:///home/conda/feedstock_root/build_artifacts/toml_1604308577558/work
tornado @ file:///home/conda/feedstock_root/build_artifacts/tornado_1610094708661/work
traitlets @ file:///home/conda/feedstock_root/build_artifacts/traitlets_1602771532708/work
typed-ast @ file:///home/conda/feedstock_root/build_artifacts/typed-ast_1609539256914/work
typing-extensions @ file:///home/conda/feedstock_root/build_artifacts/typing_extensions_1602702424206/work
urllib3 @ file:///home/conda/feedstock_root/build_artifacts/urllib3_1615828766818/work
wcwidth @ file:///home/conda/feedstock_root/build_artifacts/wcwidth_1600965781394/work
webencodings==0.5.1
zipp @ file:///home/conda/feedstock_root/build_artifacts/zipp_1614945704755/work
  • jupyter labextension list
JupyterLab v3.0.12
/home/adriaan/miniforge3/envs/jupyter/share/jupyter/labextensions
        @ryantam626/jupyterlab_code_formatter v1.4.5 enabled OK (python, jupyterlab-code-formatter)
  • jupyter serverextension list
config dir: /home/{me}/miniforge3/envs/jupyter/etc/jupyter
    jupyterlab  enabled
    - Validating...
      jupyterlab 3.0.12 OK
    jupyterlab_code_formatter  enabled
    - Validating...
      jupyterlab_code_formatter 1.4.5 OK

Screenshots

Before formatting:

Screen Shot 2021-03-30 at 19 55 37

After:

Screen Shot 2021-03-30 at 19 55 45

Additional runs shift the comment further and further to the right.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
lemonthemecommented, Apr 3, 2021

Just took the new release out for a spin. Can confirm: it works just as you’d expect now. Really great to see stuff like this get patched so quickly. Thanks!

The conversation here has given me a bit more insight into how the extension works. Next issue I encounter, I’ll try to PR a fix myself.

1reaction
ryantam626commented, Apr 2, 2021

1.4.8 is now released with (^(?!\s*#)(.*)\?\??)$ which hopefully does the job correctly…

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Go Programming Language Specification
A general comment containing no newlines acts like a space. Any other comment acts like a newline. Tokens. Tokens form the vocabulary of...
Read more >
Structure and Function of Blood Vessels - Lumen Learning
The systemic circuit moves blood from the left side of the heart to the head and body and returns it to the right...
Read more >
A tour of the Dart language
You can't use await or yield as an identifier in any function body marked ... If you fail to initialize a late variable,...
Read more >
Physiology, Pulmonary Ventilation and Perfusion - NCBI - NIH
The effect of physiologic right-to-left shunts is minimized by hypoxic vasoconstriction in the pulmonary circulation, which redirects blood flow ...
Read more >
The Basics — The Swift Programming Language (Swift 5.7)
The value of a constant can't be changed once it's set, ... large blocks of code quickly and easily, even if the code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found