Skip to content

Commit 03a5e65

Browse files
authored
ref: Introduce linter for proper naming conventions (#636)
* ref: Introduce linter for proper naming conventions * ref: Document reasons for ignoring lints
1 parent 909ecaa commit 03a5e65

File tree

16 files changed

+156
-133
lines changed

16 files changed

+156
-133
lines changed

.flake8

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
[flake8]
22
ignore =
3-
E203, E266, E501, W503, E402, E731, C901, B950, B011,
4-
B014 // does not apply to Python 2
3+
E203, // Handled by black (Whitespace before ':' -- handled by black)
4+
E266, // Handled by black (Too many leading '#' for block comment)
5+
E501, // Handled by black (Line too long)
6+
W503, // Handled by black (Line break occured before a binary operator)
7+
E402, // Sometimes not possible due to execution order (Module level import is not at top of file)
8+
E731, // I don't care (Do not assign a lambda expression, use a def)
9+
C901, // I don't care (Function is too complex)
10+
B950, // Handled by black (Line too long by flake8-bugbear)
11+
B011, // I don't care (Do not call assert False)
12+
B014, // does not apply to Python 2 (redundant exception types by flake8-bugbear)
13+
N812, // I don't care (Lowercase imported as non-lowercase by pep8-naming)
14+
N804 // is a worse version of and conflicts with B902 (first argument of a classmethod should be named cls)
515
max-line-length = 80
616
max-complexity = 18
7-
select = B,C,E,F,W,T4,B9
17+
select = N,B,C,E,F,W,T4,B9
818
exclude=checkouts,lol*,.tox

linter-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ flake8
33
flake8-import-order
44
mypy==0.761
55
flake8-bugbear>=19.8.0
6+
pep8-naming

sentry_sdk/_compat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ def reraise(tp, value, tb=None):
5959

6060
def with_metaclass(meta, *bases):
6161
# type: (Any, *Any) -> Any
62-
class metaclass(type):
62+
class MetaClass(type):
6363
def __new__(metacls, name, this_bases, d):
6464
# type: (Any, Any, Any, Any) -> Any
6565
return meta(name, bases, d)
6666

67-
return type.__new__(metaclass, "temporary_class", (), {})
67+
return type.__new__(MetaClass, "temporary_class", (), {})
6868

6969

7070
def check_thread_support():

sentry_sdk/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def __exit__(self, exc_type, exc_value, tb):
389389
# Use `ClientConstructor` to define the argument types of `init` and
390390
# `Dict[str, Any]` to tell static analyzers about the return type.
391391

392-
class get_options(ClientConstructor, Dict[str, Any]):
392+
class get_options(ClientConstructor, Dict[str, Any]): # noqa: N801
393393
pass
394394

395395
class Client(ClientConstructor, _Client):

sentry_sdk/hub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def _init(*args, **kwargs):
118118
# Use `ClientConstructor` to define the argument types of `init` and
119119
# `ContextManager[Any]` to tell static analyzers about the return type.
120120

121-
class init(ClientConstructor, ContextManager[Any]):
121+
class init(ClientConstructor, ContextManager[Any]): # noqa: N801
122122
pass
123123

124124

sentry_sdk/integrations/bottle.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
raise DidNotEnable("Bottle not installed")
3535

3636

37+
TRANSACTION_STYLE_VALUES = ("endpoint", "url")
38+
39+
3740
class BottleIntegration(Integration):
3841
identifier = "bottle"
3942

@@ -42,7 +45,6 @@ class BottleIntegration(Integration):
4245
def __init__(self, transaction_style="endpoint"):
4346
# type: (str) -> None
4447

45-
TRANSACTION_STYLE_VALUES = ("endpoint", "url")
4648
if transaction_style not in TRANSACTION_STYLE_VALUES:
4749
raise ValueError(
4850
"Invalid value for transaction_style: %s (must be in %s)"

sentry_sdk/integrations/django/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ def is_authenticated(request_user):
7171
return request_user.is_authenticated
7272

7373

74+
TRANSACTION_STYLE_VALUES = ("function_name", "url")
75+
76+
7477
class DjangoIntegration(Integration):
7578
identifier = "django"
7679

@@ -79,7 +82,6 @@ class DjangoIntegration(Integration):
7982

8083
def __init__(self, transaction_style="url", middleware_spans=True):
8184
# type: (str, bool) -> None
82-
TRANSACTION_STYLE_VALUES = ("function_name", "url")
8385
if transaction_style not in TRANSACTION_STYLE_VALUES:
8486
raise ValueError(
8587
"Invalid value for transaction_style: %s (must be in %s)"

sentry_sdk/integrations/falcon.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,16 @@ def process_request(self, req, resp, *args, **kwargs):
8181
scope.add_event_processor(_make_request_event_processor(req, integration))
8282

8383

84+
TRANSACTION_STYLE_VALUES = ("uri_template", "path")
85+
86+
8487
class FalconIntegration(Integration):
8588
identifier = "falcon"
8689

8790
transaction_style = None
8891

8992
def __init__(self, transaction_style="uri_template"):
9093
# type: (str) -> None
91-
TRANSACTION_STYLE_VALUES = ("uri_template", "path")
9294
if transaction_style not in TRANSACTION_STYLE_VALUES:
9395
raise ValueError(
9496
"Invalid value for transaction_style: %s (must be in %s)"

sentry_sdk/integrations/flask.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@
4646
raise DidNotEnable("Flask is not installed")
4747

4848

49+
TRANSACTION_STYLE_VALUES = ("endpoint", "url")
50+
51+
4952
class FlaskIntegration(Integration):
5053
identifier = "flask"
5154

5255
transaction_style = None
5356

5457
def __init__(self, transaction_style="endpoint"):
5558
# type: (str) -> None
56-
TRANSACTION_STYLE_VALUES = ("endpoint", "url")
5759
if transaction_style not in TRANSACTION_STYLE_VALUES:
5860
raise ValueError(
5961
"Invalid value for transaction_style: %s (must be in %s)"

sentry_sdk/integrations/pyramid.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ def authenticated_userid(request):
4343
from pyramid.security import authenticated_userid # type: ignore
4444

4545

46+
TRANSACTION_STYLE_VALUES = ("route_name", "route_pattern")
47+
48+
4649
class PyramidIntegration(Integration):
4750
identifier = "pyramid"
4851

4952
transaction_style = None
5053

5154
def __init__(self, transaction_style="route_name"):
5255
# type: (str) -> None
53-
TRANSACTION_STYLE_VALUES = ("route_name", "route_pattern")
5456
if transaction_style not in TRANSACTION_STYLE_VALUES:
5557
raise ValueError(
5658
"Invalid value for transaction_style: %s (must be in %s)"

0 commit comments

Comments
 (0)