<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def with_scheme(self, scheme):
 """Return a new URL with scheme replaced."""

        # N.B. doesn't cleanup query/fragment
        if not isinstance(scheme, str):
            raise TypeError("Invalid scheme type")
        if not self.is_absolute():
            raise ValueError("scheme replacement is not allowed " "for relative URLs")
        return URL(self._val._replace(scheme=scheme.lower()), encoded=True)