Wemake-python-styleguide: False positive Z114 for time-based suffixes

Created on 13 Jan 2019  路  6Comments  路  Source: wemake-services/wemake-python-styleguide

Bug report

What's wrong

The Z114 rule restricts numbers in variables, unless they are trailing ones. However, there are some cases when this rule is wrong:

Z114 Found underscored name pattern: clicks_1h
Z114 Found underscored name pattern: shows_1h
Z114 Found underscored name pattern: shows_24h
Z114 Found underscored name pattern: clicks_24h

We have a code., which calculates some CTR metrics for 1 hour and 24 hour period. Obliviously for us is to include the period in variable name to avoid any confusions. But this makes such names illegal for linter.

How is that should be

This rule should allow to have time-based suffixes.

System information

flake8 information

Contents of flake8 --bug-report:

{
  "dependencies": [
    {
      "dependency": "setuptools",
      "version": "40.6.3"
    }
  ],
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.6.3",
    "system": "Linux"
  },
  "plugins": [
    {
      "is_local": false,
      "plugin": "flake8-bandit",
      "version": "v1.0.2"
    },
    {
      "is_local": false,
      "plugin": "flake8-broken-line",
      "version": "0.1.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-bugbear",
      "version": "18.8.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-comprehensions",
      "version": "1.4.1"
    },
    {
      "is_local": false,
      "plugin": "flake8-debugger",
      "version": "3.1.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-docstrings",
      "version": "1.3.0, pydocstyle: 3.0.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-eradicate",
      "version": "0.2.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-print",
      "version": "3.1.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-string-format",
      "version": "0.2.3"
    },
    {
      "is_local": false,
      "plugin": "flake8-type-annotations",
      "version": "0.1.0"
    },
    {
      "is_local": false,
      "plugin": "flake8_builtins",
      "version": "1.4.1"
    },
    {
      "is_local": false,
      "plugin": "flake8_coding",
      "version": "1.3.1"
    },
    {
      "is_local": false,
      "plugin": "flake8_commas",
      "version": "2.0.0"
    },
    {
      "is_local": false,
      "plugin": "flake8_isort",
      "version": "2.3"
    },
    {
      "is_local": false,
      "plugin": "flake8_pep3101",
      "version": "1.2.1"
    },
    {
      "is_local": false,
      "plugin": "flake8_quotes",
      "version": "1.0.0"
    },
    {
      "is_local": false,
      "plugin": "logging-format",
      "version": "0.6.0"
    },
    {
      "is_local": false,
      "plugin": "mccabe",
      "version": "0.6.1"
    },
    {
      "is_local": false,
      "plugin": "naming",
      "version": "0.7.0"
    },
    {
      "is_local": false,
      "plugin": "per-file-ignores",
      "version": "0.7"
    },
    {
      "is_local": false,
      "plugin": "pycodestyle",
      "version": "2.4.0"
    },
    {
      "is_local": false,
      "plugin": "pyflakes",
      "version": "2.0.0"
    },
    {
      "is_local": false,
      "plugin": "wemake-python-styleguide",
      "version": "0.6.2"
    }
  ],
  "version": "3.6.0"
}

pip information

Contents of pip freeze:

added-value==0.14.1
alabaster==0.7.12
astor==0.7.1
atomicwrites==1.2.1
attrs==18.2.0
Babel==2.6.0
bandit==1.5.1
CacheControl==0.12.5
cachy==0.2.0
certifi==2018.11.29
chardet==3.0.4
cleo==0.6.8
Click==7.0
coverage==4.5.2
doc8==0.8.0
docutils==0.14
dparse==0.4.1
eradicate==1.0
flake8==3.6.0
flake8-bandit==1.0.2
flake8-broken-line==0.1.0
flake8-bugbear==18.8.0
flake8-builtins==1.4.1
flake8-coding==1.3.1
flake8-commas==2.0.0
flake8-comprehensions==1.4.1
flake8-debugger==3.1.0
flake8-docstrings==1.3.0
flake8-eradicate==0.2.0
flake8-isort==2.6.0
flake8-logging-format==0.6.0
flake8-pep3101==1.2.1
flake8-per-file-ignores==0.7
flake8-polyfill==1.0.2
flake8-print==3.1.0
flake8-quotes==1.0.0
flake8-string-format==0.2.3
flake8-type-annotations==0.1.0
gitdb2==2.0.5
GitPython==2.1.11
html5lib==1.0.1
idna==2.8
imagesize==1.1.0
isort==4.3.4
Jinja2==2.10
jsonschema==3.0.0a4
lockfile==0.12.2
m2r==0.2.1
MarkupSafe==1.1.0
mccabe==0.6.1
mistune==0.8.4
more-itertools==5.0.0
msgpack==0.6.0
mypy==0.650
mypy-extensions==0.4.1
natsort==5.5.0
packaging==18.0
pastel==0.1.0
pathmatch==0.2.1
pbr==5.1.1
pep8-naming==0.7.0
pkginfo==1.5.0.1
pluggy==0.8.1
poetry==0.12.10
py==1.7.0
pycodestyle==2.4.0
pydocstyle==3.0.0
pyflakes==2.0.0
Pygments==2.3.1
pylev==1.3.0
pyparsing==2.3.0
pyrsistent==0.14.9
pytest==4.1.0
pytest-cov==2.6.1
pytest-randomly==1.2.3
pytz==2018.9
PyYAML==3.13
requests==2.21.0
requests-toolbelt==0.8.0
restructuredtext-lint==1.2.2
safety==1.8.4
shellingham==1.2.8
six==1.12.0
smmap2==2.0.5
snowballstemmer==1.2.1
Sphinx==1.8.3
sphinx-autodoc-typehints==1.6.0
sphinxcontrib-mermaid==0.3.1
sphinxcontrib-websupport==1.1.0
stevedore==1.30.0
testfixtures==6.4.3
tomlkit==0.5.3
typed-ast==1.1.1
typing==3.6.6
typing-extensions==3.6.6
urllib3==1.24.1
webencodings==0.5.1
-e git+https://github.com/wemake-services/wemake-python-styleguide/@fce0dcbc79b030bae58de9da09777be07e6c6803#egg=wemake_python_styleguide&subdirectory=../../..
bug

All 6 comments

Hm, can you suggest a general rule to make this check work for you?

Well, I'm not sure for general case since I could only give that specific one to you: allow _\d+[smhd] suffixes.

How about?

clicks_h1
shows_h1
shows_h24
clicks_h24

Readability cries in agony. May be clicks_for_hour / shows_for_day would work, but that's a strange rename just to rename.

@kxepal ok, your example is even better. This is not useless, since by this strict process we find cases that can be improved. Compare clicks_24h and clicks_per_day. The second one is way better.

Closing as resolved.

Oh, remind me not to suggest you again in my bugs (: Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sobolevn picture sobolevn  路  4Comments

Dreamsorcerer picture Dreamsorcerer  路  3Comments

hangtwenty picture hangtwenty  路  5Comments

webknjaz picture webknjaz  路  3Comments

chamaoskurumi picture chamaoskurumi  路  5Comments