code: def with_user(self, user):
          
          # 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,
          )
docs: Return a new URL with user replaced.
  
          Autoencode user if needed.
  
          Clear user/password if user is None.