Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use Ruff instead of flake8 #1112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

13 changes: 4 additions & 9 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Lint

on:
push:
branches: ["main"]
paths:
- '**.py'
pull_request:
Expand All @@ -13,16 +14,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.x

- uses: psf/black@stable
with:
options: "--check --verbose"
src: "."
- name: Setup flake8 annotations
uses: rbialon/flake8-annotations@v1
- name: flake8
run: |
pip install flake8
flake8 pymysql

- uses: chartboost/ruff-action@v1
3 changes: 2 additions & 1 deletion pymysql/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def sha2_rsa_encrypt(password, salt, public_key):
"""
if not _have_cryptography:
raise RuntimeError(
"'cryptography' package is required for sha256_password or caching_sha2_password auth methods"
"'cryptography' package is required for sha256_password or"
+ " caching_sha2_password auth methods"
)
message = _xor_password(password + b"\0", salt)
rsa_key = serialization.load_pem_public_key(public_key, default_backend())
Expand Down
15 changes: 10 additions & 5 deletions pymysql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ class Connection:
the interface from which to connect to the host. Argument can be
a hostname or an IP address.
:param unix_socket: Use a unix socket rather than TCP/IP.
:param read_timeout: The timeout for reading from the connection in seconds (default: None - no timeout)
:param write_timeout: The timeout for writing to the connection in seconds (default: None - no timeout)
:param read_timeout: The timeout for reading from the connection in seconds.
(default: None - no timeout)
:param write_timeout: The timeout for writing to the connection in seconds.
(default: None - no timeout)
:param charset: Charset to use.
:param sql_mode: Default SQL_MODE to use.
:param read_default_file:
Expand All @@ -130,7 +132,8 @@ class Connection:
:param ssl_ca: Path to the file that contains a PEM-formatted CA certificate.
:param ssl_cert: Path to the file that contains a PEM-formatted client certificate.
:param ssl_disabled: A boolean value that disables usage of TLS.
:param ssl_key: Path to the file that contains a PEM-formatted private key for the client certificate.
:param ssl_key: Path to the file that contains a PEM-formatted private key for
the client certificate.
:param ssl_verify_cert: Set to true to check the server certificate's validity.
:param ssl_verify_identity: Set to true to check the server's identity.
:param read_default_group: Group to read from in the configuration file.
Expand Down Expand Up @@ -533,7 +536,8 @@ def cursor(self, cursor=None):
Create a new cursor to execute queries with.

:param cursor: The type of cursor to create. None means use Cursor.
:type cursor: :py:class:`Cursor`, :py:class:`SSCursor`, :py:class:`DictCursor`, or :py:class:`SSDictCursor`.
:type cursor: :py:class:`Cursor`, :py:class:`SSCursor`, :py:class:`DictCursor`,
or :py:class:`SSDictCursor`.
"""
if cursor:
return cursor(self)
Expand Down Expand Up @@ -1228,7 +1232,8 @@ def _check_packet_is_eof(self, packet):
# TODO: Support CLIENT.DEPRECATE_EOF
# 1) Add DEPRECATE_EOF to CAPABILITIES
# 2) Mask CAPABILITIES with server_capabilities
# 3) if server_capabilities & CLIENT.DEPRECATE_EOF: use OKPacketWrapper instead of EOFPacketWrapper
# 3) if server_capabilities & CLIENT.DEPRECATE_EOF:
# use OKPacketWrapper instead of EOFPacketWrapper
wp = EOFPacketWrapper(packet)
self.warning_count = wp.warning_count
self.has_next = wp.has_next
Expand Down
5 changes: 4 additions & 1 deletion pymysql/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ def escape_time(obj, mapping=None):

def escape_datetime(obj, mapping=None):
if obj.microsecond:
fmt = "'{0.year:04}-{0.month:02}-{0.day:02} {0.hour:02}:{0.minute:02}:{0.second:02}.{0.microsecond:06}'"
fmt = (
"'{0.year:04}-{0.month:02}-{0.day:02}"
+ " {0.hour:02}:{0.minute:02}:{0.second:02}.{0.microsecond:06}'"
)
else:
fmt = "'{0.year:04}-{0.month:02}-{0.day:02} {0.hour:02}:{0.minute:02}:{0.second:02}'"
return fmt.format(obj)
Expand Down
19 changes: 0 additions & 19 deletions pymysql/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +0,0 @@
# Sorted by alphabetical order
from pymysql.tests.test_DictCursor import *
from pymysql.tests.test_SSCursor import *
from pymysql.tests.test_basic import *
from pymysql.tests.test_connection import *
from pymysql.tests.test_converters import *
from pymysql.tests.test_cursor import *
from pymysql.tests.test_err import *
from pymysql.tests.test_issues import *
from pymysql.tests.test_load_local import *
from pymysql.tests.test_nextset import *
from pymysql.tests.test_optionfile import *

from pymysql.tests.thirdparty import *

if __name__ == "__main__":
import unittest

unittest.main()
1 change: 0 additions & 1 deletion pymysql/tests/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gc
import json
import os
import re
Expand Down
28 changes: 22 additions & 6 deletions pymysql/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import pymysql.cursors
from pymysql.tests import base
from pymysql.err import ProgrammingError


__all__ = ["TestConversion", "TestCursor", "TestBulkInserts"]
Expand All @@ -18,7 +17,22 @@ def test_datatypes(self):
conn = self.connect()
c = conn.cursor()
c.execute(
"create table test_datatypes (b bit, i int, l bigint, f real, s varchar(32), u varchar(32), bb blob, d date, dt datetime, ts timestamp, td time, t time, st datetime)"
"""
create table test_datatypes (
b bit,
i int,
l bigint,
f real,
s varchar(32),
u varchar(32),
bb blob,
d date,
dt datetime,
ts timestamp,
td time,
t time,
st datetime)
"""
)
try:
# insert values
Expand All @@ -38,7 +52,8 @@ def test_datatypes(self):
time.localtime(),
)
c.execute(
"insert into test_datatypes (b,i,l,f,s,u,bb,d,dt,td,t,st) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
"insert into test_datatypes (b,i,l,f,s,u,bb,d,dt,td,t,st) values"
" (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
v,
)
c.execute("select b,i,l,f,s,u,bb,d,dt,td,t,st from test_datatypes")
Expand All @@ -54,7 +69,8 @@ def test_datatypes(self):

# check nulls
c.execute(
"insert into test_datatypes (b,i,l,f,s,u,bb,d,dt,td,t,st) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
"insert into test_datatypes (b,i,l,f,s,u,bb,d,dt,td,t,st)"
" values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
[None] * 12,
)
c.execute("select b,i,l,f,s,u,bb,d,dt,td,t,st from test_datatypes")
Expand Down Expand Up @@ -156,7 +172,8 @@ def test_timedelta(self):
conn = self.connect()
c = conn.cursor()
c.execute(
"select time('12:30'), time('23:12:59'), time('23:12:59.05100'), time('-12:30'), time('-23:12:59'), time('-23:12:59.05100'), time('-00:30')"
"select time('12:30'), time('23:12:59'), time('23:12:59.05100'),"
+ " time('-12:30'), time('-23:12:59'), time('-23:12:59.05100'), time('-00:30')"
)
self.assertEqual(
(
Expand Down Expand Up @@ -317,7 +334,6 @@ class TestBulkInserts(base.PyMySQLTestCase):
def setUp(self):
super(TestBulkInserts, self).setUp()
self.conn = conn = self.connect()
c = conn.cursor(self.cursor_type)

# create a table and some data to query
self.safe_create_table(
Expand Down
Loading