Skip to content

Commit 889080f

Browse files
committed
Version 0.5.0 release, closes #312
1 parent edf198b commit 889080f

File tree

14 files changed

+93
-62
lines changed

14 files changed

+93
-62
lines changed

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@
33
We follow Semantic Versions since the `0.1.0` release.
44
We used to have incremental versioning before `0.1.0`.
55

6-
## WIP
6+
## 0.5.0
77

88
### Features
99

10-
- Adds `TooLongNameViolation`
1110
- **Breaking**: removes `--max-conditions` and `--max-elifs` options
1211
- **Breaking**: removes `--max-offset-blocks`
1312
- **Breaking**: changes default `TooManyConditionsViolation` threshold from `3` to `4`
1413
- **Breaking**: changes `TooManyBaseClassesViolation` code from ``225`` to ``215``
1514
- Forbids to use `lambda` inside loops
16-
- Reserving names `self`, `cls`, and `mcs` for first arguments only
15+
- Forbids to use `self`, `cls`, and `mcs` except for first arguments only
1716
- Forbids to use too many decorators
18-
- Now `RedundantLoopElseViolation` also checks `while` loops
1917
- Forbids to have unreachable code
2018
- Forbids to have statements that have no effect
19+
- Forbids to have too long names for modules and variables
20+
- Forbids to have names with unicode for modules and variables
2121
- Add `variable` to the blacklisted names
22+
- Now `RedundantLoopElseViolation` also checks `while` loops
23+
2224

2325
## Bugfixes
2426

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "wemake-python-styleguide"
3-
version = "0.4.0"
3+
version = "0.5.0"
44
description = "The strictest and most opinionated python linter ever"
55

66
license = "MIT"

tests/test_checker/test_module_names.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
('123py.py', naming.WrongModuleNamePatternViolation),
1717
('version_1.py', naming.UnderscoredNumberNameViolation),
1818
('__private.py', naming.PrivateNameViolation),
19-
('oh_no_not_an_extremely_super_duper_unreasonably_long_name.py',
20-
naming.TooLongNameViolation),
19+
(
20+
'oh_no_not_an_extremely_super_duper_unreasonably_long_name.py',
21+
naming.TooLongNameViolation,
22+
),
23+
('привет', naming.UnicodeNameViolation),
2124
])
2225
def test_module_names(filename, error, default_options):
2326
"""Ensures that checker works with module names."""

tests/test_visitors/test_ast/test_complexity/test_counts/test_method_counts.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ def first(): ...
1313
def second(): ...
1414
"""
1515

16-
module_without_methods_with_async_functions = """
16+
module_with_async_functions = """
1717
async def first(): ...
1818
1919
async def second(): ...
2020
"""
2121

22-
module_without_methods_with_async_and_usual_functions = """
22+
module_async_and_usual_functions = """
2323
def first(): ...
2424
2525
async def second(): ...
@@ -76,8 +76,8 @@ async def method2(cls): ...
7676

