8000 Improve documentation with errors and links (#642) · ammogcoder/PyMySQL@9dde50a · GitHub
[go: up one dir, main page]

Skip to content

Commit 9dde50a

Browse files
Phlosioneermethane
authored andcommitted
Improve documentation with errors and links (PyMySQL#642)
1 parent c51b47e commit 9dde50a

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

pymysql/connections.py

+55-7
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,9 @@ class Connection(object):
560560
:param db: Alias for database. (for compatibility to MySQLdb)
561561
:param passwd: Alias for password. (for compatibility to MySQLdb)
562562
:param binary_prefix: Add _binary prefix on bytes and bytearray. (default: False)
563+
564+
See `Connection <https://www.python.org/dev/peps/pep-0249/#connection-objects>`_ in the
565+
specification.
563566
"""
564567

565568
_sock = None
@@ -716,7 +719,14 @@ def _create_ssl_ctx(self, sslp):
716719
return ctx
717720

718721
def close(self):
719-
"""Send the quit message and close the socket"""
722+
"""
723+
Send the quit message and close the socket.
724+
725+
See `Connection.close() <https://www.python.org/dev/peps/pep-0249/#Connection.close>`_
726+
in the specification.
727+
728+
:raise Error: If the connection is already closed.
729+
"""
720730
if self._closed:
721731
raise err.Error("Already closed")
722732
self._closed = True
@@ -732,6 +742,7 @@ def close(self):
732742

733743
@property
734744
def open(self):
745+
"""Return True if the connection is open"""
735746
return self._sock is not None
736747

737748
def _force_close(self):
@@ -776,24 +787,38 @@ def begin(self):
776787
self._read_ok_packet()
777788

778789
def commit(self):
779-
"""Commit changes to stable storage"""
790+
"""
791+
Commit changes to stable storage.
792+
793+
See `Connection.commit() <https://www.python.org/dev/peps/pep-0249/#commit>`_
794+
in the specification.
795+
"""
780796
self._execute_command(COMMAND.COM_QUERY, "COMMIT")
781797
self._read_ok_packet()
782798

783799
def rollback(self):
784-
"""Roll back the current transaction"""
800+
"""
801+
Roll back the current transaction.
802+
803+
See `Connection.rollback() <https://www.python.org/dev/peps/pep-0249/#rollback>`_
804+
in the specification.
805+
"""
785806
self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
786807
self._read_ok_packet()
787808

788809
def show_warnings(self):
789-
"""SHOW WARNINGS"""
810+
"""Send the "SHOW WARNINGS" SQL command."""
790811
self._execute_command(COMMAND.COM_QUERY, "SHOW WARNINGS")
791812
result = MySQLResult(self)
792813
result.read()
793814
return result.rows
794815

795816
def select_db(self, db):
796-
"""Set current db"""
817+
"""
818+
Set current db.
819+
820+
:param db: The name of the db.
821+
"""
797822
self._execute_command(COMMAND.COM_INIT_DB, db)
798823
self._read_ok_packet()
799824

@@ -831,7 +856,13 @@ def _quote_bytes(self, s):
831856
return converters.escape_bytes(s)
832857

833858
def cursor(self, cursor=None):
834-
"""Create a new cursor to execute queries with"""
859+
"""
860+
Create a new cursor to execute queries with.
861+
862+
:param cursor: The type of cursor to create; one of :py:class:`Cursor`,
863+
:py:class:`SSCursor`, :py:class:`DictCursor`, or :py:class:`SSDictCursor`.
864+
None means use Cursor.
865+
"""
835866
if cursor:
836867
return cursor(self)
837868
return self.cursorclass(self)
@@ -873,7 +904,12 @@ def kill(self, thread_id):
873904
return self._read_ok_packet()
874905

875906
def ping(self, reconnect=True):
876-
"""Check if the server is alive"""
907+
"""
908+
Check if the server is alive.
909+
910+
:param reconnect: If the connection is closed, reconnect.
911+
:raise Error: If the connection is closed and reconnect=False.
912+
"""
877913
if self._sock is None:
878914
if reconnect:
879915
self.connect()
@@ -985,6 +1021,9 @@ def write_packet(self, payload):
9851021
def _read_packet(self, packet_type=MysqlPacket):
9861022
"""Read an entire "mysql packet" in its entirety from the network
9871023
and return a MysqlPacket type that represents the results.
1024+
1025+
:raise OperationalError: If the connection to the MySQL server is lost.
1026+
:raise InternalError: If the packet sequence number is wrong.
9881027
"""
9891028
buff = b''
9901029
while True:
@@ -1071,6 +1110,11 @@ def insert_id(self):
10711110
return 0
10721111

10731112
def _execute_command(self, command, sql):
1113+
"""
1114+
:raise InterfaceError: If the connection is closed.
1115+
:raise ValueError: If no username was specified.
1116+
"""
1117+
10741118
if not self._sock:
10751119
raise err.InterfaceError("(0, '')")
10761120

@@ -1358,6 +1402,10 @@ def read(self):
13581402
self.connection = None
13591403

13601404
def init_unbuffered_query(self):
1405+
"""
1406+
:raise OperationalError: If the connection to the MySQL server is lost.
1407+
:raise InternalError:
1408+
"""
13611409
self.unbuffered_active = True
13621410
first_packet = self.connection._read_packet()
13631411

pymysql/cursors.py

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class Cursor(object):
2424
2525
Do not create an instance of a Cursor yourself. Call
2626
connections.Connection.cursor().
27+
28+
See `Cursor <https://www.python.org/dev/peps/pep-0249/#cursor-objects>`_ in
29+
the specification.
2730
"""
2831

2932
#: Max statement size which :meth:`executemany` generates.

0 commit comments

Comments
 (0)
0