def __new__(cls, major, minor, micro, release="final", pre=0, post=0, dev=0):
        """Validate version info."""

        # Ensure all parts are positive integers.
        for value in (major, minor, micro, pre, post):
            if not (isinstance(value, int) and value >= 0):
                raise ValueError("All version parts except 'release' should be integers.")

        if release not in REL_MAP:
            raise ValueError("'{}' is not a valid release type.".format(release))

        # Ensure valid pre-release (we do not allow implicit pre-releases).
        if ".dev-candidate" < release < "final":
            if pre == 0:
                raise ValueError("Implicit pre-releases not allowed.")
            elif dev:
                raise ValueError("Version is not a development release.")
            elif post:
                raise ValueError("Post-releases are not allowed with pre-releases.")

        # Ensure valid development or development/pre release
        elif release < "alpha":
            if release > ".dev" and pre == 0:
                raise ValueError("Implicit pre-release not allowed.")
            elif post:
                raise ValueError("Post-releases are not allowed with pre-releases.")

        # Ensure a valid normal release
        else:
            if pre:
                raise ValueError("Version is not a pre-release.")
            elif dev:
                raise ValueError("Version is not a development release.")

        return super(Version, cls).__new__(cls, major, minor, micro, release, pre, post, dev)
def __new__ ( cls , major , minor , micro , release = "final" , pre = 0 , post = 0 , dev = 0 ) : for value in ( major , minor , micro , pre , post ) : if not ( isinstance ( value , int ) and value >= 0 ) : raise ValueError ( "All version parts except 'release' should be integers." ) if release not in REL_MAP : raise ValueError ( "'{}' is not a valid release type." . format ( release ) ) if ".dev-candidate" < release < "final" : if pre == 0 : raise ValueError ( "Implicit pre-releases not allowed." ) elif dev : raise ValueError ( "Version is not a development release." ) elif post : raise ValueError ( "Post-releases are not allowed with pre-releases." ) elif release < "alpha" : if release > ".dev" and pre == 0 : raise ValueError ( "Implicit pre-release not allowed." ) elif post : raise ValueError ( "Post-releases are not allowed with pre-releases." ) else : if pre : raise ValueError ( "Version is not a pre-release." ) elif dev : raise ValueError ( "Version is not a development release." ) return super ( Version , cls ) . __new__ ( cls , major , minor , micro , release , pre , post , dev )
Validate version info.