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

# fmt: skip cannot be combined with another comment #3460

Closed
ricardo-dematos opened this issue Dec 19, 2022 · 2 comments
Closed

# fmt: skip cannot be combined with another comment #3460

ricardo-dematos opened this issue Dec 19, 2022 · 2 comments
Labels
F: fmtskip fmt: skip implementation T: bug Something isn't working

Comments

@ricardo-dematos
Copy link

Describe the bug

With below configuration in pyproject.toml :

[tool.black]

# How many characters per line to allow.
line-length = 120

# When processing Jupyter Notebooks, add the given magic to the list of known 
# python-magics (timeit, prun, capture, pypy, python3, python, time). 
# Useful for formatting cells with custom python magics.
# python-cell-magics = 

# Require a specific version of Black to be running 
# (useful for unifying results across many environments e.g. with a pyproject.toml file). 
# It can be either a major version number or an exact version.
# required-version = 

# A regular expression that matches files and directories that should be 
# included on recursive searches. An empty value means all files are included 
# regardless of the name. Use forward slashes for directories on all platforms (Windows, too). 
# Exclusions are calculated first, inclusions later.
# include = "(\.pyi?|\.ipynb)$"

# A regular expression that matches files and directories that should be 
# excluded on recursive searches. An empty value means no paths are excluded. 
# Use forward slashes for directories on all platforms (Windows, too). 
# Exclusions are calculated first, inclusions later.
# exclude = "/(\.direnv|\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|venv|\.svn|\.ipynb_checkpoints|_build|buck-out|build|dist|__pypackages__)/"

# Like 'exclude', but adds additional files and directories on top of the excluded ones.
# (Useful if you simply want to add to the default).
# extend-exclude = 

# Like 'exclude', but files and directories matching this regex will be excluded 
# even when they are passed explicitly as arguments.
# force-exclude = 

# The name of the file when passing it through stdin. 
# Useful to make sure Black will respect 'force-exclude' option on some editors that rely on using stdin.
# stdin-filename = 

# Number of parallel workers. 
# Can be a number or a range.
# workers = 

and this command line :

black --config "pyproject.toml" --target-version py39 --check --diff .

the following line of code is flagged :

ave_quantity = self.exec_math(math_iterable["mean"], "mean", [])  # execute the "mean" fxn on the dataset  # cspell: disable-line # fmt: skip
--- properties/datasets/models.py    2022-11-30 00:01:16.590743 +0000
+++ properties/datasets/models.py    2022-11-30 00:01:18.692767 +0000
@@ -746,11 +746,13 @@
         calculate the mean value of all the dataset points
 
         return: numerical value of this function when all variables are zero
         rtype: float
         """
-        ave_quantity = self.exec_math(math_iterable["mean"], "mean", [])  # execute the "mean" fxn on the dataset # fmt:skip
+        ave_quantity = self.exec_math(
+            math_iterable["mean"], "mean", []
+        )  # execute the "mean" fxn on the dataset # fmt:skip
         return getattr(ave_quantity, "magnitude", 0.0)
 
     def serialize(self, flat=False):
         return {
             "type": "dataset",
would reformat properties/datasets/models.py

Oh no! 💥 💔 💥
1 file would be reformatted, 102 files would be left unchanged.

Which contradicts

Black reformats entire files in place. It doesn’t reformat lines that end with # fmt: skip or blocks that start with # fmt: off and end with # fmt: on.

Expected behavior

Black should honor the directive # fmt: skip and ignore the flagged line of code.

Environment

  • Black's version: 22.12.0
  • OS and Python version: Ubuntu 22.04.1 LTS/Python 3.9.16

Additional context

With directive #fmt:skip as the solely comment in the end of the line, black honors the directive and ignores the line of code.

Related to

@ricardo-dematos ricardo-dematos added the T: bug Something isn't working label Dec 19, 2022
@JelleZijlstra JelleZijlstra added the F: fmtskip fmt: skip implementation label Dec 19, 2022
@FSpanhel
Copy link

FSpanhel commented Jan 4, 2023

This is related to #3450 where it is also shown that adding a hash before #fmt:skip results in black not ignoring this line of code.

@JelleZijlstra JelleZijlstra changed the title Black is not honoring #fmt: skip # fmt: skip cannot be combined with another comment Jul 10, 2023
@JelleZijlstra
Copy link
Collaborator

Duplicate of #3330

@JelleZijlstra JelleZijlstra marked this as a duplicate of #3330 Jul 10, 2023
@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: fmtskip fmt: skip implementation T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants