Skip to content

Commit

Permalink
lint cython code
Browse files Browse the repository at this point in the history
  • Loading branch information
chaokunyang committed Dec 20, 2024
1 parent e815aa8 commit 3073e3c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
9 changes: 4 additions & 5 deletions python/pyfury/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
from typing import TypeVar, Union
from enum import Enum

from pyfury._serialization import (
ENABLE_FURY_CYTHON_SERIALIZATION,
ClassInfo,
)
from pyfury._serialization import ENABLE_FURY_CYTHON_SERIALIZATION
from pyfury import Language
from pyfury.error import TypeUnregisteredError

Expand Down Expand Up @@ -81,7 +78,9 @@
logger = logging.getLogger(__name__)


if not ENABLE_FURY_CYTHON_SERIALIZATION:
if ENABLE_FURY_CYTHON_SERIALIZATION:
from pyfury._serialization import ClassInfo
else:

class ClassInfo:
__slots__ = (
Expand Down
16 changes: 16 additions & 0 deletions python/pyfury/_serialization.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ cdef int8_t NOT_NULL_VALUE_FLAG = -1
# this flag indicates that the object is a referencable and first read.
cdef int8_t REF_VALUE_FLAG = 0


@cython.final
cdef class MapRefResolver:
cdef flat_hash_map[uint64_t, int32_t] written_objects_id # id(obj) -> ref_id
Expand Down Expand Up @@ -1050,6 +1051,7 @@ cpdef inline read_nullable_pystr(Buffer buffer):
else:
return None


@cython.final
cdef class SerializationContext:
cdef dict objects
Expand Down Expand Up @@ -1124,6 +1126,7 @@ cdef class ByteSerializer(CrossLanguageCompatibleSerializer):
cpdef inline read(self, Buffer buffer):
return buffer.read_int8()


@cython.final
cdef class Int16Serializer(CrossLanguageCompatibleSerializer):
cpdef inline write(self, Buffer buffer, value):
Expand All @@ -1132,6 +1135,7 @@ cdef class Int16Serializer(CrossLanguageCompatibleSerializer):
cpdef inline read(self, Buffer buffer):
return buffer.read_int16()


@cython.final
cdef class Int32Serializer(CrossLanguageCompatibleSerializer):
cpdef inline write(self, Buffer buffer, value):
Expand All @@ -1140,6 +1144,7 @@ cdef class Int32Serializer(CrossLanguageCompatibleSerializer):
cpdef inline read(self, Buffer buffer):
return buffer.read_int32()


@cython.final
cdef class Int64Serializer(CrossLanguageCompatibleSerializer):
cpdef inline xwrite(self, Buffer buffer, value):
Expand All @@ -1163,6 +1168,7 @@ cdef int64_t INT32_MAX_VALUE = 1 << 31 - 1
cdef float FLOAT32_MIN_VALUE = 1.17549e-38
cdef float FLOAT32_MAX_VALUE = 3.40282e+38


@cython.final
cdef class DynamicIntSerializer(CrossLanguageCompatibleSerializer):
cpdef inline xwrite(self, Buffer buffer, value):
Expand All @@ -1175,6 +1181,7 @@ cdef class DynamicIntSerializer(CrossLanguageCompatibleSerializer):
assert type_id == <int32_t> TypeId.INT64, type_id
return buffer.read_varint64()


@cython.final
cdef class FloatSerializer(CrossLanguageCompatibleSerializer):
cpdef inline write(self, Buffer buffer, value):
Expand Down Expand Up @@ -1214,8 +1221,10 @@ cdef class StringSerializer(CrossLanguageCompatibleSerializer):
cpdef inline read(self, Buffer buffer):
return buffer.read_string()


cdef _base_date = datetime.date(1970, 1, 1)


@cython.final
cdef class DateSerializer(CrossLanguageCompatibleSerializer):
cpdef inline write(self, Buffer buffer, value):
Expand All @@ -1232,6 +1241,7 @@ cdef class DateSerializer(CrossLanguageCompatibleSerializer):
days = buffer.read_int32()
return _base_date + datetime.timedelta(days=days)


@cython.final
cdef class TimestampSerializer(CrossLanguageCompatibleSerializer):
cpdef inline write(self, Buffer buffer, value):
Expand Down Expand Up @@ -1500,6 +1510,7 @@ cdef inline get_next_elenment(
ref_resolver.set_read_object(ref_id, o)
return o


@cython.final
cdef class TupleSerializer(CollectionSerializer):
cpdef inline read(self, Buffer buffer):
Expand Down Expand Up @@ -1554,6 +1565,7 @@ cdef class StringArraySerializer(ListSerializer):
def __init__(self, fury, type_):
super().__init__(fury, type_, StringSerializer(fury, str))


@cython.final
cdef class SetSerializer(CollectionSerializer):
cpdef inline read(self, Buffer buffer):
Expand Down Expand Up @@ -1619,6 +1631,7 @@ cdef class SetSerializer(CollectionSerializer):
))
return instance


@cython.final
cdef class MapSerializer(Serializer):
cdef ClassResolver class_resolver
Expand Down Expand Up @@ -1745,6 +1758,7 @@ cdef class MapSerializer(Serializer):
map_[k] = v
return map_


@cython.final
cdef class SubMapSerializer(Serializer):
cdef ClassResolver class_resolver
Expand Down Expand Up @@ -1833,6 +1847,7 @@ cdef class SubMapSerializer(Serializer):
map_[key] = value
return map_


@cython.final
cdef class EnumSerializer(Serializer):
@classmethod
Expand All @@ -1852,6 +1867,7 @@ cdef class EnumSerializer(Serializer):
cpdef inline xread(self, Buffer buffer):
raise NotImplementedError


@cython.final
cdef class SliceSerializer(Serializer):
cpdef inline write(self, Buffer buffer, v):
Expand Down
7 changes: 3 additions & 4 deletions python/pyfury/includes/libutil.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ from libcpp.string cimport string as c_string

cdef extern from "fury/util/buffer.h" namespace "fury" nogil:
cdef cppclass CStatus" fury::Status":
c_string ToString() const;
c_string ToString() const

c_string CodeAsString() const;
c_string CodeAsString() const

c_string message() const

Expand All @@ -40,7 +40,6 @@ cdef extern from "fury/util/buffer.h" namespace "fury" nogil:
IOError = 6,
UnknownError = 7


cdef cppclass CBuffer" fury::Buffer":
CBuffer(uint8_t* data, uint32_t size, c_bool own_data=True)

Expand Down Expand Up @@ -83,7 +82,7 @@ cdef extern from "fury/util/buffer.h" namespace "fury" nogil:

inline double GetDouble(uint32_t offset)

inline CStatus GetBytesAsInt64(uint32_t offset, uint32_t length, int64_t* target);
inline CStatus GetBytesAsInt64(uint32_t offset, uint32_t length, int64_t* target)

inline uint32_t PutVarUint32(uint32_t offset, int32_t value)

Expand Down
1 change: 0 additions & 1 deletion python/pyfury/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import array
import dataclasses
import enum
import importlib
import inspect

Expand Down

0 comments on commit 3073e3c

Please sign in to comment.