Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14.0-beta.2"]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14.0-beta.4"]
os: ["ubuntu-latest", "windows-latest", "macos-latest"]


Expand All @@ -26,7 +26,7 @@ jobs:
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "0.6.11"
version: "0.8.0"
- name: Run ruff
run: |
uvx ruff check
Expand All @@ -39,7 +39,7 @@ jobs:
uv build
- name: Installing
run: |
uv pip install dist/paramclasses-0.3.7.dev0-py3-none-any.whl
uv pip install dist/paramclasses-0.4.0-py3-none-any.whl
- name: Run pytest with coverage
run: |
uv run pytest --cov-report=xml
Expand Down
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
![OS Independant](https://img.shields.io/badge/OS_Independant-%E2%9C%93-blue)
[![python versions](https://img.shields.io/badge/python-3.10%20|%203.11%20|%203.12%20|%203.13%20|%203.14.0b2-blue)](https://devguide.python.org/versions/)
[![python versions](https://img.shields.io/badge/python-3.10%20|%203.11%20|%203.12%20|%203.13%20|%203.14.0b4-blue)](https://devguide.python.org/versions/)
[![license MIT](https://img.shields.io/github/license/eliegoudout/paramclasses)](https://opensource.org/licenses/MIT)
[![pypi](https://img.shields.io/pypi/v/paramclasses)](https://pypi.org/project/paramclasses/)
[![pipeline status](https://github.com/eliegoudout/paramclasses/actions/workflows/ci.yml/badge.svg)](https://github.com/eliegoudout/paramclasses/actions)
Expand Down Expand Up @@ -214,20 +214,26 @@ is triggered. For example, it can be used to `unfit` and estimator on specific m

#### Instantiation logic with `__post_init__`

Similarly to [dataclasses](https://docs.python.org/3/library/dataclasses.html), a `__post_init__` method can be defined to complete instantiation after the initial setting of parameter values. It must have signature
```python
def __post_init__(self, *args: object, **kwargs: object) -> None
```
and is called as follows by `__init__`.
Similarly to [dataclasses](https://docs.python.org/3/library/dataclasses.html), a `__post_init__` method can be defined to complete instantiation after the initial setting of parameter values. It must **always** return `None`.

In general, it as called as follows by `__init__`.

```python
# Close equivalent to actual implementation
@protected
def __init__(self, args: list[object] = [], kwargs: dict[str, object] = {}, /, **param_values: object) -> None:
self.set_params(**param_values)
self.__post_init__(*args, **kwargs)

def __init__(
self,
post_init_args: list[object] = [],
post_init_kwargs: dict[str, object] = {},
/,
**param_values: object,
) -> None:
"""Close equivalent to actual implementation"""
self.set_params(**param_values)
self.__post_init__(*args, **kwargs)
```

**Note however** that if `__post_init__` does not accept positional (_resp._ keyword) arguments, then `post_init_args`(_resp._ `post_init_kwargs`) is removed from `__init__`'s signature. In any case, you can check the signature with `inspect.signature(your_paramclass)`.

Since parameter values are set before `__post_init__` is called, they are accessible when it executes. Note that even if a _paramclass_ does not define `__post_init__`, its bases might, in which case it is used.

Additionally, both `@staticmethod` and `@classmethod` decorators are supported decorators for `__post_init__` declaration. In other cases, the `__signature__` property may fail.
Expand All @@ -237,13 +243,16 @@ Additionally, both `@staticmethod` and `@classmethod` decorators are supported d
#### Abstract methods

The base `ParamClass` already inherits `ABC` functionalities, so `@abstractmethod` can be used.

```python
from abc import abstractmethod

class A(ParamClass):
@abstractmethod
def next(self): ...

```

```pycon
>>> A()
<traceback>
Expand Down
Loading
Loading