def _connect(dsn: Optional[str] = None, **kwargs: Any) -> 'Connection[Any]':
        """Call :func:`psycopg.connect` with *dsn* and ``**kwargs``.

        .. note::
            Will create following methods and attributes in the returning connection to keep compatibility
            with the object that would be returned by :func:`psycopg2.connect`:

                * ``server_version`` attribute.
                * ``get_parameter_status`` method.

        :param dsn: DSN to call :func:`psycopg.connect` with.
        :param kwargs: keyword arguments to call :func:`psycopg.connect` with.

        :returns: a connection to the database.
        """
        ret: 'Connection[Any]' = __connect(dsn or "", **kwargs)
        # compatibility with psycopg2
        setattr(ret, 'server_version', ret.pgconn.server_version)
        setattr(ret, 'get_parameter_status', types.MethodType(__get_parameter_status, ret))
        return ret
Call :func:`psycopg.connect` with *dsn* and ``**kwargs``.

        .. note::
            Will create following methods and attributes in the returning connection to keep compatibility
            with the object that would be returned by :func:`psycopg2.connect`:

                * ``server_version`` attribute.
                * ``get_parameter_status`` method.

        :param dsn: DSN to call :func:`psycopg.connect` with.
        :param kwargs: keyword arguments to call :func:`psycopg.connect` with.

        :returns: a connection to the database.
        
patroni/psycopg.py