On Wed, 2015-12-09 at 16:54 +0100, Julien Cristau wrote:
> On Fri, Dec  4, 2015 at 19:09:47 +0000, Adam D. Barratt wrote:
> 
> > diff --git a/scripts/hint b/scripts/hint
> > index 9d38274..3b3b1ee 100755
> > --- a/scripts/hint
> > +++ b/scripts/hint
> > @@ -513,9 +513,11 @@ class Hint(object):
> >  
> >      ##
> >  
> > -    def __init__(self, hintname, *args):
> > +    def __init__(self, hintname, *args, **kwargs):
> 
> I'd prefer an explicit 'update' kwarg, defaulting to True.  That'd not
> give the impression that we're going to do anything with arbitrary
> kwargs, be more self-documenting, and avoid a 'noupdate=False' confusing
> double negation.

As per our IRC conversation, Python 2 doesn't make that particularly
easy to accomplish, so I've ported hint to Python 3, thus allowing
explicitly named arguments to occur after the varargs parameters.

I've attached a revised patch on that basis, which feels a lot cleaner
(at least IMO).

Regards,

Adam
diff --git a/scripts/hint b/scripts/hint
index ec16707..6529a77 100755
--- a/scripts/hint
+++ b/scripts/hint
@@ -513,10 +513,11 @@ class Hint(object):
 
     ##
 
-    def __init__(self, hintname, *args):
+    def __init__(self, hintname, *args, is_mutable=True):
         starts_with_letter = re.compile(r'(?i)^[a-z]')
 
         self.name = hintname
+        self.is_mutable = is_mutable
         self.pkgs = []
 
         self.versionmap0 = {} # original versions on the hint
@@ -562,7 +563,7 @@ class Hint(object):
                 suite = self.SOURCE_DISTRIBUTION
             except AttributeError:
                 suite = 'unstable'
-            if not projectb.is_source_pkg(suite, src):
+            if not projectb.is_source_pkg(suite, src) and self.is_mutable:
                 tmpsrc = src
                 src = projectb.get_source_pkg(suite, src)
                 if src is None:
@@ -634,7 +635,7 @@ class Hint(object):
             words = [ ]
         return ' '.join(words)
 
-    def __new__(cls, hintname, *args):
+    def __new__(cls, hintname, *args, is_mutable=True):
         if hintname in \
                 [ 'easy', 'hint', 'force', 'force-hint', 'unblock', 'urgent', 'unblock-udeb' ]:
             subclass = UnstableToTestingHint
@@ -685,8 +686,8 @@ class UnversionedHint(Hint):
 class MigrationHint(Hint):
     """A hint whose packages are meant to move from one distribution to another."""
 
-    def __init__(self, *args):
-        Hint.__init__(self, *args)
+    def __init__(self, *args, is_mutable=True):
+        Hint.__init__(self, *args, is_mutable=is_mutable)
         self._versions = None
 
     @property
@@ -700,7 +701,7 @@ class MigrationHint(Hint):
         }
 
         for pkg, ver in self._versions['source'].items():
-            if ver is None and pkg not in self.remove_pkgs:
+            if ver is None and pkg not in self.remove_pkgs and self.is_mutable:
                 print(
                     'W: package %s not in %s, skipping.'
                     % (pkg, self.SOURCE_DISTRIBUTION), file=sys.stderr)
@@ -785,8 +786,9 @@ class TpuToTestingHint(MigrationHint):
 
 
 class AgeDaysHint(UnstableToTestingHint):
-    def __init__(self, hintname, days, *args):
-        UnstableToTestingHint.__init__(self, '%s %s' % (hintname, days), *args)
+    def __init__(self, hintname, days, *args, is_mutable=True):
+        UnstableToTestingHint.__init__(self, '%s %s' % (hintname, days), *args,
+          is_mutable=is_mutable)
 
 
 class RemovalHint(Hint):
@@ -868,7 +870,7 @@ class HintfileParagraph(object):
             else:
                 if seen_hint and split_out:
                     self._groups.append([])
-                hint = Hint(*line.strip().split())
+                hint = Hint(*line.strip().split(), is_mutable=False)
                 self._groups[-1].append(hint)
                 seen_hint = True
 

Reply via email to