Skip to content

Commit e64f9e3

Browse files
committed
Merge branch 'main' into validate
2 parents 1a71ae3 + 30ae96b commit e64f9e3

File tree

173 files changed

+2381
-1434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+2381
-1434
lines changed

.github/dependabot.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ updates:
55
directory: "/"
66
schedule:
77
interval: "monthly"
8-
open-pull-requests-limit: 100
8+
groups:
9+
python-requirements:
10+
patterns:
11+
- "*"
912

1013
- package-ecosystem: "github-actions"
1114
directory: "/"
1215
schedule:
1316
interval: "monthly"
14-
open-pull-requests-limit: 100
17+
groups:
18+
github-actions:
19+
patterns:
20+
- "*"

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 70 deletions
This file was deleted.

.github/workflows/create-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
steps:
1616
- name: Checkout
17-
uses: actions/checkout@v4
17+
uses: actions/checkout@v5
1818

1919
- name: Extract release notes
2020
id: extract-release-notes
@@ -27,7 +27,7 @@ jobs:
2727
token: ${{ secrets.WORKFLOWS_CREATE_RELEASE_TOKEN }}
2828

2929
- name: Set up Python
30-
uses: actions/setup-python@v5
30+
uses: actions/setup-python@v6
3131
with:
3232
python-version: '3.x'
3333
cache: 'pip'

.github/workflows/pre-commit-autoupdate.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: Pre-commit auto-update
22

3+
permissions:
4+
contents: write
5+
pull-requests: write
6+
37
on:
48
# every month
59
schedule:
@@ -11,8 +15,8 @@ jobs:
1115
auto-update:
1216
runs-on: ubuntu-latest
1317
steps:
14-
- uses: actions/checkout@v4
15-
- uses: actions/setup-python@v5
18+
- uses: actions/checkout@v5
19+
- uses: actions/setup-python@v6
1620
with:
1721
python-version: '3.x'
1822
- uses: browniebroke/pre-commit-autoupdate-action@main

.github/workflows/test-package.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: Test package
22

3+
permissions:
4+
contents: read
5+
36
on:
47
push:
58
branches: [ main ]
@@ -20,10 +23,10 @@ jobs:
2023

2124
steps:
2225

23-
- uses: actions/checkout@v4
26+
- uses: actions/checkout@v5
2427

2528
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v5
29+
uses: actions/setup-python@v6
2730
with:
2831
python-version: ${{ matrix.python-version }}
2932
cache: 'pip'

.pre-commit-config.yaml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,37 @@ repos:
88
- id: pyupgrade
99
args: ["--py310-plus"]
1010

11+
- repo: https://github.com/frostming/fix-future-annotations
12+
rev: 0.5.0
13+
hooks:
14+
- id: fix-future-annotations
15+
1116
- repo: https://github.com/astral-sh/ruff-pre-commit
12-
rev: v0.11.13
17+
rev: v0.13.2
1318
hooks:
1419
- id: ruff
1520
args: [--fix, --exit-non-zero-on-fix]
1621
- id: ruff-format
1722

