def with_user(self, user):
        """Return a new URL with user replaced.

        Autoencode user if needed.

        Clear user/password if user is None.

        """
        # N.B. doesn't cleanup query/fragment
        val = self._val
        if user is None:
            password = None
        elif isinstance(user, str):
            user = self._QUOTER(user)
            password = val.password
        else:
            raise TypeError("Invalid user type")
        if not self.is_absolute():
            raise ValueError("user replacement is not allowed " "for relative URLs")
        return URL(
            self._val._replace(
                netloc=self._make_netloc(
                    user, password, val.hostname, val.port, encode=False
                )
            ),
            encoded=True,
        )
Return a new URL with user replaced.

        Autoencode user if needed.

        Clear user/password if user is None.