Skip to content

Commit

Permalink
Add flake8-no-implicit-concat (#7731)
Browse files Browse the repository at this point in the history
(cherry picked from commit 1d170d3)
  • Loading branch information
booniepepper committed Sep 3, 2024
1 parent a3fa8d8 commit ff878e0
Show file tree
Hide file tree
Showing 35 changed files with 118 additions and 130 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ repos:
- id: flake8
additional_dependencies:
- flake8-docstrings==1.6.0
- flake8-no-implicit-concat==0.3.4
- flake8-requirements==1.7.8
exclude: "^docs/"
- repo: https://github.com/Lucas-C/pre-commit-hooks-markup
Expand Down
1 change: 1 addition & 0 deletions CHANGES/7731.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added flake8 settings to avoid some forms of implicit concatenation. -- by :user:`booniepepper`.
6 changes: 3 additions & 3 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,15 @@ def __init__(
self._timeout = DEFAULT_TIMEOUT
if read_timeout is not sentinel:
warnings.warn(
"read_timeout is deprecated, " "use timeout argument instead",
"read_timeout is deprecated, use timeout argument instead",
DeprecationWarning,
stacklevel=2,
)
self._timeout = attr.evolve(self._timeout, total=read_timeout)
if conn_timeout is not None:
self._timeout = attr.evolve(self._timeout, connect=conn_timeout)
warnings.warn(
"conn_timeout is deprecated, " "use timeout argument instead",
"conn_timeout is deprecated, use timeout argument instead",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -1255,7 +1255,7 @@ def requote_redirect_url(self) -> bool:
def requote_redirect_url(self, val: bool) -> None:
"""Do URL requoting on redirection handling."""
warnings.warn(
"session.requote_redirect_url modification " "is deprecated #2778",
"session.requote_redirect_url modification is deprecated #2778",
DeprecationWarning,
stacklevel=2,
)
Expand Down
12 changes: 5 additions & 7 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ def __init__(self, fingerprint: bytes) -> None:
if not hashfunc:
raise ValueError("fingerprint has invalid length")
elif hashfunc is md5 or hashfunc is sha1:
raise ValueError(
"md5 and sha1 are insecure and " "not supported. Use sha256."
)
raise ValueError("md5 and sha1 are insecure and not supported. Use sha256.")
self._hashfunc = hashfunc
self._fingerprint = fingerprint

Expand Down Expand Up @@ -190,7 +188,7 @@ def _merge_ssl_params(
ssl = ssl_context
if fingerprint is not None:
warnings.warn(
"fingerprint is deprecated, " "use ssl=Fingerprint(fingerprint) instead",
"fingerprint is deprecated, use ssl=Fingerprint(fingerprint) instead",
DeprecationWarning,
stacklevel=3,
)
Expand Down Expand Up @@ -505,7 +503,7 @@ def update_content_encoding(self, data: Any) -> None:
if enc:
if self.compress:
raise ValueError(
"compress can not be set " "if Content-Encoding header is set"
"compress can not be set if Content-Encoding header is set"
)
elif self.compress:
if not isinstance(self.compress, str):
Expand All @@ -527,7 +525,7 @@ def update_transfer_encoding(self) -> None:
elif self.chunked:
if hdrs.CONTENT_LENGTH in self.headers:
raise ValueError(
"chunked can not be set " "if Content-Length header is set"
"chunked can not be set if Content-Length header is set"
)

self.headers[hdrs.TRANSFER_ENCODING] = "chunked"
Expand Down Expand Up @@ -1205,7 +1203,7 @@ async def json(
self.history,
status=self.status,
message=(
"Attempt to decode JSON with " "unexpected mimetype: %s" % ctype
"Attempt to decode JSON with unexpected mimetype: %s" % ctype
),
headers=self.headers,
)
Expand Down
6 changes: 3 additions & 3 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def __init__(
if force_close:
if keepalive_timeout is not None and keepalive_timeout is not sentinel:
raise ValueError(
"keepalive_timeout cannot " "be set if force_close is True"
"keepalive_timeout cannot be set if force_close is True"
)
else:
if keepalive_timeout is sentinel:
Expand Down Expand Up @@ -853,7 +853,7 @@ def clear_dns_cache(
if host is not None and port is not None:
self._cached_hosts.remove((host, port))
elif host is not None or port is not None:
raise ValueError("either both host and port " "or none of them are allowed")
raise ValueError("either both host and port or none of them are allowed")
else:
self._cached_hosts.clear()

Expand Down Expand Up @@ -1575,7 +1575,7 @@ def __init__(
self._loop, asyncio.ProactorEventLoop # type: ignore[attr-defined]
):
raise RuntimeError(
"Named Pipes only available in proactor " "loop under windows"
"Named Pipes only available in proactor loop under windows"
)
self._path = path

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CookieJar(AbstractCookieJar):
DATE_DAY_OF_MONTH_RE = re.compile(r"(\d{1,2})")

DATE_MONTH_RE = re.compile(
"(jan)|(feb)|(mar)|(apr)|(may)|(jun)|(jul)|" "(aug)|(sep)|(oct)|(nov)|(dec)",
"(jan)|(feb)|(mar)|(apr)|(may)|(jun)|(jul)|(aug)|(sep)|(oct)|(nov)|(dec)",
re.I,
)

Expand Down
8 changes: 3 additions & 5 deletions aiohttp/formdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def add_field(

type_options: MultiDict[str] = MultiDict({"name": name})
if filename is not None and not isinstance(filename, str):
raise TypeError(
"filename must be an instance of str. " "Got: %s" % filename
)
raise TypeError("filename must be an instance of str. Got: %s" % filename)
if filename is None and isinstance(value, io.IOBase):
filename = guess_filename(value, name)
if filename is not None:
Expand All @@ -77,7 +75,7 @@ def add_field(
if content_type is not None:
if not isinstance(content_type, str):
raise TypeError(
"content_type must be an instance of str. " "Got: %s" % content_type
"content_type must be an instance of str. Got: %s" % content_type
)
headers[hdrs.CONTENT_TYPE] = content_type
self._is_multipart = True
Expand Down Expand Up @@ -131,7 +129,7 @@ def _gen_form_urlencoded(self) -> payload.BytesPayload:
if charset == "utf-8":
content_type = "application/x-www-form-urlencoded"
else:
content_type = "application/x-www-form-urlencoded; " "charset=%s" % charset
content_type = "application/x-www-form-urlencoded; charset=%s" % charset

return payload.BytesPayload(
urlencode(data, doseq=True, encoding=charset).encode(),
Expand Down
10 changes: 3 additions & 7 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,16 +393,14 @@ def content_disposition_header(
params is a dict with disposition params.
"""
if not disptype or not (TOKEN > set(disptype)):
raise ValueError("bad content disposition type {!r}" "".format(disptype))
raise ValueError(f"bad content disposition type {disptype!r}")

value = disptype
if params:
lparams = []
for key, val in params.items():
if not key or not (TOKEN > set(key)):
raise ValueError(
"bad content disposition parameter" " {!r}={!r}".format(key, val)
)
raise ValueError(f"bad content disposition parameter {key!r}={val!r}")
if quote_fields:
if key.lower() == "filename":
qval = quote(val, "", encoding=_charset)
Expand Down Expand Up @@ -690,9 +688,7 @@ def __enter__(self) -> BaseTimerContext:
task = asyncio.current_task(loop=self._loop)

if task is None:
raise RuntimeError(
"Timeout context manager should be used " "inside a task"
)
raise RuntimeError("Timeout context manager should be used inside a task")

if self._cancelled:
raise asyncio.TimeoutError from None
Expand Down
4 changes: 2 additions & 2 deletions aiohttp/http_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def ws_ext_gen(
# compress wbit 8 does not support in zlib
if compress < 9 or compress > 15:
raise ValueError(
"Compress wbits must between 9 and 15, " "zlib does not support wbits=8"
"Compress wbits must between 9 and 15, zlib does not support wbits=8"
)
enabledext = ["permessage-deflate"]
if not isserver:
Expand Down Expand Up @@ -512,7 +512,7 @@ def parse_frame(
if opcode > 0x7 and length > 125:
raise WebSocketError(
WSCloseCode.PROTOCOL_ERROR,
"Control frame payload cannot be " "larger than 125 bytes",
"Control frame payload cannot be larger than 125 bytes",
)

# Set compress status if last package is FIN
Expand Down
4 changes: 1 addition & 3 deletions aiohttp/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,7 @@ def _decode_content_transfer(self, data: bytes) -> bytes:
elif encoding in ("binary", "8bit", "7bit"):
return data
else:
raise RuntimeError(
"unknown content transfer encoding: {}" "".format(encoding)
)
raise RuntimeError(f"unknown content transfer encoding: {encoding}")

def get_charset(self, default: str) -> str:
"""Returns charset parameter from Content-Type header or default."""
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def begin_http_chunk_receiving(self) -> None:
if self._http_chunk_splits is None:
if self.total_bytes:
raise RuntimeError(
"Called begin_http_chunk_receiving when" "some data was already fed"
"Called begin_http_chunk_receiving when some data was already fed"
)
self._http_chunk_splits = []

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def __init__(
) -> None:
if not isinstance(server, BaseTestServer):
raise TypeError(
"server must be TestServer " "instance, found type: %r" % type(server)
"server must be TestServer instance, found type: %r" % type(server)
)
self._server = server
self._loop = loop
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def main(argv: List[str]) -> None:
# Compatibility logic
if args.path is not None and not hasattr(socket, "AF_UNIX"):
arg_parser.error(
"file system paths not supported by your operating" " environment"
"file system paths not supported by your operating environment"
)

logging.basicConfig(level=logging.DEBUG)
Expand Down
6 changes: 3 additions & 3 deletions aiohttp/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def __getitem__(self, key: Union[str, AppKey[_T]]) -> Any:
def _check_frozen(self) -> None:
if self._frozen:
warnings.warn(
"Changing state of started or joined " "application is deprecated",
"Changing state of started or joined application is deprecated",
DeprecationWarning,
stacklevel=3,
)
Expand Down Expand Up @@ -433,7 +433,7 @@ def make_handler(
) -> Server:

warnings.warn(
"Application.make_handler(...) is deprecated, " "use AppRunner API instead",
"Application.make_handler(...) is deprecated, use AppRunner API instead",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -492,7 +492,7 @@ def _prepare_middleware(self) -> Iterator[Tuple[Middleware, bool]]:
yield m, True
else:
warnings.warn(
'old-style middleware "{!r}" deprecated, ' "see #2252".format(m),
f'old-style middleware "{m!r}" deprecated, see #2252',
DeprecationWarning,
stacklevel=2,
)
Expand Down
4 changes: 2 additions & 2 deletions aiohttp/web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def clone(
will reuse the one from the current request object.
"""
if self._read_bytes:
raise RuntimeError("Cannot clone request " "after reading its content")
raise RuntimeError("Cannot clone request after reading its content")

dct: Dict[str, Any] = {}
if method is not sentinel:
Expand Down Expand Up @@ -773,7 +773,7 @@ async def post(self) -> "MultiDictProxy[Union[str, bytes, FileField]]":
)
else:
raise ValueError(
"To decode nested multipart you need " "to use custom reader",
"To decode nested multipart you need to use custom reader",
)

field = await multipart.next()
Expand Down
18 changes: 9 additions & 9 deletions aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ def set_status(
status: int,
reason: Optional[str] = None,
) -> None:
assert not self.prepared, (
"Cannot change the response status code after " "the headers have been sent"
)
assert (
not self.prepared
), "Cannot change the response status code after the headers have been sent"
self._status = int(status)
if reason is None:
try:
Expand Down Expand Up @@ -168,7 +168,7 @@ def enable_chunked_encoding(self, chunk_size: Optional[int] = None) -> None:

if hdrs.CONTENT_LENGTH in self._headers:
raise RuntimeError(
"You can't enable chunked encoding when " "a content length is set"
"You can't enable chunked encoding when a content length is set"
)
if chunk_size is not None:
warnings.warn("Chunk size is deprecated #1615", DeprecationWarning)
Expand All @@ -184,9 +184,9 @@ def enable_compression(
"Using boolean for force is deprecated #3318", DeprecationWarning
)
elif force is not None:
assert isinstance(force, ContentCoding), (
"force should one of " "None, bool or " "ContentEncoding"
)
assert isinstance(
force, ContentCoding
), "force should one of None, bool or ContentEncoding"

self._compression = True
self._compression_force = force
Expand Down Expand Up @@ -289,7 +289,7 @@ def content_length(self, value: Optional[int]) -> None:
value = int(value)
if self._chunked:
raise RuntimeError(
"You can't set content length when " "chunked encoding is enable"
"You can't set content length when chunked encoding is enable"
)
self._headers[hdrs.CONTENT_LENGTH] = str(value)
else:
Expand Down Expand Up @@ -611,7 +611,7 @@ def __init__(
real_headers = headers # = cast('CIMultiDict[str]', headers)

if content_type is not None and "charset" in content_type:
raise ValueError("charset must not be in content_type " "argument")
raise ValueError("charset must not be in content_type argument")

if text is not None:
if hdrs.CONTENT_TYPE in real_headers:
Expand Down
4 changes: 2 additions & 2 deletions aiohttp/web_routedef.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __repr__(self) -> str:
info = []
for name, value in sorted(self.kwargs.items()):
info.append(f", {name}={value!r}")
return "<RouteDef {method} {path} -> {handler.__name__!r}" "{info}>".format(
return "<RouteDef {method} {path} -> {handler.__name__!r}{info}>".format(
method=self.method, path=self.path, handler=self.handler, info="".join(info)
)

Expand All @@ -90,7 +90,7 @@ def __repr__(self) -> str:
info = []
for name, value in sorted(self.kwargs.items()):
info.append(f", {name}={value!r}")
return "<StaticDef {prefix} -> {path}" "{info}>".format(
return "<StaticDef {prefix} -> {path}{info}>".format(
prefix=self.prefix, path=self.path, info="".join(info)
)

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def __init__(
loop, asyncio.ProactorEventLoop # type: ignore[attr-defined]
):
raise RuntimeError(
"Named Pipes only available in proactor" "loop under windows"
"Named Pipes only available in proactor loop under windows"
)
super().__init__(runner, shutdown_timeout=shutdown_timeout)
self._path = path
Expand Down
8 changes: 4 additions & 4 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ def __init__(
pass
elif inspect.isgeneratorfunction(handler):
warnings.warn(
"Bare generators are deprecated, " "use @coroutine wrapper",
"Bare generators are deprecated, use @coroutine wrapper",
DeprecationWarning,
)
elif isinstance(handler, type) and issubclass(handler, AbstractView):
pass
else:
warnings.warn(
"Bare functions are deprecated, " "use async ones", DeprecationWarning
"Bare functions are deprecated, use async ones", DeprecationWarning
)

@wraps(handler)
Expand Down Expand Up @@ -777,7 +777,7 @@ def _add_prefix_to_resources(self, prefix: str) -> None:
router.index_resource(resource)

def url_for(self, *args: str, **kwargs: str) -> URL:
raise RuntimeError(".url_for() is not supported " "by sub-application root")
raise RuntimeError(".url_for() is not supported by sub-application root")

def get_info(self) -> _InfoDict:
return {"app": self._app, "prefix": self._prefix}
Expand Down Expand Up @@ -900,7 +900,7 @@ async def resolve(self, request: Request) -> _Resolve:
return match_info, methods

def __repr__(self) -> str:
return "<MatchedSubAppResource -> {app!r}>" "".format(app=self._app)
return f"<MatchedSubAppResource -> {self._app!r}>"


class ResourceRoute(AbstractRoute):
Expand Down
Loading

0 comments on commit ff878e0

Please sign in to comment.