Skip to content

Commit b594f18

Browse files
committed
Add flake8-bugbear to report potential bugs
1 parent c991716 commit b594f18

File tree

11 files changed

+24
-13
lines changed

11 files changed

+24
-13
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
ignore = E203,W503
55
exclude = .git,.mypy_cache,.pytest_cache,.tox,.venv,__pycache__,build,dist,docs
66
max-line-length = 88
7+
per-file-ignores = tests/*:B011

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ optional = true
6363
black = "22.8.0"
6464
flake8 = "^5.0"
6565
flake8-bandit = "^4.1"
66+
flake8-bugbear = "22.9.23"
6667
isort = "^5.10"
6768
mypy = "0.971"
6869
bump2version = ">=1.0,<2"

src/graphql/execution/execute.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ async def await_completed(item: Any, item_path: Path) -> Any:
714714
error = located_error(
715715
raw_error, field_nodes, item_path.as_list()
716716
)
717-
self.handle_field_error(error, item_type)
717+
self.handle_field_error(error, item_type) # noqa: B023
718718
return None
719719

720720
completed_item = await_completed(item, item_path)
@@ -732,7 +732,7 @@ async def await_completed(item: Any, item_path: Path) -> Any:
732732
error = located_error(
733733
raw_error, field_nodes, item_path.as_list()
734734
)
735-
self.handle_field_error(error, item_type)
735+
self.handle_field_error(error, item_type) # noqa: B023
736736
return None
737737

738738
completed_item = await_completed(completed_item, item_path)

src/graphql/execution/values.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ def on_input_value_error(
125125
path: List[Union[str, int]], invalid_value: Any, error: GraphQLError
126126
) -> None:
127127
invalid_str = inspect(invalid_value)
128-
prefix = f"Variable '${var_name}' got invalid value {invalid_str}"
128+
prefix = (
129+
f"Variable '${var_name}' got invalid value {invalid_str}" # noqa: B023
130+
)
129131
if path:
130-
prefix += f" at '{var_name}{print_path_list(path)}'"
132+
prefix += f" at '{var_name}{print_path_list(path)}'" # noqa: B023
131133
on_error(
132134
GraphQLError(
133135
prefix + "; " + error.message,
134-
var_def_node,
136+
var_def_node, # noqa: B023
135137
original_error=error.original_error,
136138
)
137139
)

src/graphql/language/source.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
__all__ = ["Source", "is_source"]
77

8+
DEFAULT_NAME = "GraphQL request"
9+
DEFAULT_SOURCE_LOCATION = SourceLocation(1, 1)
10+
811

912
class Source:
1013
"""A representation of source input to GraphQL."""
@@ -15,8 +18,8 @@ class Source:
1518
def __init__(
1619
self,
1720
body: str,
18-
name: str = "GraphQL request",
19-
location_offset: SourceLocation = SourceLocation(1, 1),
21+
name: str = DEFAULT_NAME,
22+
location_offset: SourceLocation = DEFAULT_SOURCE_LOCATION,
2023
) -> None:
2124
"""Initialize source input.
2225

src/graphql/language/visitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def leave(self, node, key, parent, path, ancestors):
110110
def __init_subclass__(cls) -> None:
111111
"""Verify that all defined handlers are valid."""
112112
super().__init_subclass__()
113-
for attr, val in cls.__dict__.items():
113+
for attr in cls.__dict__:
114114
if attr.startswith("_"):
115115
continue
116116
attr_kind = attr.split("_", 1)

src/graphql/pyutils/cached_property.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CachedProperty:
2222
"""
2323

2424
def __init__(self, func: Callable) -> None:
25-
self.__doc__ = getattr(func, "__doc__")
25+
self.__doc__ = func.__doc__
2626
self.func = func
2727

2828
def __get__(self, obj: object, cls: type) -> Any:

src/graphql/pyutils/identity_func.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
T = TypeVar("T")
1010

11+
DEFAULT_VALUE = cast(Any, Undefined)
1112

12-
def identity_func(x: T = cast(Any, Undefined), *_args: Any) -> T:
13+
14+
def identity_func(x: T = DEFAULT_VALUE, *_args: Any) -> T:
1315
"""Return the first received argument."""
1416
return x

tests/language/test_ast.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,19 @@ def can_hash():
180180
assert node3 != node
181181
assert hash(node3) != hash(node)
182182

183+
# noinspection PyProtectedMember
183184
def caches_are_hashed():
184185
node = SampleTestNode(alpha=1)
185186
assert not hasattr(node, "_hash")
186187
hash1 = hash(node)
187188
assert hasattr(node, "_hash")
188-
assert hash1 == getattr(node, "_hash")
189+
assert hash1 == node._hash
189190
node.alpha = 2
190191
assert not hasattr(node, "_hash")
191192
hash2 = hash(node)
192193
assert hash2 != hash1
193194
assert hasattr(node, "_hash")
194-
assert hash2 == getattr(node, "_hash")
195+
assert hash2 == node._hash
195196

196197
def can_create_weak_reference():
197198
node = SampleTestNode(alpha=1, beta=2)

tests/pyutils/test_simple_pub_sub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ async def iterator_aclose_is_idempotent():
9191
pubsub = SimplePubSub()
9292
iterator = pubsub.get_subscriber()
9393
assert iterator.listening
94-
for n in range(3):
94+
for _n in range(3):
9595
await iterator.aclose()
9696
assert not iterator.listening

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ basepython = python3.9
2020
deps =
2121
flake8>=5,<6
2222
flake8-bandit>=4.1,<6
23+
flake8-bugbear==22.9.23
2324
commands =
2425
flake8 src tests
2526

0 commit comments

Comments
 (0)