Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Unified Diff: recipe_engine/util.py

Issue 1773273003: Make output placeholders like json.output index-able by name. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: recipe_engine/util.py
diff --git a/recipe_engine/util.py b/recipe_engine/util.py
index 75cd5f9441f5b9eed881ef37bdf4ccedabcaa6e1..49526329d470c1ed4dad722fa26f5b55abbb680f 100644
--- a/recipe_engine/util.py
+++ b/recipe_engine/util.py
@@ -34,9 +34,12 @@ class ModuleInjectionSite(object):
class Placeholder(object):
+ DEFAULT_ID = object()
+
"""Base class for json placeholders. Do not use directly."""
- def __init__(self):
+ def __init__(self, id=None):
iannucci 2016/03/10 03:17:42 I think you can do id=DEFAULT_ID or maybe
stgao 2016/03/10 20:34:23 No. We can't do that, because subclasses will call
self.name_pieces = None
+ self.id = id or Placeholder.DEFAULT_ID
@property
def backing_file(self): # pragma: no cover
@@ -68,6 +71,12 @@ class Placeholder(object):
assert self.name_pieces
return "%s.%s" % self.name_pieces
+ @property
+ def id_name(self):
+ if self.id == self.DEFAULT_ID:
iannucci 2016/03/10 03:17:42 use the `is` keyword for comparison (compares poin
stgao 2016/03/10 20:34:23 Done.
+ return self.name
+ else:
+ return "%s.%s" % (self.id, self.name)
def static_wraps(func):
wrapped_fn = func

Powered by Google App Engine
This is Rietveld 408576698