23+
- repo: https://github.com/pre-commit/mirrors-mypy
24+
rev: v1.18.2
25+
hooks:
26+
- id: mypy
27+
args: [--config-file=pyproject.toml]
28+
additional_dependencies:
29+
- boto3-stubs[essential,lambda]==1.40.41
30+
- decouple-types==1.0.2
31+
- types-PyYAML==6.0.12.20250915
32+
- types-beautifulsoup4==4.12.0.20250516
33+
- types-html5lib==1.1.11.20250917
34+
- types-openpyxl==3.1.5.20250919
35+
- types-python-dateutil==2.9.0.20250822
36+
- types-toml==0.10.8.20240310
37+
- types-xmltodict==1.0.1.20250920
38+
exclude: "tests"
39+
1840
- repo: https://github.com/pre-commit/pre-commit-hooks
19-
rev: v5.0.0
41+
rev: v6.0.0
2042
hooks:
2143
- id: trailing-whitespace
2244
- id: end-of-file-fixer

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.35.0](https://github.com/fabiocaccamo/python-benedict/releases/tag/0.35.0) - 2025-10-01
8+
- Add type annotations. #157 (by [@Tatsh](https://github.com/Tatsh) in #491)
9+
- Bump requirements and `pre-commit` hooks.
10+
711
## [0.34.1](https://github.com/fabiocaccamo/python-benedict/releases/tag/0.34.1) - 2025-01-18
812
- Add `sort` parameter to `keypaths` method. #404 (by [@kotfu](https://github.com/kotfu) in #467)
913
- Bump requirements and `pre-commit` hooks.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
[![](https://results.pre-commit.ci/badge/github/fabiocaccamo/python-benedict/main.svg)](https://results.pre-commit.ci/latest/github/fabiocaccamo/python-benedict/main)
88
[![](https://img.shields.io/github/actions/workflow/status/fabiocaccamo/python-benedict/test-package.yml?branch=main&label=build&logo=github)](https://github.com/fabiocaccamo/python-benedict)
99
[![](https://img.shields.io/codecov/c/gh/fabiocaccamo/python-benedict?logo=codecov)](https://codecov.io/gh/fabiocaccamo/python-benedict)
10-
[![](https://img.shields.io/codeclimate/maintainability/fabiocaccamo/python-benedict?logo=code-climate)](https://codeclimate.com/github/fabiocaccamo/python-benedict/)
1110
[![](https://img.shields.io/codacy/grade/0dbd5cc2089f4dce80a0e49e6822be3c?logo=codacy)](https://www.codacy.com/app/fabiocaccamo/python-benedict)
1211
[![](https://img.shields.io/scrutinizer/quality/g/fabiocaccamo/python-benedict?logo=scrutinizer)](https://scrutinizer-ci.com/g/fabiocaccamo/python-benedict/?branch=main)
1312
[![](https://img.shields.io/badge/code%20style-black-000000.svg?logo=python&logoColor=black)](https://github.com/psf/black)

bandit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
skips: ['B101']

benedict/core/clean.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
def _clean_dict(d, strings, collections):
1+
from __future__ import annotations
2+
3+
from collections.abc import MutableMapping, MutableSequence
4+
from typing import Any, TypeVar
5+
6+
_K = TypeVar("_K")
7+
_V = TypeVar("_V")
8+
_T = TypeVar("_T")
9+
10+
11+
def _clean_dict(
12+
d: MutableMapping[_K, _V], strings: bool, collections: bool
13+
) -> MutableMapping[_K, _V]:
214
keys = list(d.keys())
315
for key in keys:
416
d[key] = _clean_value(d[key], strings=strings, collections=collections)
@@ -7,41 +19,47 @@ def _clean_dict(d, strings, collections):
719
return d
820

921

10-
def _clean_list(ls, strings, collections):
22+
def _clean_list(
23+
ls: MutableSequence[_T], strings: bool, collections: bool
24+
) -> MutableSequence[_T]:
1125
for i in range(len(ls) - 1, -1, -1):
1226
ls[i] = _clean_value(ls[i], strings=strings, collections=collections)
1327
if ls[i] is None:
1428
ls.pop(i)
1529
return ls
1630

1731

18-
def _clean_set(values, strings, collections):
32+
def _clean_set(values: set[_T], strings: bool, collections: bool) -> set[_T]:
1933
return {
2034
value
2135
for value in values
2236
if _clean_value(value, strings=strings, collections=collections) is not None
2337
}
2438

2539

26-
def _clean_str(s, strings, collections):
40+
def _clean_str(s: str, strings: bool, collections: bool) -> str | None:
2741
return s if s and s.strip() else None
2842

2943

30-
def _clean_tuple(values, strings, collections):
44+
def _clean_tuple(
45+
values: tuple[_T, ...], strings: bool, collections: bool
46+
) -> tuple[_T, ...]:
3147
return tuple(
3248
value
3349
for value in values
3450
if _clean_value(value, strings=strings, collections=collections) is not None
3551
)
3652

3753

38-
def _clean_value(value, strings, collections):
54+
def _clean_value(value: Any, strings: bool, collections: bool) -> Any:
3955
if value is None:
4056
return value
41-
elif isinstance(value, list) and collections:
57+
elif isinstance(value, MutableSequence) and collections:
4258
value = _clean_list(value, strings=strings, collections=collections) or None
43-
elif isinstance(value, dict) and collections:
44-
value = _clean_dict(value, strings=strings, collections=collections) or None
59+
elif isinstance(value, MutableMapping) and collections:
60+
value = (
61+
_clean_dict(dict(value), strings=strings, collections=collections) or None
62+
)
4563
elif isinstance(value, set) and collections:
4664
value = _clean_set(value, strings=strings, collections=collections) or None
4765
elif isinstance(value, str) and strings:
@@ -51,5 +69,5 @@ def _clean_value(value, strings, collections):
5169
return value
5270

5371

54-
def clean(d, strings=True, collections=True):
72+
def clean(d: Any, strings: bool = True, collections: bool = True) -> Any:
5573
return _clean_dict(d, strings=strings, collections=collections)

0 commit comments

Comments
 (0)