Skip to content

Commit

Permalink
#114 Remove kw_onl default to True
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhad6 committed Aug 30, 2023
1 parent 9a44282 commit 853a9cd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ on:
- develop

env:
POETRY_VERSION: "1.6.1"
MAIN_PYTHON_VERSION: "3.9"
POETRY_VERSION: "1.5.1"

jobs:
ci:
strategy:
matrix:
python_version: ["3.9", "3.10"]
python_version: ["3.9", "3.10", "3.11"]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -33,9 +33,6 @@ jobs:
python-version: ${{ matrix.python_version }}
cache: poetry

- name: Check Python version
run: poetry run python --version

- name: Install dependencies
run: poetry install --all-extras --without docs

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ on:
types: [published]

env:
PYTHON_VERSION: "3.10"
POETRY_VERSION: "1.5.1"
POETRY_VERSION: "1.6.1"

jobs:
build:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Support for Python 3.9

### Removed

- Parameter dataclass bases (`Param` and `Struct`) no longer set `kw_only` to True by
default (since this feature does not exist in Python 3.9).

## [0.9.1] (Aug 9 2023)

### Changed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ParamDB

[![PyPI Latest Release](https://img.shields.io/pypi/v/paramdb)](https://pypi.org/project/paramdb/)
![PyPI Python Versions](https://img.shields.io/pypi/pyversions/paramdb)
[![License](https://img.shields.io/pypi/l/paramdb)](https://github.com/PainterQubits/paramdb/blob/main/LICENSE)
[![CI](https://github.com/PainterQubits/paramdb/actions/workflows/ci.yml/badge.svg)](https://github.com/PainterQubits/paramdb/actions/workflows/ci.yml)
[![Codecov](https://codecov.io/github/PainterQubits/paramdb/branch/main/graph/badge.svg?token=PQEJWLBTBK)](https://codecov.io/github/PainterQubits/paramdb)
Expand Down
18 changes: 12 additions & 6 deletions docs/parameter-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,24 @@ param.value
The dataclass aspects of the subclass can be customized by passing keyword arguments when
defining the custom class (the same arguments that would be passed to the [`@dataclass`]
decorator), and by using the dataclass [`field`] function. The class arguments have the
same default values as in [`@dataclass`], except `kw_only` is True by default for
ParamDB dataclasses to facilitate dataclass inheritance with default values. An example of
dataclass customization is shown below.
same default values as in [`@dataclass`]. An example of dataclass customization is shown
below.

```{note}
The `kw_only` setting below only works in Python 3.10, but is useful for defining
non-default arguments after those with default values (like in the example), especially
when building up dataclasses through inheritance.
```

```{jupyter-execute}
from dataclasses import field
class CustomizedDataclassParam(Param, kw_only=False, repr=False):
class CustomizedDataclassParam(Param, kw_only=True):
values: list[int] = field(default_factory=list)
count: int
customized_dataclass_param = CustomizedDataclassParam([1, 2, 3])
customized_dataclass_param.values
customized_dataclass_param = CustomizedDataclassParam(count=123)
customized_dataclass_param
```

```{warning}
Expand Down
6 changes: 3 additions & 3 deletions paramdb/_param_data/_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from paramdb._param_data._param_data import ParamData


@dataclass_transform(kw_only_default=True)
@dataclass_transform()
class _ParamDataclass(ParamData):
"""
Base class for parameter dataclasses.
Expand All @@ -19,10 +19,10 @@ class _ParamDataclass(ParamData):
constructor.
"""

def __init_subclass__(cls, /, kw_only: bool = True, **kwargs: Any) -> None:
def __init_subclass__(cls, /, **kwargs: Any) -> None:
# Convert subclasses into dataclasses
super().__init_subclass__() # kwargs are passed to dataclass constructor
dataclass(kw_only=kw_only, **kwargs)(cls)
dataclass(**kwargs)(cls)

def __getitem__(self, name: str) -> Any:
# Enable getting attributes via indexing
Expand Down

0 comments on commit 853a9cd

Please sign in to comment.