Repository: scrapy/scrapy

Issue:
Increase the usage of augmented assignment statements
:eyes: Some source code analysis tools can help to find opportunities for improving software components.
:thought_balloon: I propose to [increase the usage of augmented assignment statements](https://docs.python.org/3/reference/simple_stmts.html#augmented-assignment-statements "Augmented assignment statements") accordingly.

```diff
diff --git a/scrapy/core/downloader/handlers/http11.py b/scrapy/core/downloader/handlers/http11.py
index 8a91d4c5..38935667 100644
--- a/scrapy/core/downloader/handlers/http11.py
+++ b/scrapy/core/downloader/handlers/http11.py
@@ -213,7 +213,7 @@ class TunnelingAgent(Agent):
         # proxy host and port are required for HTTP pool `key`
         # otherwise, same remote host connection request could reuse
         # a cached tunneled connection to a different proxy
-        key = key + self._proxyConf
+        key += self._proxyConf
         return super()._requestWithEndpoint(
             key=key,
             endpoint=endpoint,
diff --git a/scrapy/core/http2/stream.py b/scrapy/core/http2/stream.py
index c2a4b702..5c393c02 100644
--- a/scrapy/core/http2/stream.py
+++ b/scrapy/core/http2/stream.py
@@ -285,8 +285,8 @@ class Stream:
 
             self._protocol.conn.send_data(self.stream_id, data_chunk, end_stream=False)
 
-            bytes_to_send_size = bytes_to_send_size - chunk_size
-            self.metadata['remaining_content_length'] = self.metadata['remaining_content_length'] - chunk_size
+            bytes_to_send_size -= chunk_size
+            self.metadata['remaining_content_length'] -= chunk_size
 
         self.metadata['remaining_content_length'] = max(0, self.metadata['remaining_content_length'])
 
diff --git a/tests/test_request_left.py b/tests/test_request_left.py
index 373b2e49..4d448388 100644
--- a/tests/test_request_left.py
+++ b/tests/test_request_left.py
@@ -22,7 +22,7 @@ class SignalCatcherSpider(Spider):
         return spider
 
     def on_request_left(self, request, spider):
-        self.caught_times = self.caught_times + 1
+        self.caught_times += 1
 
 
 class TestCatching(TestCase):
```
added augmented assignment statements
Found one place where augmented assignment could have been used, with regards to issue #5314 


Discussion:
Can you please make a pull request with the changes you propose?
Doesn't that issue list 3 more cases?


# [Codecov](https://codecov.io/gh/scrapy/scrapy/pull/5321?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scrapy) Report
> Merging [#5321](https://codecov.io/gh/scrapy/scrapy/pull/5321?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scrapy) (ff9503f) into [master](https://codecov.io/gh/scrapy/scrapy/commit/28eba610e22c0d2a42e830b4e64746edf44598f9?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scrapy) (28eba61) will **not change** coverage.
> The diff coverage is `0.00%`.


```diff
@@           Coverage Diff           @@
##           master    #5321   +/-   ##
=======================================
  Coverage   88.59%   88.59%           
=======================================
  Files         163      163           
  Lines       10616    10616           
  Branches     1558     1558           
=======================================
  Hits         9405     9405           
  Misses        936      936           
  Partials      275      275           
```

| [Impacted Files](https://codecov.io/gh/scrapy/scrapy/pull/5321?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scrapy) | Coverage Δ | |
|---|---|---|
| [scrapy/commands/genspider.py](https://codecov.io/gh/scrapy/scrapy/pull/5321/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scrapy#diff-c2NyYXB5L2NvbW1hbmRzL2dlbnNwaWRlci5weQ==) | `87.85% <0.00%> (ø)` | |

There is also a flake8 error for this change.

Resolving patch:
diff --git a/scrapy/core/downloader/handlers/http11.py b/scrapy/core/downloader/handlers/http11.py
--- a/scrapy/core/downloader/handlers/http11.py
+++ b/scrapy/core/downloader/handlers/http11.py
@@ -213,7 +213,7 @@ def _requestWithEndpoint(self, key, endpoint, method, parsedURI, headers, bodyPr
         # proxy host and port are required for HTTP pool `key`
         # otherwise, same remote host connection request could reuse
         # a cached tunneled connection to a different proxy
-        key = key + self._proxyConf
+        key += self._proxyConf
         return super()._requestWithEndpoint(
             key=key,
             endpoint=endpoint,
diff --git a/scrapy/core/http2/stream.py b/scrapy/core/http2/stream.py
--- a/scrapy/core/http2/stream.py
+++ b/scrapy/core/http2/stream.py
@@ -285,8 +285,8 @@ def send_data(self) -> None:
 
             self._protocol.conn.send_data(self.stream_id, data_chunk, end_stream=False)
 
-            bytes_to_send_size = bytes_to_send_size - chunk_size
-            self.metadata['remaining_content_length'] = self.metadata['remaining_content_length'] - chunk_size
+            bytes_to_send_size -= chunk_size
+            self.metadata['remaining_content_length'] -= chunk_size
 
         self.metadata['remaining_content_length'] = max(0, self.metadata['remaining_content_length'])
 


Test patch:
diff --git a/tests/test_request_left.py b/tests/test_request_left.py
--- a/tests/test_request_left.py
+++ b/tests/test_request_left.py
@@ -22,7 +22,7 @@ def from_crawler(cls, crawler, *args, **kwargs):
         return spider
 
     def on_request_left(self, request, spider):
-        self.caught_times = self.caught_times + 1
+        self.caught_times += 1
 
 
 class TestCatching(TestCase):