[Patchew-devel] [PATCH 1/4] modules: do not use "import *"

Philippe Mathieu-Daudé philmd at redhat.com
Mon May 27 10:19:20 UTC 2019


On 5/25/19 10:39 AM, Paolo Bonzini wrote:
> import * prevents static analysis of undefined symbols, drop it.
> ---
>  mod.py          | 16 ++++++++--------
>  mods/email.py   | 30 +++++++++++++++---------------
>  mods/git.py     | 10 +++++-----
>  mods/testing.py | 22 +++++++++++-----------
>  4 files changed, 39 insertions(+), 39 deletions(-)
> 
> diff --git a/mod.py b/mod.py
> index a7ba7e2..d47745c 100644
> --- a/mod.py
> +++ b/mod.py
> @@ -15,7 +15,7 @@ from django.conf import settings
>  from django.template import Template, Context
>  import traceback
>  import configparser
> -from schema import *
> +import schema
>  
>  class PatchewModule(object):
>      """ Module base class """
> @@ -103,22 +103,22 @@ class PatchewModule(object):
>                                       value=config)
>  
>      def _build_one(self, request, project, prefix, config, scm):
> -        if type(scm) == MapSchema:
> +        if type(scm) == schema.MapSchema:
>              return self._build_map_scm(request, project, prefix, config, scm)
> -        elif type(scm) == StringSchema:
> +        elif type(scm) == schema.StringSchema:
>              return self._build_string_scm(request, project, prefix, config, scm)
> -        elif type(scm) == IntegerSchema:
> +        elif type(scm) == schema.IntegerSchema:
>              return self._build_integer_scm(request, project, prefix, config, scm)
> -        elif type(scm) == BooleanSchema:
> +        elif type(scm) == schema.BooleanSchema:
>              return self._build_boolean_scm(request, project, prefix, config, scm)
> -        elif type(scm) == EnumSchema:
> +        elif type(scm) == schema.EnumSchema:
>              return self._build_enum_scm(request, project, prefix, config, scm)
> -        elif type(scm) == ArraySchema:
> +        elif type(scm) == schema.ArraySchema:
>              return self._build_array_scm(request, project, prefix, config, scm)
>          assert False
>  
>      def build_config_html(self, request, project):
> -        assert isinstance(self.project_config_schema, ArraySchema)
> +        assert isinstance(self.project_config_schema, schema.ArraySchema)
>          scm = self.project_config_schema
>          config = self.get_project_config(project)
>          return self._build_one(request, project, scm.name, config, scm)
> diff --git a/mods/email.py b/mods/email.py
> index 175af9d..e95fbe9 100644
> --- a/mods/email.py
> +++ b/mods/email.py
> @@ -21,7 +21,7 @@ import email.utils
>  import uuid
>  from api.models import Message, Project
>  from event import register_handler, get_events_info
> -from schema import *
> +import schema
>  
>  _default_config = """
>  [smtp]
> @@ -52,46 +52,46 @@ Email information is configured in "INI" style:
>      default_config = _default_config
>  
>      email_schema = \
> -        ArraySchema("{name}", "Email Notification",
> +        schema.ArraySchema("{name}", "Email Notification",
>                      desc="Email notification",
>                      members=[
> -                        EnumSchema("event", "Event",
> +                        schema.EnumSchema("event", "Event",
>                                     enums=lambda: get_events_info(),
>                                     required=True,
>                                     desc="Which event to trigger the email notification"),
> -                        BooleanSchema("enabled", "Enabled",
> +                        schema.BooleanSchema("enabled", "Enabled",
>                                        desc="Whether this event is enabled",
>                                        default=True),
> -                        BooleanSchema("reply_to_all", "Reply to all",
> +                        schema.BooleanSchema("reply_to_all", "Reply to all",
>                                        desc='If set, Cc all the receipients of the email message associated to the event. Also, if set the original sender of the email message will be a recipient even if the "to" field is nonempty',
>                                        default=False),
> -                        BooleanSchema("in_reply_to", "Set In-Reply-To",
> +                        schema.BooleanSchema("in_reply_to", "Set In-Reply-To",
>                                        desc='Whether to set In-Reply-To to the message id, if the event has an associated email message',
>                                        default=True),
> -                        BooleanSchema("set_reply_to", "Set Reply-To",
> +                        schema.BooleanSchema("set_reply_to", "Set Reply-To",
>                                        desc='Whether to set Reply-To to the project mailing list, if the event has an associated email message',
>                                        default=True),
> -                        BooleanSchema("reply_subject", "Set replying subject",
> +                        schema.BooleanSchema("reply_subject", "Set replying subject",
>                                        desc='Whether to set Subject to "Re: xxx", if the event has an associated email message',
>                                        default=True),
> -                        BooleanSchema("to_user", "Send to user",
> +                        schema.BooleanSchema("to_user", "Send to user",
>                                        desc='Whether to set To to a user email, if the event has an associated user',
>                                        default=False),
> -                        StringSchema("to", "To", desc="Send email to"),
> -                        StringSchema("cc", "Cc", desc="Cc list"),
> -                        StringSchema("subject_template", "Subject template",
> +                        schema.StringSchema("to", "To", desc="Send email to"),
> +                        schema.StringSchema("cc", "Cc", desc="Cc list"),
> +                        schema.StringSchema("subject_template", "Subject template",
>                                       desc="""The django template for subject""",
>                                       required=True),
> -                        StringSchema("body_template", "Body template",
> +                        schema.StringSchema("body_template", "Body template",
>                                       desc="The django template for email body.",
>                                       multiline=True,
>                                       required=True),
>                      ])
>  
>      project_config_schema = \
> -        ArraySchema("email", desc="Configuration for email module",
> +        schema.ArraySchema("email", desc="Configuration for email module",
>                      members=[
> -                        MapSchema("notifications", "Email notifications",
> +                        schema.MapSchema("notifications", "Email notifications",
>                                     desc="Email notifications",
>                                     item=email_schema),
>                     ])
> diff --git a/mods/git.py b/mods/git.py
> index 78939b8..753da7e 100644
> --- a/mods/git.py
> +++ b/mods/git.py
> @@ -25,7 +25,7 @@ from api.models import (Message, Project, Result)
>  from api.rest import PluginMethodField, SeriesSerializer, reverse_detail
>  from api.views import APILoginRequiredView, prepare_series
>  from patchew.logviewer import LogView
> -from schema import *
> +import schema
>  from rest_framework import generics, mixins, serializers
>  from rest_framework.fields import CharField, SerializerMethodField
>  
> @@ -64,14 +64,14 @@ class GitModule(PatchewModule):
>      result_data_serializer_class = ResultDataSerializer
>  
>      project_config_schema = \
> -        ArraySchema("git", desc="Configuration for git module",
> +        schema.ArraySchema("git", desc="Configuration for git module",
>                      members=[
> -                        StringSchema("push_to", "Push remote",
> +                        schema.StringSchema("push_to", "Push remote",
>                                       desc="Remote to push to",
>                                       required=True),
> -                        StringSchema("public_repo", "Public repo",
> +                        schema.StringSchema("public_repo", "Public repo",
>                                       desc="Publicly visible repo URL"),
> -                        StringSchema("url_template", "URL template",
> +                        schema.StringSchema("url_template", "URL template",
>                                       desc="Publicly visible URL template for applied branch, where %t will be replaced by the applied tag name",
>                                       required=True),
>                     ])
> diff --git a/mods/testing.py b/mods/testing.py
> index 90bb2be..cece418 100644
> --- a/mods/testing.py
> +++ b/mods/testing.py
> @@ -24,7 +24,7 @@ from api.rest import PluginMethodField, TestPermission, reverse_detail
>  from api.search import SearchEngine
>  from event import emit_event, declare_event, register_handler
>  from patchew.logviewer import LogView
> -from schema import *
> +import schema
>  from rest_framework import serializers, generics
>  from rest_framework.fields import CharField, BooleanField
>  from rest_framework.response import Response
> @@ -64,17 +64,17 @@ class TestingModule(PatchewModule):
>      result_data_serializer_class = ResultDataSerializer
>  
>      test_schema = \
> -        ArraySchema("{name}", "Test", desc="Test spec",
> +        schema.ArraySchema("{name}", "Test", desc="Test spec",
>                      members=[
> -                        BooleanSchema("enabled", "Enabled",
> +                        schema.BooleanSchema("enabled", "Enabled",
>                                        desc="Whether this test is enabled",
>                                        default=True),
> -                        StringSchema("requirements", "Requirements",
> +                        schema.StringSchema("requirements", "Requirements",
>                                       desc="List of requirements of the test"),
> -                        IntegerSchema("timeout", "Timeout",
> +                        schema.IntegerSchema("timeout", "Timeout",
>                                        default=3600,
>                                        desc="Timeout for the test"),
> -                        StringSchema("script", "Test script",
> +                        schema.StringSchema("script", "Test script",
>                                       desc="The testing script",
>                                       default=TESTING_SCRIPT_DEFAULT,
>                                       multiline=True,
> @@ -82,9 +82,9 @@ class TestingModule(PatchewModule):
>                      ])
>  
>      requirement_schema = \
> -        ArraySchema("{name}", "Requirement", desc="Test requirement spec",
> +        schema.ArraySchema("{name}", "Requirement", desc="Test requirement spec",
>                      members=[
> -                        StringSchema("script", "Probe script",
> +                        schema.StringSchema("script", "Probe script",
>                                       desc="The probing script for this requirement",
>                                       default="#!/bin/bash\ntrue",
>                                       multiline=True,
> @@ -92,12 +92,12 @@ class TestingModule(PatchewModule):
>                      ])
>  
>      project_config_schema = \
> -        ArraySchema("testing", desc="Configuration for testing module",
> +        schema.ArraySchema("testing", desc="Configuration for testing module",
>                      members=[
> -                        MapSchema("tests", "Tests",
> +                        schema.MapSchema("tests", "Tests",
>                                     desc="Testing specs",
>                                     item=test_schema),
> -                        MapSchema("requirements", "Requirements",
> +                        schema.MapSchema("requirements", "Requirements",
>                                     desc="Requirement specs",
>                                     item=requirement_schema),
>                     ])
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd at redhat.com>




More information about the Patchew-devel mailing list