From 783adc3c610e7476cb408bfa177fa8eb96171013 Mon Sep 17 00:00:00 2001 From: Willi Sontopski <32729196+LostInDarkMath@users.noreply.github.com> Date: Fri, 8 Aug 2025 11:45:53 +0200 Subject: [PATCH 1/5] fix `WithDecoratedMethods` --- CHANGELOG.md | 3 +++ pedantic/mixins/with_decorated_methods.py | 11 ++++++----- pedantic/tests/test_with_decorated_methods.py | 11 +++++++++++ pyproject.toml | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aae03b1..a192f79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +## Pedantic 2.2.3 +- fix `WithDecoratedMethods` + ## Pedantic 2.2.2 - fix `GenericMixin` diff --git a/pedantic/mixins/with_decorated_methods.py b/pedantic/mixins/with_decorated_methods.py index 9c7826c..7a86abf 100644 --- a/pedantic/mixins/with_decorated_methods.py +++ b/pedantic/mixins/with_decorated_methods.py @@ -11,13 +11,14 @@ class DecoratorType(StrEnum): The values of this enum are used as property names and the properties are added to the decorated functions. So I would recommend naming them with a leading underscore to keep them private and also write it lowercase. + Example: >>> class Decorators(DecoratorType): ... FOO = '_foo' """ -E = TypeVar('E', bound=DecoratorType) +DecoratorTypeVar = TypeVar('DecoratorTypeVar', bound=DecoratorType) T = TypeVar('T') C = TypeVar('C', bound=Callable) @@ -45,7 +46,7 @@ def fun(f: C) -> C: return decorator -class WithDecoratedMethods(ABC, Generic[E], GenericMixin): +class WithDecoratedMethods(ABC, Generic[DecoratorTypeVar], GenericMixin): """ A mixin that is used to figure out which method is decorated with custom parameterized decorators. Example: @@ -79,12 +80,12 @@ class WithDecoratedMethods(ABC, Generic[E], GenericMixin): } """ - def get_decorated_functions(self) -> dict[E, dict[C, T]]: - decorator_types = self.type_var + def get_decorated_functions(self) -> dict[DecoratorTypeVar, dict[C, T]]: + decorator_types = self.type_vars[DecoratorTypeVar] decorated_functions = {t: dict() for t in decorator_types} # type: ignore for attribute_name in dir(self): - if attribute_name.startswith('__'): + if attribute_name.startswith('__') or attribute_name in ['type_var', 'type_vars']: continue attribute = getattr(self, attribute_name) diff --git a/pedantic/tests/test_with_decorated_methods.py b/pedantic/tests/test_with_decorated_methods.py index b095712..b05325c 100644 --- a/pedantic/tests/test_with_decorated_methods.py +++ b/pedantic/tests/test_with_decorated_methods.py @@ -1,8 +1,10 @@ import unittest from functools import wraps +from typing import TypeVar, Generic from pedantic import DecoratorType, create_decorator, WithDecoratedMethods +T = TypeVar('T') class Decorators(DecoratorType): FOO = '_foo' @@ -96,3 +98,12 @@ def m1(self) -> int: assert instance.get_decorated_functions() == expected assert instance.m1() == 4422 # check that transformation was applied + + def test_with_decorated_methods_can_have_generic_child_class(self): + class MyClass(Generic[T], WithDecoratedMethods[Decorators]): + @foo(42) + def m1(self) -> None: ... + + instance = MyClass[int]() + actual = instance.get_decorated_functions() + assert actual == {Decorators.FOO: {instance.m1: 42}, Decorators.BAR: {}} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index a59938b..92ecf82 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "pedantic" -version = "2.2.2" +version = "2.2.3" description = "Some useful Python decorators for cleaner software development." readme = "README.md" requires-python = ">=3.11" From 7672c916f1383ca7af318cf5986990447935b09c Mon Sep 17 00:00:00 2001 From: Willi Sontopski <32729196+LostInDarkMath@users.noreply.github.com> Date: Fri, 8 Aug 2025 11:50:26 +0200 Subject: [PATCH 2/5] added `3.14.0-rc.1` to CI test matrix --- .github/workflows/main.yml | 2 +- CHANGELOG.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 85ce5ac..42e3d99 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.11, 3.12, 3.13] + python-version: [3.11, 3.12, 3.13, 3.14.0-rc.1] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} diff --git a/CHANGELOG.md b/CHANGELOG.md index a192f79..fa18098 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Changelog ## Pedantic 2.2.3 +- added `3.14.0-rc.1` to CI test matrix - fix `WithDecoratedMethods` ## Pedantic 2.2.2 From f9e2e64548fbbe4ba7dc25774af2718761fec335 Mon Sep 17 00:00:00 2001 From: Willi Sontopski <32729196+LostInDarkMath@users.noreply.github.com> Date: Fri, 8 Aug 2025 11:52:58 +0200 Subject: [PATCH 3/5] remove support for deprecated `typing.ByteString` --- CHANGELOG.md | 1 + pedantic/type_checking_logic/check_types.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa18098..04d3251 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Pedantic 2.2.3 - added `3.14.0-rc.1` to CI test matrix +- remove support for deprecated `typing.ByteString` - fix `WithDecoratedMethods` ## Pedantic 2.2.2 diff --git a/pedantic/type_checking_logic/check_types.py b/pedantic/type_checking_logic/check_types.py index 32a49b7..433b8a6 100644 --- a/pedantic/type_checking_logic/check_types.py +++ b/pedantic/type_checking_logic/check_types.py @@ -965,7 +965,6 @@ def _instancecheck_type(value: Any, type_: Any, type_vars: Dict, context: Dict[s 'typing.Sequence': _instancecheck_iterable, 'typing.Iterable': _instancecheck_iterable, 'typing.MutableSequence': _instancecheck_iterable, - 'typing.ByteString': _instancecheck_iterable, 'typing.Deque': _instancecheck_iterable, 'typing.List': _instancecheck_iterable, 'typing.Set': _instancecheck_iterable, From e29ab3753845029774c8ea1c36530c4e7f1f1e49 Mon Sep 17 00:00:00 2001 From: Willi Sontopski <32729196+LostInDarkMath@users.noreply.github.com> Date: Fri, 8 Aug 2025 12:50:04 +0200 Subject: [PATCH 4/5] set multiprocessing start method to spawn --- pedantic/decorators/fn_deco_in_subprocess.py | 3 +++ pedantic/type_checking_logic/check_types.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pedantic/decorators/fn_deco_in_subprocess.py b/pedantic/decorators/fn_deco_in_subprocess.py index 8809d49..dfc285e 100644 --- a/pedantic/decorators/fn_deco_in_subprocess.py +++ b/pedantic/decorators/fn_deco_in_subprocess.py @@ -4,8 +4,11 @@ from typing import Callable, TypeVar, Any, Awaitable, Optional, Type, Union try: + import multiprocess as mp from multiprocess import Process, Pipe from multiprocess.connection import Connection + + mp.set_start_method(method="spawn", force=True) except ImportError: Process: Optional[Type] = None Pipe: Optional[Type] = None diff --git a/pedantic/type_checking_logic/check_types.py b/pedantic/type_checking_logic/check_types.py index 433b8a6..293329c 100644 --- a/pedantic/type_checking_logic/check_types.py +++ b/pedantic/type_checking_logic/check_types.py @@ -3,7 +3,7 @@ import types import typing from io import BytesIO, StringIO, BufferedWriter, TextIOWrapper -from typing import Any, Dict, Iterable, ItemsView, Callable, Union, Optional, Tuple, Mapping, TypeVar, NewType, \ +from typing import Any, Dict, Iterable, ItemsView, Callable, Optional, Tuple, Mapping, TypeVar, NewType, \ _ProtocolMeta import collections From 0d75b48d7802a6986e48ae5bdd1eecb9795ce33b Mon Sep 17 00:00:00 2001 From: Willi Sontopski <32729196+LostInDarkMath@users.noreply.github.com> Date: Fri, 8 Aug 2025 13:00:29 +0200 Subject: [PATCH 5/5] remove 3.14 rc from CI i will re-add it later --- .github/workflows/main.yml | 2 +- CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 42e3d99..85ce5ac 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.11, 3.12, 3.13, 3.14.0-rc.1] + python-version: [3.11, 3.12, 3.13] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 04d3251..64b2e02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # Changelog ## Pedantic 2.2.3 -- added `3.14.0-rc.1` to CI test matrix - remove support for deprecated `typing.ByteString` - fix `WithDecoratedMethods` +- use start method `spawn` for `multiprocess` ## Pedantic 2.2.2 - fix `GenericMixin`