Skip to content

Commit 7821a79

Browse files
committed
Support and test internal fields on Python up to 3.12
1 parent 09fa127 commit 7821a79

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

.github/workflows/pythonapp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
build:
77
strategy:
88
matrix:
9-
python: [ '3.7', '3.8', '3.9', '3.10', '3.11' ]
9+
python: [ '3.7', '3.8', '3.9', '3.10', '3.11', '3.12' ]
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v3

pylasu/model/model.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@ class InternalField(Field):
2525

2626

2727
def internal_field(
28-
*, default=MISSING, default_factory=MISSING, init=True, repr=True, hash=None, compare=True, metadata=None):
28+
*, default=MISSING, default_factory=MISSING, init=True, repr=True, hash=None, compare=True, metadata=None,
29+
kw_only=False):
2930
"""Return an object to identify internal dataclass fields. The arguments are the same as dataclasses.field."""
3031

3132
if default is not MISSING and default_factory is not MISSING:
3233
raise ValueError('cannot specify both default and default_factory')
33-
return InternalField(default, default_factory, init, repr, hash, compare, metadata)
34+
try:
35+
# Python 3.10+
36+
return InternalField(default, default_factory, init, repr, hash, compare, metadata, kw_only)
37+
except:
38+
return InternalField(default, default_factory, init, repr, hash, compare, metadata)
3439

3540

3641
class Origin(ABC):

tests/fixtures.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from dataclasses import dataclass, field
22
from typing import List
33

4-
from pylasu.model import Node, pos
4+
from pylasu.model import Node, pos, internal_field
55

66

77
@dataclass
88
class Box(Node):
99
name: str = None
1010
contents: List[Node] = field(default_factory=list)
11+
internal: str = internal_field(default="unused")
1112

1213

1314
@dataclass

0 commit comments

Comments
 (0)