1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
8 def IsDirectlyConstructable(cls
):
9 """Returns True if instance of |cls| can be construct without arguments."""
10 assert inspect
.isclass(cls
)
11 if not hasattr(cls
, '__init__'):
12 # Case |class A: pass|.
14 if cls
.__init
__ is object.__init
__:
15 # Case |class A(object): pass|.
17 # Case |class (object):| with |__init__| other than |object.__init__|.
18 args
, _
, _
, defaults
= inspect
.getargspec(cls
.__init
__)
21 # Return true if |self| is only arg without a default.
22 return len(args
) == len(defaults
) + 1