Skip to content

WPS221 (line Jones complexity) is overly strict with f-strings #3350

@Tapeline

Description

@Tapeline

What's wrong

Given following source code:

@frozen
class Token:
    """Represents a token."""

    type: TokenType
    lexeme: str
    value: str
    line: int
    char: int

    def __str__(self):
        """Convert token to string representation with info."""
        return f"{self.type}:{self.lexeme}:{self.line}:{self.char}"

WPS complains that: WPS221 Found line with high Jones Complexity: 17 > 14

However, this f-string is essentially the same thing as f"{type}:{lexeme}:{line}:{char}" (which passes WPS checks) both from semantic and perception point of view.

How it should be

It should be way less than 17 complexity

Flake8 version and plugins

{
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.13.2",
    "system": "Windows"
  },
  "plugins": [
    {
      "plugin": "mccabe",
      "version": "0.7.0"
    },
    {
      "plugin": "pycodestyle",
      "version": "2.12.1"
    },
    {
      "plugin": "pyflakes",
      "version": "3.2.0"
    },
    {
      "plugin": "wemake-python-styleguide",
      "version": "1.0.0"
    }
  ],
  "version": "7.1.2"
}

pip information

pip 23.2.1 from D:\Coding\PycharmProjects\Kumir-Compose\.venv\Lib\site-packages\pip (python 3.13)
annotated-types==0.7.0
anyio==4.9.0
attrs==25.3.0
build==1.2.2.post1
CacheControl==0.14.2
certifi==2025.1.31
charset-normalizer==3.4.1
cleo==2.1.0
click==8.1.8
colorama==0.4.6
covdefaults==2.3.0
coverage==7.7.0
crashtest==0.4.1
distlib==0.3.9
dulwich==0.22.8
fastapi==0.115.11
fastjsonschema==2.21.1
filelock==3.18.0
findpython==0.6.3
flake8==7.1.2
grimp==3.7.1
h11==0.14.0
httpcore==1.0.7
httpx==0.28.1
idna==3.10
import-linter==2.3
iniconfig==2.0.0
installer==0.7.0
jaraco.classes==3.4.0
jaraco.context==6.0.1
jaraco.functools==4.1.0
keyring==25.6.0
# Editable Git install with no remote
mccabe==0.7.0
more-itertools==10.6.0
msgpack==1.1.0
mypy==1.15.0
mypy-extensions==1.0.0
packaging==24.2
pbs-installer==2025.3.11
pkginfo==1.12.1.2
platformdirs==4.3.6
pluggy==1.5.0
poetry==2.1.1
poetry-core==2.1.1
pycodestyle==2.12.1
pydantic==2.10.6
pydantic_core==2.27.2
pyflakes==3.2.0
Pygments==2.19.1
pyproject_hooks==1.2.0
pytest==8.3.5
pytest-cov==6.0.0
pywin32-ctypes==0.2.3
RapidFuzz==3.12.2
requests==2.32.3
requests-toolbelt==1.0.0
ruff==0.11.0
shellingham==1.5.4
sniffio==1.3.1
starlette==0.46.1
syrupy==4.9.0
tomlkit==0.13.2
trove-classifiers==2025.3.13.13
typing_extensions==4.12.2
urllib3==2.3.0
uvicorn==0.34.0
virtualenv==20.29.3
wemake-python-styleguide==1.0.0
zstandard==0.23.0

OS information

Windows 10 22H2

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions