Skip to content

Commit

Permalink
Support and test internal fields on Python up to 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiostalla committed Oct 10, 2023
1 parent 09fa127 commit 7821a79
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
strategy:
matrix:
python: [ '3.7', '3.8', '3.9', '3.10', '3.11' ]
python: [ '3.7', '3.8', '3.9', '3.10', '3.11', '3.12' ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
9 changes: 7 additions & 2 deletions pylasu/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ class InternalField(Field):


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

if default is not MISSING and default_factory is not MISSING:
raise ValueError('cannot specify both default and default_factory')
return InternalField(default, default_factory, init, repr, hash, compare, metadata)
try:
# Python 3.10+
return InternalField(default, default_factory, init, repr, hash, compare, metadata, kw_only)
except:
return InternalField(default, default_factory, init, repr, hash, compare, metadata)


class Origin(ABC):
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from dataclasses import dataclass, field
from typing import List

from pylasu.model import Node, pos
from pylasu.model import Node, pos, internal_field


@dataclass
class Box(Node):
name: str = None
contents: List[Node] = field(default_factory=list)
internal: str = internal_field(default="unused")


@dataclass
Expand Down

0 comments on commit 7821a79

Please sign in to comment.