[Patchew-devel] [PATCH 3/4] remove dead code

Paolo Bonzini posted 4 patches 6 years, 8 months ago
[Patchew-devel] [PATCH 3/4] remove dead code
Posted by Paolo Bonzini 6 years, 8 months ago
Based on a patch generated by autoflake.
---
 api/migrations/0025_populate_project_maintainers.py | 1 -
 api/migrations/0028_populate_git_results.py         | 3 ---
 mbox.py                                             | 1 -
 mods/testing.py                                     | 1 -
 4 files changed, 6 deletions(-)

diff --git a/api/migrations/0025_populate_project_maintainers.py b/api/migrations/0025_populate_project_maintainers.py
index 3f9f3aa..0d83191 100644
--- a/api/migrations/0025_populate_project_maintainers.py
+++ b/api/migrations/0025_populate_project_maintainers.py
@@ -27,7 +27,6 @@ def maintainers_to_property(apps, schema_editor):
     # version than this migration expects. We use the historical version.
     Project = apps.get_model('api', 'Project')
     ProjectProperty = apps.get_model('api', 'ProjectProperty')
-    User = apps.get_model('auth', 'User')
     projects = Project.objects. \
         annotate(maintainer_count=Count('maintainers')). \
         filter(maintainer_count__gt=0)
diff --git a/api/migrations/0028_populate_git_results.py b/api/migrations/0028_populate_git_results.py
index dd6f9bc..ef7a593 100644
--- a/api/migrations/0028_populate_git_results.py
+++ b/api/migrations/0028_populate_git_results.py
@@ -49,8 +49,6 @@ def result_from_properties(apps, schema_editor):
                         data['base'] = git_base
                 r.status = api.models.Result.SUCCESS
             r.data = data
-        else:
-            status = api.models.Result.PENDING
         r.last_update = datetime.datetime.utcnow()
         r.save()
     messages = Message.objects.filter(properties__name='git.apply-log', properties__blob=True)
@@ -64,7 +62,6 @@ def result_to_properties(apps, schema_editor):
     Message = apps.get_model('api', 'Message')
     MessageProperty = apps.get_model('api', 'MessageProperty')
     MessageResult = apps.get_model('api', 'MessageResult')
-    LogEntry = apps.get_model('api', 'LogEntry')
     messages = Message.objects.filter(results__name='git')
     for m in messages:
         r = MessageResult.objects.get(name='git', message=m)
