internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: jschneier/django-storages

Issue:
URL parameters are ignored with custom domain in S3Boto3Storage
If custom domain is configured for S3Boto3Storage, `parameters` passed to `url` method are ignored.



Discussion:

Resolving patch:
diff --git a/storages/backends/s3boto3.py b/storages/backends/s3boto3.py
--- a/storages/backends/s3boto3.py
+++ b/storages/backends/s3boto3.py
@@ -7,7 +7,7 @@
 from datetime import datetime, timedelta
 from gzip import GzipFile
 from tempfile import SpooledTemporaryFile
-from urllib.parse import parse_qsl, urlsplit
+from urllib.parse import parse_qsl, urlencode, urlsplit
 
 from django.contrib.staticfiles.storage import ManifestFilesMixin
 from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation
@@ -558,12 +558,17 @@ def _strip_signing_parameters(self, url):
     def url(self, name, parameters=None, expire=None, http_method=None):
         # Preserve the trailing slash after normalizing the path.
         name = self._normalize_name(self._clean_name(name))
+        params = parameters.copy() if parameters else {}
         if expire is None:
             expire = self.querystring_expire
 
         if self.custom_domain:
-            url = "{}//{}/{}".format(
-                self.url_protocol, self.custom_domain, filepath_to_uri(name))
+            url = "{}//{}/{}{}".format(
+                self.url_protocol,
+                self.custom_domain,
+                filepath_to_uri(name),
+                "?{}".format(urlencode(params)) if params else "",
+            )
 
             if self.querystring_auth and self.cloudfront_signer:
                 expiration = datetime.utcnow() + timedelta(seconds=expire)
@@ -572,7 +577,6 @@ def url(self, name, parameters=None, expire=None, http_method=None):
 
             return url
 
