Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed May 6, 2024
1 parent 949201e commit 1372686
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 48 deletions.
12 changes: 6 additions & 6 deletions msgpack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from .exceptions import *
from .ext import ExtType, Timestamp

# ruff: noqa: F401
import os

from .exceptions import * # noqa: F403
from .ext import ExtType, Timestamp

version = (1, 0, 8)
__version__ = "1.0.8"


if os.environ.get("MSGPACK_PUREPYTHON"):
from .fallback import Packer, unpackb, Unpacker
from .fallback import Packer, Unpacker, unpackb
else:
try:
from ._cmsgpack import Packer, unpackb, Unpacker
from ._cmsgpack import Packer, Unpacker, unpackb
except ImportError:
from .fallback import Packer, unpackb, Unpacker
from .fallback import Packer, Unpacker, unpackb


def pack(o, stream, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion msgpack/ext.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import namedtuple
import datetime
import struct
from collections import namedtuple


class ExtType(namedtuple("ExtType", "code data")):
Expand Down
17 changes: 8 additions & 9 deletions msgpack/fallback.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Fallback pure Python implementation of msgpack"""

from datetime import datetime as _DateTime
import sys
import struct

import sys
from datetime import datetime as _DateTime

if hasattr(sys, "pypy_version_info"):
from __pypy__ import newlist_hint
Expand Down Expand Up @@ -32,13 +31,14 @@ def getvalue(self):
else:
from io import BytesIO

newlist_hint = lambda size: []
_USING_STRINGBUILDER = False

def newlist_hint(size):
return []

from .exceptions import BufferFull, OutOfData, ExtraData, FormatError, StackError
from .ext import ExtType, Timestamp

from .exceptions import BufferFull, ExtraData, FormatError, OutOfData, StackError
from .ext import ExtType, Timestamp

EX_SKIP = 0
EX_CONSTRUCT = 1
Expand Down Expand Up @@ -669,9 +669,8 @@ def __init__(
self._buffer = BytesIO()
self._datetime = bool(datetime)
self._unicode_errors = unicode_errors or "strict"
if default is not None:
if not callable(default):
raise TypeError("default must be callable")
if not callable(default):
raise TypeError("default must be callable")
self._default = default

def _pack(
Expand Down
14 changes: 11 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@ version = {attr = "msgpack.__version__"}
line-length = 100
target-version = "py38"
lint.ignore = []
lint.select = [
# pycodestyle
"E",
# Pyflakes
"F",
# isort
"I",
# pyupgrade
#"UP",
]

[tool.ruff.lint.per-file-ignores]
"msgpack/__init__.py" = ["F401", "F403"]
"msgpack/fallback.py" = ["E731"]
"test/test_seq.py" = ["E501"]
#"msgpack/__init__.py" = ["F401", "F403"]
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python
import os
import sys
from setuptools import setup, Extension

from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext
from setuptools.command.sdist import sdist


PYPY = hasattr(sys, "pypy_version_info")


Expand Down
2 changes: 1 addition & 1 deletion test/test_buffer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pytest import raises

from msgpack import packb, unpackb, Packer
from msgpack import Packer, packb, unpackb


def test_unpack_buffer():
Expand Down
5 changes: 3 additions & 2 deletions test/test_except.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python

import datetime

from pytest import raises
from msgpack import packb, unpackb, Unpacker, FormatError, StackError, OutOfData

import datetime
from msgpack import FormatError, OutOfData, StackError, Unpacker, packb, unpackb


class DummyException(Exception):
Expand Down
1 change: 1 addition & 0 deletions test/test_extension.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import array

import msgpack
from msgpack import ExtType

Expand Down
8 changes: 4 additions & 4 deletions test/test_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import pytest

from msgpack import (
packb,
unpackb,
Packer,
Unpacker,
ExtType,
Packer,
PackOverflowError,
PackValueError,
Unpacker,
UnpackValueError,
packb,
unpackb,
)


Expand Down
1 change: 1 addition & 0 deletions test/test_memoryview.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

from array import array

from msgpack import packb, unpackb


Expand Down
2 changes: 1 addition & 1 deletion test/test_newspec.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from msgpack import packb, unpackb, ExtType
from msgpack import ExtType, packb, unpackb


def test_str8():
Expand Down
1 change: 1 addition & 0 deletions test/test_obj.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

from pytest import raises

from msgpack import packb, unpackb


Expand Down
4 changes: 2 additions & 2 deletions test/test_pack.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python

import struct
from collections import OrderedDict
from io import BytesIO
import struct

import pytest

from msgpack import packb, unpackb, Unpacker, Packer
from msgpack import Packer, Unpacker, packb, unpackb


def check(data, use_list=False):
Expand Down
2 changes: 1 addition & 1 deletion test/test_read_size.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test Unpacker's read_array_header and read_map_header methods"""

from msgpack import packb, Unpacker, OutOfData
from msgpack import OutOfData, Unpacker, packb

UnexpectedTypeException = ValueError

Expand Down
6 changes: 3 additions & 3 deletions test/test_seq.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python

# ruff: noqa: E501
# ignore line length limit for long comments
import io
import msgpack

import msgpack

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

Expand Down
7 changes: 4 additions & 3 deletions test/test_sequnpack.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
import io
from msgpack import Unpacker, BufferFull
from msgpack import pack, packb
from msgpack.exceptions import OutOfData

from pytest import raises

from msgpack import BufferFull, Unpacker, pack, packb
from msgpack.exceptions import OutOfData


def test_partialdata():
unpacker = Unpacker()
Expand Down
3 changes: 2 additions & 1 deletion test/test_stricttype.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import namedtuple
from msgpack import packb, unpackb, ExtType

from msgpack import ExtType, packb, unpackb


def test_namedtuple():
Expand Down
3 changes: 2 additions & 1 deletion test/test_subtype.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python

from msgpack import packb
from collections import namedtuple

from msgpack import packb


class MyList(list):
pass
Expand Down
4 changes: 3 additions & 1 deletion test/test_timestamp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
import datetime

import pytest

import msgpack
from msgpack.ext import Timestamp

Expand Down
11 changes: 4 additions & 7 deletions test/test_unpack.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from io import BytesIO
import sys
from msgpack import Unpacker, packb, OutOfData, ExtType
from pytest import raises, mark
from io import BytesIO

from pytest import mark, raises

try:
from itertools import izip as zip
except ImportError:
pass
from msgpack import ExtType, OutOfData, Unpacker, packb


def test_unpack_array_header_from_file():
Expand Down

0 comments on commit 1372686

Please sign in to comment.