From 8269c292498a88473ff22712d7ca38bf1a72c913 Mon Sep 17 00:00:00 2001 From: Tin Tvrtkovic Date: Tue, 20 Jun 2023 01:43:25 +0200 Subject: [PATCH 1/2] Stop generating kwonly params for speed --- HISTORY.md | 1 + src/cattrs/gen/__init__.py | 2 +- src/cattrs/gen/typeddicts.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index e0baf91c..08aab454 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -12,6 +12,7 @@ - Improve the implementation of `cattrs._compat.is_typeddict`. The implementation is now simpler, and relies on fewer private implementation details from `typing` and typing_extensions. ([#384](https://github.com/python-attrs/cattrs/pull/384)) - Improve handling of TypedDicts with forward references. +- Speed up generated _attrs_ and TypedDict structuring functions by changing their signature slightly. ## 23.1.2 (2023-06-02) diff --git a/src/cattrs/gen/__init__.py b/src/cattrs/gen/__init__.py index 279934b0..8e3dc29d 100644 --- a/src/cattrs/gen/__init__.py +++ b/src/cattrs/gen/__init__.py @@ -470,7 +470,7 @@ def make_dict_structure_fn( globs[k] = v total_lines = [ - f"def {fn_name}(o, _, *, {internal_arg_line}):", + f"def {fn_name}(o, _, {internal_arg_line}):", *lines, *post_lines, *instantiation_lines, diff --git a/src/cattrs/gen/typeddicts.py b/src/cattrs/gen/typeddicts.py index 6b794397..cbbc4bdc 100644 --- a/src/cattrs/gen/typeddicts.py +++ b/src/cattrs/gen/typeddicts.py @@ -504,7 +504,7 @@ def make_dict_structure_fn( globs[k] = v total_lines = [ - f"def {fn_name}(o, _, *, {internal_arg_line}):", + f"def {fn_name}(o, _, {internal_arg_line}):", *lines, *post_lines, " return res", From bb01ee5d2b833c5cd68ec7d318d68e1879cf7220 Mon Sep 17 00:00:00 2001 From: Tin Tvrtkovic Date: Tue, 20 Jun 2023 02:05:12 +0200 Subject: [PATCH 2/2] Changelog --- .github/workflows/main.yml | 1 + HISTORY.md | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9faaf25d..0ff7a270 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -77,6 +77,7 @@ jobs: path: "htmlcov" - name: "Make badge" + if: github.ref == 'refs/heads/main' uses: "schneegans/dynamic-badges-action@v1.4.0" with: # GIST_TOKEN is a GitHub personal access token with scope "gist". diff --git a/HISTORY.md b/HISTORY.md index 08aab454..4e9d5770 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -13,6 +13,7 @@ ([#384](https://github.com/python-attrs/cattrs/pull/384)) - Improve handling of TypedDicts with forward references. - Speed up generated _attrs_ and TypedDict structuring functions by changing their signature slightly. + ([#388](https://github.com/python-attrs/cattrs/pull/388)) ## 23.1.2 (2023-06-02) @@ -20,7 +21,8 @@ ## 23.1.1 (2023-05-30) -- Add `typing_extensions` as a direct dependency on 3.10. ([#369](https://github.com/python-attrs/cattrs/issues/369) [#370](https://github.com/python-attrs/cattrs/pull/370)) +- Add `typing_extensions` as a direct dependency on 3.10. + ([#369](https://github.com/python-attrs/cattrs/issues/369) [#370](https://github.com/python-attrs/cattrs/pull/370)) ## 23.1.0 (2023-05-30)