-        params = parameters.copy() if parameters else {}
         params['Bucket'] = self.bucket.name
         params['Key'] = name
         url = self.bucket.meta.client.generate_presigned_url('get_object', Params=params,


Test patch:
diff --git a/tests/test_s3boto3.py b/tests/test_s3boto3.py
--- a/tests/test_s3boto3.py
+++ b/tests/test_s3boto3.py
@@ -625,6 +625,14 @@ def test_special_characters(self):
         parsed_url = urlparse(url)
         self.assertEqual(parsed_url.path, "/%C3%A3l%C3%B6h%C3%A2.jpg")
 
+    def test_custom_domain_parameters(self):
+        self.storage.custom_domain = "mock.cloudfront.net"
+        filename = "filename.mp4"
+        url = self.storage.url(filename, parameters={"version": 10})
+        parsed_url = urlparse(url)
+        self.assertEqual(parsed_url.path, "/filename.mp4")
+        self.assertEqual(parsed_url.query, "version=10")
+
     def test_strip_signing_parameters(self):
         expected = 'http://bucket.s3-aws-region.amazonaws.com/foo/bar'
         self.assertEqual(self.storage._strip_signing_parameters(
Repository: jschneier/django-storages

Issue:
AzureStorage get_modified_time  'ContainerClient' object has no attribute 'get_blob_properties' 
I suspect this is a bug from a change in Azure's python client. I can't say I'm an expert but it looks like [this](https://github.com/jschneier/django-storages/blob/master/storages/backends/azure_storage.py#L337) line needs be changed from.

```python
        properties = self.client.get_blob_properties(
            self._get_valid_path(name),
            timeout=self.timeout)
```

to

```python
        properties = self.client.get_blob_client(self._get_valid_path(name)).get_blob_properties(
            timeout=self.timeout)
```

Reproduction steps

```
from storages.backends.azure_storage import AzureStorage
storage = AzureStorage()
storage.get_modified_time("your-file")

AttributeError: 'ContainerClient' object has no attribute 'get_blob_properties'
```

I could submit a pull request if desired. It might be good for another set of eyes to confirm this is the right approach to fix.


Discussion:

Resolving patch:
diff --git a/storages/backends/azure_storage.py b/storages/backends/azure_storage.py
--- a/storages/backends/azure_storage.py
+++ b/storages/backends/azure_storage.py
@@ -334,9 +334,8 @@ def get_modified_time(self, name):
         Returns an (aware) datetime object containing the last modified time if
         USE_TZ is True, otherwise returns a naive datetime in the local timezone.
         """
-        properties = self.client.get_blob_properties(
-            self._get_valid_path(name),
-            timeout=self.timeout)
+        blob_client = self.client.get_blob_client(self._get_valid_path(name))
+        properties = blob_client.get_blob_properties(timeout=self.timeout)
         if not setting('USE_TZ', False):
             return timezone.make_naive(properties.last_modified)
 


Test patch:
diff --git a/tests/test_azure.py b/tests/test_azure.py
--- a/tests/test_azure.py
+++ b/tests/test_azure.py
@@ -391,7 +391,9 @@ def test_last_modified_of_file(self):
         props = BlobProperties()
         accepted_time = datetime.datetime(2017, 5, 11, 8, 52, 4)
         props.last_modified = accepted_time
-        self.storage._client.get_blob_properties.return_value = props
+        client_mock = mock.MagicMock()
+        client_mock.get_blob_properties.return_value = props
+        self.storage._client.get_blob_client.return_value = client_mock
         time = self.storage.modified_time("name")
         self.assertEqual(accepted_time, time)
Repository: jschneier/django-storages

Issue:
ClientError (404) in S3Boto3Storage when calling write()
When `S3Boto3Storage` has gzip enabled, the following code generates an error when writing to an S3 key that does not already exist:

```
with my_storage.open('new_key.txt', 'wb') as f:
    f.write(b'hello')
```

The stack trace indicates an error is happening for `S3Boto3StorageFile._get_file()`:

```
            ...
            if self._storage.gzip and self.obj.content_encoding == 'gzip':
                self._file = GzipFile(mode=self._mode, fileobj=self._file, mtime=0.0)
```

Basically, by checking `self.obj.content_encoding`, Boto3 is performing a `HeadObject()` operation on the key, even though it doesn't exist yet, which is generating the 404.

Should the relevant code instead use the content-encoding guessed from the newly created file? That's what the `S3Boto3Storage.save()` method does and it doesn't have this issue.



Discussion:

Resolving patch:
diff --git a/storages/backends/s3boto3.py b/storages/backends/s3boto3.py
--- a/storages/backends/s3boto3.py
+++ b/storages/backends/s3boto3.py
@@ -148,8 +148,8 @@ def _get_file(self):
                 self._is_dirty = False
                 self.obj.download_fileobj(self._file, Config=self._storage.transfer_config)
                 self._file.seek(0)
-            if self._storage.gzip and self.obj.content_encoding == 'gzip':
-                self._file = self._decompress_file(mode=self._mode, file=self._file)
+                if self._storage.gzip and self.obj.content_encoding == 'gzip':
+                    self._file = self._decompress_file(mode=self._mode, file=self._file)
         return self._file
 
     def _set_file(self, value):


Test patch:
Repository: jschneier/django-storages

Issue:
Cleanup after aborted connection can throw error
In the following code:

https://github.com/jschneier/django-storages/blob/a87dea670dc7a6a27cc2cb83f4c90b0129e9998b/storages/backends/s3boto3.py#L172-L176

If the connection is aborted after `self._is_dirty` is set to `True`, but before `self._multipart` is assigned, then `self._multipart` will remain `None`. Then during cleanup:

https://github.com/jschneier/django-storages/blob/a87dea670dc7a6a27cc2cb83f4c90b0129e9998b/storages/backends/s3boto3.py#L231-L234

we try to call `self._multipart.complete`, which will throw 

```
'NoneType' object has no attribute 'complete'
```

This path in the cleanup should have some check for `self._multipart is not None`. I would file a PR but I am not sure of the right logic for this case and what exactly should be guarded.


Discussion:
I don't really get this one because `_flush_write_buffer` also refers to `self._multipart` before the `complete` method, do you have any ideas?
I guess `buffer_file_size` is zero at that point, okay.

Resolving patch:
diff --git a/storages/backends/s3.py b/storages/backends/s3.py
--- a/storages/backends/s3.py
+++ b/storages/backends/s3.py
@@ -251,8 +251,9 @@ def _create_empty_on_close(self):
 
     def close(self):
         if self._is_dirty:
-            self._flush_write_buffer()
-            self._multipart.complete(MultipartUpload={"Parts": self._parts})
+            if self._multipart is not None:
+                self._flush_write_buffer()
+                self._multipart.complete(MultipartUpload={"Parts": self._parts})
         else:
             if self._multipart is not None:
                 self._multipart.abort()


Test patch:
Repository: jschneier/django-storages

Issue:
Not setting bucket name causes confusing error
I'm learning django-storages by starting with zero configuration and adding what's needed one bit at a time to see how it alters behavior.

When I configure credentials but not a default bucket, then make a request to the server, it fails with a `ValueError`.

This stops happening as soon as I either set `settings.AWS_STORAGE_BUCKET_NAME` or set `bucket_name` in my storage subclass.

It may be worth adding an explicit check for required settings in order to provide a relevant error message informing the user of where they're falling short.

Traceback:  https://gist.github.com/odigity/d73cf6338a5bb7908399cbe58d84572d


Discussion:

Resolving patch:
diff --git a/storages/backends/s3.py b/storages/backends/s3.py
--- a/storages/backends/s3.py
+++ b/storages/backends/s3.py
@@ -288,6 +288,8 @@ def __init__(self, **settings):
         super().__init__(**settings)
 
         check_location(self)
+        if not self.bucket_name:
+            raise ImproperlyConfigured("Setting a bucket name is required.")
 
         if (self.access_key or self.secret_key) and self.session_profile:
             raise ImproperlyConfigured(


Test patch:
diff --git a/tests/test_s3.py b/tests/test_s3.py
--- a/tests/test_s3.py
+++ b/tests/test_s3.py
@@ -956,6 +956,11 @@ def test_auth_config(self):
                 access_key="foo", secret_key="boo", session_profile="moo"
             )
 
+    def test_bucket_name_required(self):
+        with override_settings(AWS_STORAGE_BUCKET_NAME=None):
+            with self.assertRaises(ImproperlyConfigured):
+                s3.S3Storage()
+
 
 class S3StaticStorageTests(TestCase):
     def setUp(self):
Repository: open-mmlab/mmpose

Issue:
Pylint: C0325
```bash
mmpose/core/evaluation/mesh_eval.py:27:0: C0325: Unnecessary parens after 'assert' keyword (superfluous-parens)
mmpose/datasets/datasets/mesh/mesh_h36m_dataset.py:94:0: C0325: Unnecessary parens after 'assert' keyword (superfluous-parens)
```


Discussion:

Resolving patch:
diff --git a/mmpose/core/evaluation/mesh_eval.py b/mmpose/core/evaluation/mesh_eval.py
--- a/mmpose/core/evaluation/mesh_eval.py
+++ b/mmpose/core/evaluation/mesh_eval.py
@@ -24,8 +24,8 @@ def compute_similarity_transform(source_points, target_points):
         source_points_hat (np.ndarray([N, 3])): Transformed source point set.
     """
 
-    assert (target_points.shape[0] == source_points.shape[0])
-    assert (target_points.shape[1] == 3 and source_points.shape[1] == 3)
+    assert target_points.shape[0] == source_points.shape[0]
+    assert target_points.shape[1] == 3 and source_points.shape[1] == 3
 
     source_points = source_points.T
     target_points = target_points.T
diff --git a/mmpose/datasets/datasets/mesh/mesh_h36m_dataset.py b/mmpose/datasets/datasets/mesh/mesh_h36m_dataset.py
--- a/mmpose/datasets/datasets/mesh/mesh_h36m_dataset.py
+++ b/mmpose/datasets/datasets/mesh/mesh_h36m_dataset.py
@@ -91,7 +91,7 @@ def evaluate_kernel(self, pred_joints_3d, joints_3d, joints_3d_visible):
         """Evaluate one example."""
         # Only 14 lsp joints are used for evaluation
         joint_mapper = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 18]
-        assert (joints_3d_visible[joint_mapper].min() > 0)
+        assert joints_3d_visible[joint_mapper].min() > 0
 
         pred_joints_3d = np.array(pred_joints_3d)
         pred_joints_3d = pred_joints_3d[joint_mapper, :]


Test patch:
Repository: open-mmlab/mmpose

Issue:
Pylint: W0707
```bash
mmpose/utils/hooks.py:37:20: W0707: Consider explicitly re-raising using the 'from' keyword (raise-missing-from)
```


Discussion:

Resolving patch:
diff --git a/mmpose/utils/hooks.py b/mmpose/utils/hooks.py
--- a/mmpose/utils/hooks.py
+++ b/mmpose/utils/hooks.py
@@ -33,8 +33,9 @@ def hook(model, input, output):
                 try:
                     layer = rgetattr(module, name)
                     h = layer.register_forward_hook(hook_wrapper(name))
-                except AttributeError:
-                    raise AttributeError(f'Module {name} not found')
+                except ModuleNotFoundError as module_not_found:
+                    raise ModuleNotFoundError(
+                        f'Module {name} not found') from module_not_found
                 self.handles.append(h)
 
     def remove(self):


Test patch:
Repository: open-mmlab/mmpose

Issue:
Pylint: R1716
```bash
mmpose/datasets/pipelines/bottom_up_transform.py:168:20: R1716: Simplify chained comparison between the operands (chained-comparison)
mmpose/models/backbones/regnet.py:135:15: R1716: Simplify chained comparison between the operands (chained-comparison)
mmpose/models/backbones/resnet.py:503:15: R1716: Simplify chained comparison between the operands (chained-comparison)
```


Discussion:

Resolving patch:
diff --git a/mmpose/datasets/pipelines/bottom_up_transform.py b/mmpose/datasets/pipelines/bottom_up_transform.py
--- a/mmpose/datasets/pipelines/bottom_up_transform.py
+++ b/mmpose/datasets/pipelines/bottom_up_transform.py
@@ -165,8 +165,8 @@ def __call__(self, joints):
             tot = 0
             for idx, pt in enumerate(joints[i]):
                 x, y = int(pt[0]), int(pt[1])
-                if (pt[2] > 0 and x >= 0 and y >= 0 and x < self.output_res
-                        and y < self.output_res):
+                if (pt[2] > 0 and 0 <= y < self.output_res
+                        and 0 <= x < self.output_res):
                     if self.tag_per_joint:
                         visible_kpts[i][tot] = \
                             (idx * output_res**2 + y * output_res + x, 1)
diff --git a/mmpose/models/backbones/regnet.py b/mmpose/models/backbones/regnet.py
--- a/mmpose/models/backbones/regnet.py
+++ b/mmpose/models/backbones/regnet.py
@@ -132,7 +132,7 @@ def __init__(self,
         self.stem_channels = stem_channels
         self.base_channels = base_channels
         self.num_stages = num_stages
-        assert num_stages >= 1 and num_stages <= 4
+        assert 1 <= num_stages <= 4
         self.strides = strides
         self.dilations = dilations
         assert len(strides) == len(dilations) == num_stages
diff --git a/mmpose/models/backbones/resnet.py b/mmpose/models/backbones/resnet.py
--- a/mmpose/models/backbones/resnet.py
+++ b/mmpose/models/backbones/resnet.py
@@ -500,7 +500,7 @@ def __init__(self,
         self.stem_channels = stem_channels
         self.base_channels = base_channels
         self.num_stages = num_stages
-        assert num_stages >= 1 and num_stages <= 4
+        assert 1 <= num_stages <= 4
         self.strides = strides
         self.dilations = dilations
         assert len(strides) == len(dilations) == num_stages


Test patch:
Repository: open-mmlab/mmpose

Issue:
Pylint: R1719
```bash
mmpose/models/backbones/shufflenet_v1.py:238:26: R1719: The if expression can be replaced with 'test' (simplifiable-if-expression)
```


Discussion:

Resolving patch:
diff --git a/mmpose/models/backbones/shufflenet_v1.py b/mmpose/models/backbones/shufflenet_v1.py
--- a/mmpose/models/backbones/shufflenet_v1.py
+++ b/mmpose/models/backbones/shufflenet_v1.py
@@ -235,7 +235,7 @@ def __init__(self,
 
         self.layers = nn.ModuleList()
         for i, num_blocks in enumerate(self.stage_blocks):
-            first_block = True if i == 0 else False
+            first_block = (i == 0)
             layer = self.make_layer(channels[i], num_blocks, first_block)
             self.layers.append(layer)
 


Test patch:
Repository: open-mmlab/mmpose

Issue:
Pylint: R1710
```bash
mmpose/apis/test.py:142:0: R1710: Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements)
mmpose/datasets/datasets/mesh/mesh_mix_dataset.py:38:4: R1710: Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements)
```


Discussion:

Resolving patch:
diff --git a/mmpose/datasets/datasets/mesh/mesh_mix_dataset.py b/mmpose/datasets/datasets/mesh/mesh_mix_dataset.py
--- a/mmpose/datasets/datasets/mesh/mesh_mix_dataset.py
+++ b/mmpose/datasets/datasets/mesh/mesh_mix_dataset.py
@@ -45,3 +45,4 @@ def __getitem__(self, idx):
                     self.datasets[i]) / self.length
                 index_new = int(np.round(index_new)) % (len(self.datasets[i]))
                 return self.datasets[i][index_new]
+        return None


Test patch:
diff --git a/mmpose/apis/test.py b/mmpose/apis/test.py
--- a/mmpose/apis/test.py
+++ b/mmpose/apis/test.py
@@ -183,3 +183,4 @@ def collect_results_gpu(result_part, size):
         # the dataloader may pad some samples
         ordered_results = ordered_results[:size]
         return ordered_results
+    return None
Repository: open-mmlab/mmpose

Issue:
Pylint: R1714
```bash
mmpose/apis/inference.py:170:7: R1714: Consider merging these comparisons with "in" to "dataset in ('TopDownCocoDataset', 'TopDownOCHumanDataset')" (consider-using-in)
mmpose/apis/inference.py:194:10: R1714: Consider merging these comparisons with "in" to "dataset in ('OneHand10KDataset', 'FreiHandDataset', 'PanopticDataset', 'InterHand2DDataset')" (consider-using-in)
mmpose/apis/inference.py:433:7: R1714: Consider merging these comparisons with "in" to "dataset in ('TopDownCocoDataset', 'BottomUpCocoDataset', 'TopDownOCHumanDataset')" (consider-using-in)
mmpose/apis/inference.py:502:10: R1714: Consider merging these comparisons with "in" to "dataset in ('OneHand10KDataset', 'FreiHandDataset', 'PanopticDataset')" (consider-using-in)
```


Discussion:

Resolving patch:
diff --git a/mmpose/apis/inference.py b/mmpose/apis/inference.py
--- a/mmpose/apis/inference.py
+++ b/mmpose/apis/inference.py
@@ -167,7 +167,7 @@ def _inference_single_pose_model(model,
     center, scale = _box2cs(cfg, bbox)
 
     flip_pairs = None
-    if dataset == 'TopDownCocoDataset' or dataset == 'TopDownOCHumanDataset':
+    if dataset in ('TopDownCocoDataset', 'TopDownOCHumanDataset'):
         flip_pairs = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12],
                       [13, 14], [15, 16]]
     elif dataset == 'TopDownCocoWholeBodyDataset':
@@ -191,8 +191,8 @@ def _inference_single_pose_model(model,
         flip_pairs = [[0, 3], [1, 4], [2, 5], [6, 9], [7, 10], [8, 11]]
     elif dataset == 'TopDownMpiiDataset':
         flip_pairs = [[0, 5], [1, 4], [2, 3], [10, 15], [11, 14], [12, 13]]
-    elif (dataset == 'OneHand10KDataset' or dataset == 'FreiHandDataset'
-          or dataset == 'PanopticDataset' or dataset == 'InterHand2DDataset'):
+    elif dataset in ('OneHand10KDataset', 'FreiHandDataset', 'PanopticDataset',
+                     'InterHand2DDataset'):
         flip_pairs = []
     else:
         raise NotImplementedError()
@@ -430,8 +430,8 @@ def vis_pose_result(model,
 
     radius = 4
 
-    if dataset == 'TopDownCocoDataset' or dataset == 'BottomUpCocoDataset' \
-            or dataset == 'TopDownOCHumanDataset':
+    if dataset in ('TopDownCocoDataset', 'BottomUpCocoDataset',
+                   'TopDownOCHumanDataset'):
         # show the results
         skeleton = [[16, 14], [14, 12], [17, 15], [15, 13], [12, 13], [6, 12],
                     [7, 13], [6, 7], [6, 8], [7, 9], [8, 10], [9, 11], [2, 3],
@@ -499,8 +499,8 @@ def vis_pose_result(model,
             16, 16, 16, 16, 16, 16, 7, 7, 0, 0, 9, 9, 9, 9, 9, 9
         ]]
 
-    elif (dataset == 'OneHand10KDataset' or dataset == 'FreiHandDataset'
-          or dataset == 'PanopticDataset'):
+    elif dataset in ('OneHand10KDataset', 'FreiHandDataset',
+                     'PanopticDataset'):
         skeleton = [[1, 2], [2, 3], [3, 4], [4, 5], [1, 6], [6, 7], [7, 8],
                     [8, 9], [1, 10], [10, 11], [11, 12], [12, 13], [1, 14],
                     [14, 15], [15, 16], [16, 17], [1, 18], [18, 19], [19, 20],


Test patch:
Repository: open-mmlab/mmpose

Issue:
Pylint: W0223
```bash
mmpose/models/detectors/bottom_up.py:19:0: W0223: Method 'simple_test' is abstract in class 'BasePose' but is not overridden (abstract-method)
mmpose/models/detectors/top_down.py:18:0: W0223: Method 'simple_test' is abstract in class 'BasePose' but is not overridden (abstract-method)
```


Discussion:

Resolving patch:
diff --git a/mmpose/models/detectors/base.py b/mmpose/models/detectors/base.py
--- a/mmpose/models/detectors/base.py
+++ b/mmpose/models/detectors/base.py
@@ -31,10 +31,6 @@ def forward_train(self, img, img_metas, **kwargs):
     def forward_test(self, img, img_metas, **kwargs):
         """Defines the computation performed at testing."""
 
-    @abstractmethod
-    def simple_test(self, img, img_metas, **kwargs):
-        """Simple test function."""
-
     @abstractmethod
     def forward(self, img, img_metas, return_loss=True, **kwargs):
         """Forward function."""


Test patch:
Repository: open-mmlab/mmpose

Issue:
Pylint: W0105
```bash
mmpose/datasets/datasets/top_down/topdown_mpii_trb_dataset.py:173:8: W0105: String statement has no effect (pointless-string-statement)
```


Discussion:

Resolving patch:
diff --git a/mmpose/datasets/datasets/top_down/topdown_mpii_trb_dataset.py b/mmpose/datasets/datasets/top_down/topdown_mpii_trb_dataset.py
--- a/mmpose/datasets/datasets/top_down/topdown_mpii_trb_dataset.py
+++ b/mmpose/datasets/datasets/top_down/topdown_mpii_trb_dataset.py
@@ -170,7 +170,7 @@ def evaluate(self, outputs, res_folder, metric='PCKh', **kwargs):
         for metric in metrics:
             if metric not in allowed_metrics:
                 raise KeyError(f'metric {metric} is not supported')
-        """Evaluate MPII-TRB keypoint results."""
+
         res_file = os.path.join(res_folder, 'result_keypoints.json')
 
         kpts = []


Test patch: