diff options
-rw-r--r-- | lib/spack/spack/arch.py | 2 | ||||
-rw-r--r-- | lib/spack/spack/package.py | 4 | ||||
-rw-r--r-- | lib/spack/spack/relations.py | 4 | ||||
-rw-r--r-- | lib/spack/spack/spec.py | 13 | ||||
-rw-r--r-- | lib/spack/spack/version.py | 17 |
5 files changed, 21 insertions, 19 deletions
diff --git a/lib/spack/spack/arch.py b/lib/spack/spack/arch.py index 1c5d5a2c5f..c4914de1a0 100644 --- a/lib/spack/spack/arch.py +++ b/lib/spack/spack/arch.py @@ -61,7 +61,7 @@ def sys_type(): if sys_type == None: raise NoSysTypeError() - if not type(sys_type) == str: + if not isinstance(sys_type, basestring): raise InvalidSysTypeError(sys_type) return sys_type diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 5f98380bf5..a28bfae411 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -300,7 +300,7 @@ class Package(object): except UndetectableVersionError: tty.die("Couldn't extract a default version from %s. You " + "must specify it explicitly in the package." % self.url) - elif type(self.version) != Version: + elif not isinstance(self.version, Version): self.version = Version(self.version) # This is set by scraping a web page. @@ -308,7 +308,7 @@ class Package(object): # This list overrides available_versions if set by the user. attr_setdefault(self, 'versions', None) - if self.versions and type(self.versions) != VersionList: + if self.versions and not isinstance(self.versions, VersionList): self.versions = VersionList(self.versions) # Empty at first; only compute dependent packages if necessary diff --git a/lib/spack/spack/relations.py b/lib/spack/spack/relations.py index f282351b86..4be4bb6cad 100644 --- a/lib/spack/spack/relations.py +++ b/lib/spack/spack/relations.py @@ -97,11 +97,11 @@ def _parse_local_spec(spec_like, pkg_name): e.g., provides('mpi@2', when='@1.9:') says that this package provides MPI-3 when its version is higher than 1.9. """ - if type(spec_like) not in (str, Spec): + if not isinstance(spec_like, (str, Spec)): raise TypeError('spec must be Spec or spec string. Found %s' % type(spec_like)) - if type(spec_like) == str: + if isinstance(spec_like, str): try: local_spec = Spec(spec_like) except spack.parse.ParseError: diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index d853aa78e9..358343e3bb 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -246,12 +246,12 @@ class DependencyMap(HashableMap): class Spec(object): def __init__(self, spec_like, *dep_like): # Copy if spec_like is a Spec. - if type(spec_like) == Spec: + if isinstance(spec_like, Spec): self._dup(spec_like) return # Parse if the spec_like is a string. - if type(spec_like) != str: + if not isinstance(spec_like, basestring): raise TypeError("Can't make spec out of %s" % type(spec_like)) spec_list = SpecParser().parse(spec_like) @@ -277,7 +277,7 @@ class Spec(object): # Note that given two specs a and b, Spec(a) copies a, but # Spec(a, b) will copy a but just add b as a dep. for dep in dep_like: - spec = dep if type(dep) == Spec else Spec(dep) + spec = dep if isinstance(dep, Spec) else Spec(dep) self._add_dependency(spec) @@ -632,6 +632,9 @@ class Spec(object): package that provides a virtual package that is in the spec, then we replace the virtual package with the non-virtual one. 4) The spec DAG matches package DAG. + + TODO: normalize should probably implement some form of cycle detection, + to ensure that the spec is actually a DAG. """ # Ensure first that all packages in the DAG exist. self.validate_package_names() @@ -699,7 +702,7 @@ class Spec(object): def satisfies(self, other): - if type(other) != Spec: + if not isinstance(other, Spec): other = Spec(other) def sat(attribute): @@ -772,7 +775,7 @@ class Spec(object): def __contains__(self, spec): """True if this spec has any dependency that satisfies the supplied spec.""" - if type(spec) != Spec: + if not isinstance(spec, Spec): spec = Spec(spec) for s in self.preorder_traversal(): diff --git a/lib/spack/spack/version.py b/lib/spack/spack/version.py index 0be19e96ed..904992f832 100644 --- a/lib/spack/spack/version.py +++ b/lib/spack/spack/version.py @@ -240,9 +240,9 @@ class Version(object): @total_ordering class VersionRange(object): def __init__(self, start, end): - if type(start) == str: + if isinstance(start, basestring): start = Version(start) - if type(end) == str: + if isinstance(end, basestring): end = Version(end) self.start = start @@ -347,7 +347,7 @@ class VersionList(object): def __init__(self, vlist=None): self.versions = [] if vlist != None: - if type(vlist) == str: + if isinstance(vlist, basestring): vlist = _string_to_version(vlist) if type(vlist) == VersionList: self.versions = vlist.versions @@ -542,14 +542,13 @@ def ver(obj): """Parses a Version, VersionRange, or VersionList from a string or list of strings. """ - t = type(obj) - if t == list: + if isinstance(obj, (list, tuple)): return VersionList(obj) - elif t == str: + elif isinstance(obj, basestring): return _string_to_version(obj) - elif t in (int, float): + elif isinstance(obj, (int, float)): return _string_to_version(str(obj)) - elif t in (Version, VersionRange, VersionList): + elif type(obj) in (Version, VersionRange, VersionList): return obj else: - raise TypeError("ver() can't convert %s to version!" % t) + raise TypeError("ver() can't convert %s to version!" % type(obj)) |