Skip to content

Commit 32dee44

Browse files
committed
fix cython build
1 parent b3bc1c8 commit 32dee44

File tree

2 files changed

+19
-59
lines changed

2 files changed

+19
-59
lines changed

logwrap/repr_utils.pxd

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,48 +19,8 @@ available from the main module.
1919
"""
2020

2121
# Standard Library
22-
import dataclasses
2322
import types
2423
import typing
25-
from collections.abc import Iterable
26-
27-
28-
@typing.runtime_checkable
29-
class _AttributeHolderProto(typing.Protocol):
30-
__slots__ = ()
31-
32-
def _get_kwargs(self) -> list[tuple[str, typing.Any]]:
33-
"""Protocol stub."""
34-
35-
def _get_args(self) -> list[str]:
36-
"""Protocol stub."""
37-
38-
39-
@typing.runtime_checkable
40-
class _NamedTupleProto(typing.Protocol):
41-
__slots__ = ()
42-
43-
def _asdict(self) -> dict[str, typing.Any]:
44-
"""Protocol stub."""
45-
46-
def __getnewargs__(self) -> tuple[typing.Any, ...]:
47-
"""Protocol stub."""
48-
49-
def _replace(self, **kwds: dict[str, typing.Any]) -> _NamedTupleProto:
50-
"""Protocol stub."""
51-
52-
@classmethod
53-
def _make(cls, iterable: Iterable[typing.Any]) -> _NamedTupleProto:
54-
"""Protocol stub."""
55-
56-
57-
@typing.runtime_checkable
58-
class _DataClassProto(typing.Protocol):
59-
__slots__ = ()
60-
61-
__dataclass_params__: dataclasses._DataclassParams # type: ignore[name-defined]
62-
__dataclass_fields__: dict[str, dataclasses.Field[typing.Any]] = {}
63-
6424

6525
cdef:
6626
bint _known_callable(item: typing.Any)
@@ -101,9 +61,9 @@ cdef:
10161

10262
cdef:
10363
str _repr_callable(self, src: typing.Union[types.FunctionType, types.MethodType], unsigned long indent=?)
104-
str _repr_attribute_holder(self, src: _AttributeHolderProto, unsigned long indent=?, bint no_indent_start=?)
105-
str _repr_named_tuple(self, src: _NamedTupleProto, unsigned long indent=?, bint no_indent_start=?)
106-
str _repr_dataclass(self, src: _DataClassProto, unsigned long indent=?, bint no_indent_start=?)
64+
str _repr_attribute_holder(self, object src, unsigned long indent=?, bint no_indent_start=?)
65+
str _repr_named_tuple(self, object src, unsigned long indent=?, bint no_indent_start=?)
66+
str _repr_dataclass(self, object src, unsigned long indent=?, bint no_indent_start=?)
10767
str _repr_simple(self, src: typing.Any, unsigned long indent=?, bint no_indent_start=?)
10868
str _repr_iterable_item(self, str obj_type, str prefix, unsigned long indent, bint no_indent_start, str result, str suffix)
10969
str _repr_iterable_items(self, src: typing.Iterable, unsigned long indent=?)

logwrap/repr_utils.pyx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ available from the main module.
2020

2121
# Standard Library
2222
import collections
23-
import dataclasses
2423
import inspect
2524
import types
2625
import typing
@@ -35,37 +34,37 @@ _SIMPLE_MAGIC_ATTRIBUTES = ("__repr__", "__str__")
3534
class _AttributeHolderProto(typing.Protocol):
3635
__slots__ = ()
3736

38-
def _get_kwargs(self) -> list[tuple[str, typing.Any]]:
37+
def _get_kwargs(self) -> list:
3938
"""Protocol stub."""
4039

41-
def _get_args(self) -> list[str]:
40+
def _get_args(self) -> list:
4241
"""Protocol stub."""
4342

4443

4544
@typing.runtime_checkable
4645
class _NamedTupleProto(typing.Protocol):
4746
__slots__ = ()
4847

49-
def _asdict(self) -> dict[str, typing.Any]:
48+
def _asdict(self) -> dict:
5049
"""Protocol stub."""
5150

52-
def __getnewargs__(self) -> tuple[typing.Any, ...]:
51+
def __getnewargs__(self) -> tuple:
5352
"""Protocol stub."""
5453

55-
def _replace(self, **kwds: dict[str, typing.Any]) -> _NamedTupleProto:
54+
def _replace(self, **kwds: dict):
5655
"""Protocol stub."""
5756

5857
@classmethod
59-
def _make(cls, iterable: Iterable[typing.Any]) -> _NamedTupleProto:
58+
def _make(cls, iterable: Iterable):
6059
"""Protocol stub."""
6160

6261

6362
@typing.runtime_checkable
6463
class _DataClassProto(typing.Protocol):
6564
__slots__ = ()
6665

67-
__dataclass_params__: dataclasses._DataclassParams # type: ignore[name-defined]
68-
__dataclass_fields__: dict[str, dataclasses.Field[typing.Any]] = {}
66+
__dataclass_params__: typing.Any
67+
__dataclass_fields__: typing.Any = {}
6968

7069
cdef:
7170
bint _known_callable(item: typing.Any):
@@ -239,8 +238,9 @@ cdef class PrettyFormat:
239238
param_str += " = "
240239
else:
241240
param_str += "="
242-
cdef:
243-
value = self.process_element(src=param.value, indent=next_indent, no_indent_start=True)
241+
242+
value = self.process_element(src=param.value, indent=next_indent, no_indent_start=True)
243+
244244
param_str += value
245245
param_str += ","
246246

@@ -284,18 +284,18 @@ cdef class PrettyFormat:
284284
str prefix = "\n" + " " * next_indent
285285

286286
for arg in src._get_args(): # pylint: disable=protected-access
287-
cdef repr_val = self.process_element(arg, indent=next_indent)
287+
repr_val = self.process_element(arg, indent=next_indent)
288288
param_repr.append(f"{prefix}{repr_val},")
289289

290290
for name, value in src._get_kwargs(): # pylint: disable=protected-access
291291
if name.isidentifier():
292-
cdef repr_val = self.process_element(value, indent=next_indent, no_indent_start=True)
292+
repr_val = self.process_element(value, indent=next_indent, no_indent_start=True)
293293
param_repr.append(f"{prefix}{name}={repr_val},")
294294
else:
295295
star_args[name] = value
296296

297297
if star_args:
298-
cdef repr_val = self.process_element(star_args, indent=next_indent, no_indent_start=True)
298+
repr_val = self.process_element(star_args, indent=next_indent, no_indent_start=True)
299299
param_repr.append(f"{prefix}**{repr_val},")
300300

301301
if param_repr:
@@ -332,7 +332,7 @@ cdef class PrettyFormat:
332332
str prefix = "\n" + " " * next_indent
333333

334334
for arg_name, value in src._asdict().items():
335-
cdef repr_val = self.process_element(value, indent=next_indent, no_indent_start=True)
335+
repr_val = self.process_element(value, indent=next_indent, no_indent_start=True)
336336
param_repr.append(f"{prefix}{arg_name}={repr_val},")
337337
if arg_name in args_annotations and not isinstance(
338338
getattr(args_annotations, arg_name, None), typing.ForwardRef
@@ -371,7 +371,7 @@ cdef class PrettyFormat:
371371
for arg_name, field in src.__dataclass_fields__.items():
372372
if not field.repr:
373373
continue
374-
cdef repr_val = self.process_element(getattr(src, arg_name), indent=next_indent, no_indent_start=True)
374+
repr_val = self.process_element(getattr(src, arg_name), indent=next_indent, no_indent_start=True)
375375

376376
comment: list[str] = []
377377

0 commit comments

Comments
 (0)