code: def semver(version, loose):
      if isinstance(version, SemVer):
          if version.loose == loose:
              return version
          else:
              version = version.version
      elif not isinstance(version, string_type):  # xxx:
          raise ValueError("Invalid Version: {}".format(version))
  
      
      return SemVer(version, loose)
docs: if (!(this instanceof SemVer))
         return new SemVer(version, loose);