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

Unified Diff: common/py_utils/py_utils/class_util.py

Issue 2965383002: WIP: Add support for additional flag-specified tracing categories. (Closed)
Patch Set: addressed review comments Created 3 years, 5 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
« no previous file with comments | « no previous file | common/py_utils/py_utils/class_util_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/py_utils/py_utils/class_util.py
diff --git a/common/py_utils/py_utils/class_util.py b/common/py_utils/py_utils/class_util.py
new file mode 100644
index 0000000000000000000000000000000000000000..4cec430038bf525b9f34563dff877d16257fe4e7
--- /dev/null
+++ b/common/py_utils/py_utils/class_util.py
@@ -0,0 +1,26 @@
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import inspect
+
+def IsMethodOverridden(parent_cls, child_cls, method_name):
+ assert inspect.isclass(parent_cls), '%s should be a class' % parent_cls
+ assert inspect.isclass(child_cls), '%s should be a class' % child_cls
+ assert parent_cls.__dict__.get(method_name), '%s has no method %s' % (
+ parent_cls, method_name)
+
+ if child_cls.__dict__.get(method_name):
+ # It's overridden
+ return True
+
+ if parent_cls in child_cls.__bases__:
+ # The parent is the base class of the child, we did not find the
+ # overridden method.
+ return False
+
+ # For all the base classes of this class that are not object, check if
+ # they override the method.
+ base_cls = [cls for cls in child_cls.__bases__ if cls and cls != object]
+ return any(
+ IsMethodOverridden(parent_cls, base, method_name) for base in base_cls)
« no previous file with comments | « no previous file | common/py_utils/py_utils/class_util_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698