Skip to content

Commit 6b8f064

Browse files
committed
Use dataclass where applicable; add 'make test' to Makefile
1 parent 25376cb commit 6b8f064

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: check
1+
.PHONY: check test
22

33
RUFF_VERSION ?= 0.14.13
44
RUFF = uvx ruff@$(RUFF_VERSION)
@@ -10,3 +10,7 @@ check:
1010
$(RUFF) check .
1111
$(TY) check
1212
$(RUFF) format .
13+
14+
test:
15+
python3 -m unittest discover
16+

pycparser/c_lexer.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
from typing import Callable, Dict, List, Optional, Tuple
1313

1414

15+
@dataclass(slots=True)
1516
class _Token:
16-
__slots__ = ("type", "value", "lineno", "column")
17-
18-
def __init__(self, typ: str, value: str, lineno: int, column: int) -> None:
19-
self.type = typ
20-
self.value = value
21-
self.lineno = lineno
22-
self.column = column
17+
type: str
18+
value: str
19+
lineno: int
20+
column: int
2321

2422

2523
class CLexer:

pycparser/c_parser.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Eli Bendersky [https://eli.thegreenplace.net/]
77
# License: BSD
88
# ------------------------------------------------------------------------------
9+
from dataclasses import dataclass
910
from typing import (
1011
Any,
1112
Dict,
@@ -23,23 +24,17 @@
2324
from .ast_transforms import fix_switch_cases, fix_atomic_specifiers
2425

2526

27+
@dataclass
2628
class Coord:
2729
"""Coordinates of a syntactic element. Consists of:
2830
- File name
2931
- Line number
3032
- Column number
3133
"""
3234

33-
__slots__ = ("file", "line", "column", "__weakref__")
34-
3535
file: str
3636
line: int
37-
column: Optional[int]
38-
39-
def __init__(self, file: str, line: int, column: Optional[int] = None) -> None:
40-
self.file = file
41-
self.line = line
42-
self.column = column
37+
column: Optional[int] = None
4338

4439
def __str__(self) -> str:
4540
text = f"{self.file}:{self.line}"

0 commit comments

Comments
 (0)