7777
@pytest.mark.parametrize('code', [
7878
module_without_methods,
79-
module_without_methods_with_async_functions,
80-
module_without_methods_with_async_and_usual_functions,
79+
module_with_async_functions,
80+
module_async_and_usual_functions,
8181
class_with_methods,
8282
class_with_async_methods,
8383
class_with_async_and_usual_methods,

tests/test_visitors/test_ast/test_complexity/test_counts/test_module_counts.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class Second(object):
2222
def method(self): ...
2323
"""
2424

25-
module_with_function_and_class_and_async_method = """
25+
module_with_function_and_async_method = """
2626
def first(): ...
2727
2828
class Second(object):
2929
async def method(self): ...
3030
"""
3131

32-
module_with_function_and_class_and_classmethod = """
32+
module_with_function_and_classmethod = """
3333
def first(): ...
3434
3535
class Second(object):
@@ -98,8 +98,8 @@ def other(self): ...
9898
empty_module,
9999
module_with_function_and_class,
100100
module_with_function_and_class_and_method,
101-
module_with_function_and_class_and_async_method,
102-
module_with_function_and_class_and_classmethod,
101+
module_with_function_and_async_method,
102+
module_with_function_and_classmethod,
103103
module_with_async_function_and_class,
104104
module_with_methods,
105105
module_with_async_methods,
@@ -124,8 +124,8 @@ def test_module_counts_normal(
124124
@pytest.mark.parametrize('code', [
125125
module_with_function_and_class,
126126
module_with_function_and_class_and_method,
127-
module_with_function_and_class_and_async_method,
128-
module_with_function_and_class_and_classmethod,
127+
module_with_function_and_async_method,
128+
module_with_function_and_classmethod,
129129
module_with_async_function_and_class,
130130
module_with_methods,
131131
module_with_async_methods,

tests/test_visitors/test_ast/test_keywords/test_comprehensions/test_for_count.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_multiple_for_keywords_in_comprehension(
100100
@pytest.mark.parametrize('code', [
101101
complex_nested_list_comprehension,
102102
])
103-
def test_multiple_for_keywords_in_async_comprehension(
103+
def test_multiple_fors_in_async_comprehension(
104104
assert_errors,
105105
parse_ast_tree,
106106
code,
@@ -120,7 +120,7 @@ def test_multiple_for_keywords_in_async_comprehension(
120120
regular_dict_comprehension,
121121
regular_gen_expression,
122122
])
123-
def test_regular_for_keywords_in_comprehension(
123+
def test_regular_fors_in_comprehension(
124124
assert_errors,
125125
parse_ast_tree,
126126
code,
@@ -137,7 +137,7 @@ def test_regular_for_keywords_in_comprehension(
137137
@pytest.mark.parametrize('code', [
138138
regular_nested_list_comprehension,
139139
])
140-
def test_regular_for_keywords_in_async_comprehension(
140+
def test_regular_fors_in_async_comprehension(
141141
assert_errors,
142142
parse_ast_tree,
143143
code,

tests/test_visitors/test_ast/test_naming/test_length_config.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/test_visitors/test_ast/test_naming/test_naming_rules/test_short.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# -*- coding: utf-8 -*-
22

3+
import pytest
4+
35
from wemake_python_styleguide.violations.naming import TooShortNameViolation
46
from wemake_python_styleguide.visitors.ast.naming import WrongNameVisitor
57

@@ -21,3 +23,25 @@ def test_short_variable_name(
2123

2224
assert_errors(visitor, [TooShortNameViolation])
2325
assert_error_text(visitor, short_name)
26+
27+
28+
@pytest.mark.parametrize('correct_name', [
29+
'snake_case',
30+
'_protected_or_unused',
31+
'with_number5',
32+
])
33+
def test_naming_correct(
34+
assert_errors,
35+
parse_ast_tree,
36+
naming_template,
37+
options,
38+
correct_name,
39+
):
40+
"""Ensures that correct names are allowed."""
41+
tree = parse_ast_tree(naming_template.format(correct_name))
42+
43+
option_values = options(min_name_length=3)
44+
visitor = WrongNameVisitor(option_values, tree=tree)
45+
visitor.run()
46+
47+
assert_errors(visitor, [])

tests/test_visitors/test_tokenize/test_wrong_keywords/test_keywords_spaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_missing_space(
9292
multiline_correct_function,
9393
multiline_correct_statement,
9494
])
95-
def test_fine_when_space_in_between_keyword_and_parens(
95+
def test_space_between_keyword_and_parens(
9696
parse_tokens,
9797
assert_errors,
9898
default_options,

wemake_python_styleguide/logics/naming/logical.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def is_wrong_name(name: str, to_check: Iterable[str]) -> bool:
3030
3131
"""
3232
for name_to_check in to_check:
33-
choices_to_check = [
33+
choices_to_check = {
3434
name_to_check,
3535
'_{0}'.format(name_to_check),
3636
'{0}_'.format(name_to_check),
37-
]
37+
}
3838
if name in choices_to_check:
3939
return True
4040
return False
@@ -74,7 +74,7 @@ def is_too_short_name(
7474
min_length: int = defaults.MIN_NAME_LENGTH,
7575
) -> bool:
7676
"""
77-
Checks for too short variable names.
77+
Checks for too short names.
7878
7979
>>> is_too_short_name('test')
8080
False
@@ -100,7 +100,7 @@ def is_too_long_name(
100100
max_length: int = defaults.MAX_NAME_LENGTH,
101101
) -> bool:
102102
"""
103-
Checks for too long variable names.
103+
Checks for too long names.
104104
105105
>>> is_too_long_name('test')
106106
False
@@ -123,7 +123,7 @@ def is_too_long_name(
123123

124124
def does_contain_underscored_number(name: str) -> bool:
125125
"""
126-
Checks for variable names with underscored number.
126+
Checks for names with underscored number.
127127
128128
>>> does_contain_underscored_number('star_wars_episode2')
129129
False
@@ -158,7 +158,7 @@ def does_contain_underscored_number(name: str) -> bool:
158158

159159
def does_contain_consecutive_underscores(name: str) -> bool:
160160
"""
161-
Checks if variable contains consecutive underscores in middle of name.
161+
Checks if name contains consecutive underscores in middle of name.
162162
163163
>>> does_contain_consecutive_underscores('name')
164164
False
@@ -186,3 +186,28 @@ def does_contain_consecutive_underscores(name: str) -> bool:
186186
return True
187187

188188
return False
189+
190+
191+
def does_contain_unicode(name: str) -> bool:
192+
"""
193+
Check if name contains unicode characters.
194+
195+
>>> does_contain_unicode('hello_world1')
196+
False
197+
198+
>>> does_contain_unicode('')
199+
False
200+
201+
>>> does_contain_unicode('привет_мир1')
202+
True
203+
204+
>>> does_contain_unicode('russian_техт')
205+
True
206+
207+
"""
208+
try:
209+
name.encode('ascii')
210+
except UnicodeEncodeError:
211+
return True
212+
else:
213+
return False

0 commit comments

Comments
 (0)