diff --git a/mbox.py b/mbox.py
index 16b3fc9..c66dd95 100644
--- a/mbox.py
+++ b/mbox.py
@@ -72,7 +72,6 @@ class MboxMessage(object):
            only to prepend Re:, return an empty str
            strip_re: drop leading "Re:" prefixes"""
         def do_strip_tags(t):
-            diff_stats = t.strip()
             while t.startswith("[") and "]" in t:
                 t = t[t.find("]") + 1:].strip()
             return t
diff --git a/mods/testing.py b/mods/testing.py
index cece418..ffd234f 100644
--- a/mods/testing.py
+++ b/mods/testing.py
@@ -302,7 +302,6 @@ class TestingModule(PatchewModule):
                     html_log_url=html_log_url, is_timeout=is_timeout)
 
     def get_tests(self, obj):
-        ret = {}
         if isinstance(obj, Message):
             obj = obj.project
         return self.get_project_config(obj).get("tests", {})
-- 
2.21.0


_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
Re: [Patchew-devel] [PATCH 3/4] remove dead code
Posted by Philippe Mathieu-Daudé 6 years, 8 months ago
Hi Paolo,

On 5/25/19 10:39 AM, Paolo Bonzini wrote:
> Based on a patch generated by autoflake.
> ---
>  api/migrations/0025_populate_project_maintainers.py | 1 -
>  api/migrations/0028_populate_git_results.py         | 3 ---
>  mbox.py                                             | 1 -
>  mods/testing.py                                     | 1 -
>  4 files changed, 6 deletions(-)
> 
> diff --git a/api/migrations/0025_populate_project_maintainers.py b/api/migrations/0025_populate_project_maintainers.py
> index 3f9f3aa..0d83191 100644
> --- a/api/migrations/0025_populate_project_maintainers.py
> +++ b/api/migrations/0025_populate_project_maintainers.py
> @@ -27,7 +27,6 @@ def maintainers_to_property(apps, schema_editor):
>      # version than this migration expects. We use the historical version.
>      Project = apps.get_model('api', 'Project')
>      ProjectProperty = apps.get_model('api', 'ProjectProperty')
> -    User = apps.get_model('auth', 'User')
>      projects = Project.objects. \
>          annotate(maintainer_count=Count('maintainers')). \
>          filter(maintainer_count__gt=0)
> diff --git a/api/migrations/0028_populate_git_results.py b/api/migrations/0028_populate_git_results.py
> index dd6f9bc..ef7a593 100644
> --- a/api/migrations/0028_populate_git_results.py
> +++ b/api/migrations/0028_populate_git_results.py
> @@ -49,8 +49,6 @@ def result_from_properties(apps, schema_editor):
>                          data['base'] = git_base
>                  r.status = api.models.Result.SUCCESS
>              r.data = data
> -        else:
> -            status = api.models.Result.PENDING

It seems the 'else' case is correct, but the code is broken because we
assign 'status' instead of 'r.status'.

This would be the fix:

-- >8 --
--- a/api/migrations/0028_populate_git_results.py
+++ b/api/migrations/0028_populate_git_results.py
@@ -53,5 +53,5 @@ def result_from_properties(apps, schema_editor):
             r.data = data
         else:
-            status = api.models.Result.PENDING
+            r.status = api.models.Result.PENDING
         r.last_update = datetime.datetime.utcnow()
         r.save()
---

>          r.last_update = datetime.datetime.utcnow()
>          r.save()
>      messages = Message.objects.filter(properties__name='git.apply-log', properties__blob=True)
> @@ -64,7 +62,6 @@ def result_to_properties(apps, schema_editor):
>      Message = apps.get_model('api', 'Message')
>      MessageProperty = apps.get_model('api', 'MessageProperty')
>      MessageResult = apps.get_model('api', 'MessageResult')
> -    LogEntry = apps.get_model('api', 'LogEntry')
>      messages = Message.objects.filter(results__name='git')
>      for m in messages:
>          r = MessageResult.objects.get(name='git', message=m)
> diff --git a/mbox.py b/mbox.py
> index 16b3fc9..c66dd95 100644
> --- a/mbox.py
> +++ b/mbox.py
> @@ -72,7 +72,6 @@ class MboxMessage(object):
>             only to prepend Re:, return an empty str
>             strip_re: drop leading "Re:" prefixes"""
>          def do_strip_tags(t):
> -            diff_stats = t.strip()
>              while t.startswith("[") and "]" in t:
>                  t = t[t.find("]") + 1:].strip()
>              return t
> diff --git a/mods/testing.py b/mods/testing.py
> index cece418..ffd234f 100644
> --- a/mods/testing.py
> +++ b/mods/testing.py
> @@ -302,7 +302,6 @@ class TestingModule(PatchewModule):
>                      html_log_url=html_log_url, is_timeout=is_timeout)
>  
>      def get_tests(self, obj):
> -        ret = {}
>          if isinstance(obj, Message):
>              obj = obj.project
>          return self.get_project_config(obj).get("tests", {})
> 

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
Re: [Patchew-devel] [PATCH 3/4] remove dead code
Posted by Paolo Bonzini 6 years, 8 months ago
On 27/05/19 12:18, Philippe Mathieu-Daudé wrote:
> Hi Paolo,
> 
> On 5/25/19 10:39 AM, Paolo Bonzini wrote:
>> Based on a patch generated by autoflake.
>> ---
>>  api/migrations/0025_populate_project_maintainers.py | 1 -
>>  api/migrations/0028_populate_git_results.py         | 3 ---
>>  mbox.py                                             | 1 -
>>  mods/testing.py                                     | 1 -
>>  4 files changed, 6 deletions(-)
>>
>> diff --git a/api/migrations/0025_populate_project_maintainers.py b/api/migrations/0025_populate_project_maintainers.py
>> index 3f9f3aa..0d83191 100644
>> --- a/api/migrations/0025_populate_project_maintainers.py
>> +++ b/api/migrations/0025_populate_project_maintainers.py
>> @@ -27,7 +27,6 @@ def maintainers_to_property(apps, schema_editor):
>>      # version than this migration expects. We use the historical version.
>>      Project = apps.get_model('api', 'Project')
>>      ProjectProperty = apps.get_model('api', 'ProjectProperty')
>> -    User = apps.get_model('auth', 'User')
>>      projects = Project.objects. \
>>          annotate(maintainer_count=Count('maintainers')). \
>>          filter(maintainer_count__gt=0)
>> diff --git a/api/migrations/0028_populate_git_results.py b/api/migrations/0028_populate_git_results.py
>> index dd6f9bc..ef7a593 100644
>> --- a/api/migrations/0028_populate_git_results.py
>> +++ b/api/migrations/0028_populate_git_results.py
>> @@ -49,8 +49,6 @@ def result_from_properties(apps, schema_editor):
>>                          data['base'] = git_base
>>                  r.status = api.models.Result.SUCCESS
>>              r.data = data
>> -        else:
>> -            status = api.models.Result.PENDING
> 
> It seems the 'else' case is correct, but the code is broken because we
> assign 'status' instead of 'r.status'.
> 
> This would be the fix:

