Skip to content

Commit 1372686

Browse files
committedMay 6, 2024
code cleanup
1 parent 949201e commit 1372686

20 files changed

+61
-48
lines changed
 

‎msgpack/__init__.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
from .exceptions import *
2-
from .ext import ExtType, Timestamp
3-
1+
# ruff: noqa: F401
42
import os
53

4+
from .exceptions import * # noqa: F403
5+
from .ext import ExtType, Timestamp
66

77
version = (1, 0, 8)
88
__version__ = "1.0.8"
99

1010

1111
if os.environ.get("MSGPACK_PUREPYTHON"):
12-
from .fallback import Packer, unpackb, Unpacker
12+
from .fallback import Packer, Unpacker, unpackb
1313
else:
1414
try:
15-
from ._cmsgpack import Packer, unpackb, Unpacker
15+
from ._cmsgpack import Packer, Unpacker, unpackb
1616
except ImportError:
17-
from .fallback import Packer, unpackb, Unpacker
17+
from .fallback import Packer, Unpacker, unpackb
1818

1919

2020
def pack(o, stream, **kwargs):

‎msgpack/ext.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from collections import namedtuple
21
import datetime
32
import struct
3+
from collections import namedtuple
44

55

66
class ExtType(namedtuple("ExtType", "code data")):

‎msgpack/fallback.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"""Fallback pure Python implementation of msgpack"""
22

3-
from datetime import datetime as _DateTime
4-
import sys
53
import struct
6-
4+
import sys
5+
from datetime import datetime as _DateTime
76

87
if hasattr(sys, "pypy_version_info"):
98
from __pypy__ import newlist_hint
@@ -32,13 +31,14 @@ def getvalue(self):
3231
else:
3332
from io import BytesIO
3433

35-
newlist_hint = lambda size: []
3634
_USING_STRINGBUILDER = False
3735

36+
def newlist_hint(size):
37+
return []
3838

39-
from .exceptions import BufferFull, OutOfData, ExtraData, FormatError, StackError
40-
from .ext import ExtType, Timestamp
4139

40+
from .exceptions import BufferFull, ExtraData, FormatError, OutOfData, StackError
41+
from .ext import ExtType, Timestamp
4242

4343
EX_SKIP = 0
4444
EX_CONSTRUCT = 1
@@ -669,9 +669,8 @@ def __init__(
669669
self._buffer = BytesIO()
670670
self._datetime = bool(datetime)
671671
self._unicode_errors = unicode_errors or "strict"
672-
if default is not None:
673-
if not callable(default):
674-
raise TypeError("default must be callable")
672+
if not callable(default):
673+
raise TypeError("default must be callable")
675674
self._default = default
676675

677676
def _pack(

‎pyproject.toml

+11-3
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,16 @@ version = {attr = "msgpack.__version__"}
4949
line-length = 100
5050
target-version = "py38"
5151
lint.ignore = []
52+
lint.select = [
53+
# pycodestyle
54+
"E",
55+
# Pyflakes
56+
"F",
57+
# isort
58+
"I",
59+
# pyupgrade
60+
#"UP",
61+
]
5262

5363
[tool.ruff.lint.per-file-ignores]
54-
"msgpack/__init__.py" = ["F401", "F403"]
55-
"msgpack/fallback.py" = ["E731"]
56-
"test/test_seq.py" = ["E501"]
64+
#"msgpack/__init__.py" = ["F401", "F403"]

‎setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env python
22
import os
33
import sys
4-
from setuptools import setup, Extension
4+
5+
from setuptools import Extension, setup
56
from setuptools.command.build_ext import build_ext
67
from setuptools.command.sdist import sdist
78

8-
99
PYPY = hasattr(sys, "pypy_version_info")
1010

1111

‎test/test_buffer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pytest import raises
22

3-
from msgpack import packb, unpackb, Packer
3+
from msgpack import Packer, packb, unpackb
44

55

66
def test_unpack_buffer():

‎test/test_except.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env python
22

3+
import datetime
4+
35
from pytest import raises
4-
from msgpack import packb, unpackb, Unpacker, FormatError, StackError, OutOfData
56

6-
import datetime
7+
from msgpack import FormatError, OutOfData, StackError, Unpacker, packb, unpackb
78

89

910
class DummyException(Exception):

‎test/test_extension.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import array
2+
23
import msgpack
34
from msgpack import ExtType
45

‎test/test_limits.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import pytest
33

44
from msgpack import (
5-
packb,
6-
unpackb,
7-
Packer,
8-
Unpacker,
95
ExtType,
6+
Packer,
107
PackOverflowError,
118
PackValueError,
9+
Unpacker,
1210
UnpackValueError,
11+
packb,
12+
unpackb,
1313
)
1414

1515

‎test/test_memoryview.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22

33
from array import array
4+
45
from msgpack import packb, unpackb
56

67

‎test/test_newspec.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from msgpack import packb, unpackb, ExtType
1+
from msgpack import ExtType, packb, unpackb
22

33

44
def test_str8():

‎test/test_obj.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22

33
from pytest import raises
4+
45
from msgpack import packb, unpackb
56

67

‎test/test_pack.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env python
22

3+
import struct
34
from collections import OrderedDict
45
from io import BytesIO
5-
import struct
66

77
import pytest
88

9-
from msgpack import packb, unpackb, Unpacker, Packer
9+
from msgpack import Packer, Unpacker, packb, unpackb
1010

1111

1212
def check(data, use_list=False):

‎test/test_read_size.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Test Unpacker's read_array_header and read_map_header methods"""
22

3-
from msgpack import packb, Unpacker, OutOfData
3+
from msgpack import OutOfData, Unpacker, packb
44

55
UnexpectedTypeException = ValueError
66

‎test/test_seq.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!/usr/bin/env python
2-
1+
# ruff: noqa: E501
2+
# ignore line length limit for long comments
33
import io
4-
import msgpack
54

5+
import msgpack
66

77
binarydata = bytes(bytearray(range(256)))
88

‎test/test_sequnpack.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python
22
import io
3-
from msgpack import Unpacker, BufferFull
4-
from msgpack import pack, packb
5-
from msgpack.exceptions import OutOfData
3+
64
from pytest import raises
75

6+
from msgpack import BufferFull, Unpacker, pack, packb
7+
from msgpack.exceptions import OutOfData
8+
89

910
def test_partialdata():
1011
unpacker = Unpacker()

‎test/test_stricttype.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections import namedtuple
2-
from msgpack import packb, unpackb, ExtType
2+
3+
from msgpack import ExtType, packb, unpackb
34

45

56
def test_namedtuple():

‎test/test_subtype.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env python
22

3-
from msgpack import packb
43
from collections import namedtuple
54

5+
from msgpack import packb
6+
67

78
class MyList(list):
89
pass

‎test/test_timestamp.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import pytest
21
import datetime
2+
3+
import pytest
4+
35
import msgpack
46
from msgpack.ext import Timestamp
57

‎test/test_unpack.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
from io import BytesIO
21
import sys
3-
from msgpack import Unpacker, packb, OutOfData, ExtType
4-
from pytest import raises, mark
2+
from io import BytesIO
3+
4+
from pytest import mark, raises
55

6-
try:
7-
from itertools import izip as zip
8-
except ImportError:
9-
pass
6+
from msgpack import ExtType, OutOfData, Unpacker, packb
107

118

129
def test_unpack_array_header_from_file():

0 commit comments

Comments
 (0)