code: def parse(
      version, strict=False  # type: str  # type: bool
  ):  # type:(...) -> Union[Version, LegacyVersion]
      
      try:
          return Version(version)
      except InvalidVersion:
          if strict:
              raise
  
          return LegacyVersion(version)
docs: Parse the given version string and return either a :class:`Version` object
      or a LegacyVersion object depending on if the given version is
      a valid PEP 440 version or a legacy version.
  
      If strict=True only PEP 440 versions will be accepted.