Oops, indeed!  I squashed this and pushed the result.

Paolo

> -- >8 --
> --- a/api/migrations/0028_populate_git_results.py
> +++ b/api/migrations/0028_populate_git_results.py
> @@ -53,5 +53,5 @@ def result_from_properties(apps, schema_editor):
>              r.data = data
>          else:
> -            status = api.models.Result.PENDING
> +            r.status = api.models.Result.PENDING
>          r.last_update = datetime.datetime.utcnow()
>          r.save()
> ---
> 
>>          r.last_update = datetime.datetime.utcnow()
>>          r.save()
>>      messages = Message.objects.filter(properties__name='git.apply-log', properties__blob=True)
>> @@ -64,7 +62,6 @@ def result_to_properties(apps, schema_editor):
>>      Message = apps.get_model('api', 'Message')
>>      MessageProperty = apps.get_model('api', 'MessageProperty')
>>      MessageResult = apps.get_model('api', 'MessageResult')
>> -    LogEntry = apps.get_model('api', 'LogEntry')
>>      messages = Message.objects.filter(results__name='git')
>>      for m in messages:
>>          r = MessageResult.objects.get(name='git', message=m)
>> diff --git a/mbox.py b/mbox.py
>> index 16b3fc9..c66dd95 100644
>> --- a/mbox.py
>> +++ b/mbox.py
>> @@ -72,7 +72,6 @@ class MboxMessage(object):
>>             only to prepend Re:, return an empty str
>>             strip_re: drop leading "Re:" prefixes"""
>>          def do_strip_tags(t):
>> -            diff_stats = t.strip()
>>              while t.startswith("[") and "]" in t:
>>                  t = t[t.find("]") + 1:].strip()
>>              return t
>> diff --git a/mods/testing.py b/mods/testing.py
>> index cece418..ffd234f 100644
>> --- a/mods/testing.py
>> +++ b/mods/testing.py
>> @@ -302,7 +302,6 @@ class TestingModule(PatchewModule):
>>                      html_log_url=html_log_url, is_timeout=is_timeout)
>>  
>>      def get_tests(self, obj):
>> -        ret = {}
>>          if isinstance(obj, Message):
>>              obj = obj.project
>>          return self.get_project_config(obj).get("tests", {})
>>

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel