Skip to content

Commit 7b377ac

Browse files
committed
Add ignore_docs decorator to all internal utils
1 parent 058472e commit 7b377ac

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
[1.0.1](../../releases/tag/v1.0.1) - 2023-08-01
4+
5+
Added the `ignore_docs` decorator to all internal utilities.
6+
37
[1.0.0](../../releases/tag/v1.0.0) - 2023-07-25
48

59
Initial release of the package.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ license = {text = "Apache Software License"}
1818
name = "apify_shared"
1919
readme = "README.md"
2020
requires-python = ">=3.8"
21-
version = "1.0.0"
21+
version = "1.0.1"
2222

2323
[project.optional-dependencies]
2424
dev = [
@@ -37,7 +37,7 @@ dev = [
3737
"flake8-quotes ~= 3.3.2",
3838
"flake8-unused-arguments ~= 0.0.13",
3939
"isort ~= 5.12.0",
40-
"mypy ~= 1.3.0",
40+
"mypy ~= 1.4.0",
4141
"pep8-naming ~= 0.13.3",
4242
"pre-commit ~= 3.3.2",
4343
"pytest ~= 7.3.1",

src/apify_shared/utils.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@
1212
T = TypeVar('T')
1313

1414

15+
def ignore_docs(method: T) -> T:
16+
"""Mark that a method's documentation should not be rendered. Functionally, this decorator is a noop."""
17+
return method
18+
19+
20+
@ignore_docs
1521
def filter_out_none_values_recursively(dictionary: Dict) -> Dict:
1622
"""Return copy of the dictionary, recursively omitting all keys for which values are None."""
1723
return cast(dict, _filter_out_none_values_recursively_internal(dictionary))
1824

1925

26+
@ignore_docs
2027
def _filter_out_none_values_recursively_internal(
2128
dictionary: Dict,
2229
remove_empty_dicts: Optional[bool] = None,
@@ -37,26 +44,25 @@ def _filter_out_none_values_recursively_internal(
3744
return result
3845

3946

40-
def ignore_docs(method: T) -> T:
41-
"""Mark that a method's documentation should not be rendered. Functionally, this decorator is a noop."""
42-
return method
43-
44-
47+
@ignore_docs
4548
def is_content_type_json(content_type: str) -> bool:
4649
"""Check if the given content type is JSON."""
4750
return bool(re.search(r'^application/json', content_type, flags=re.IGNORECASE))
4851

4952

53+
@ignore_docs
5054
def is_content_type_xml(content_type: str) -> bool:
5155
"""Check if the given content type is XML."""
5256
return bool(re.search(r'^application/.*xml$', content_type, flags=re.IGNORECASE))
5357

5458

59+
@ignore_docs
5560
def is_content_type_text(content_type: str) -> bool:
5661
"""Check if the given content type is text."""
5762
return bool(re.search(r'^text/', content_type, flags=re.IGNORECASE))
5863

5964

65+
@ignore_docs
6066
def is_file_or_bytes(value: Any) -> bool:
6167
"""Check if the input value is a file-like object or bytes.
6268
@@ -67,18 +73,21 @@ def is_file_or_bytes(value: Any) -> bool:
6773
return isinstance(value, (bytes, bytearray, io.IOBase))
6874

6975

76+
@ignore_docs
7077
def json_dumps(obj: Any) -> str:
7178
"""Dump JSON to a string with the correct settings and serializer."""
7279
return json.dumps(obj, ensure_ascii=False, indent=2, default=str)
7380

7481

82+
@ignore_docs
7583
def maybe_extract_enum_member_value(maybe_enum_member: Any) -> Any:
7684
"""Extract the value of an enumeration member if it is an Enum, otherwise return the original value."""
7785
if isinstance(maybe_enum_member, Enum):
7886
return maybe_enum_member.value
7987
return maybe_enum_member
8088

8189

90+
@ignore_docs
8291
def parse_date_fields(data: ListOrDict, max_depth: int = PARSE_DATE_FIELDS_MAX_DEPTH) -> ListOrDict:
8392
"""Recursively parse date fields in a list or dictionary up to the specified depth."""
8493
if max_depth < 0:
@@ -98,7 +107,7 @@ def parse(key: str, value: object) -> object:
98107
elif isinstance(value, dict):
99108
parsed_value = parse_date_fields(value, max_depth - 1)
100109
elif isinstance(value, list):
101-
parsed_value = parse_date_fields(value, max_depth)
110+
parsed_value = parse_date_fields(value, max_depth) # type: ignore # mypy doesn't work with decorators and recursive calls well
102111
return parsed_value
103112

104113
return {key: parse(key, value) for (key, value) in data.items()}

0 commit comments

Comments
 (0)