Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved deep_update from pydantic to pyuploadcare.helpers #284

Merged
merged 3 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Fixed

- The SSL context is now cached by default, resulting in significant performance improvements when initializing the `Uploadcare` class frequently. [#279](https://github.com/uploadcare/pyuploadcare/issues/279)
- The SSL context is now cached by default, resulting in significant performance improvements when initializing the `Uploadcare` class frequently. [#279](https://github.com/uploadcare/pyuploadcare/issues/279)
- Removed the warning for the usage of the deprecated `pydantic.utils.deep_update` [#283](https://github.com/uploadcare/pyuploadcare/issues/283)

## [5.0.0](https://github.com/uploadcare/pyuploadcare/compare/v4.3.0...v5.0.0) - 2023-12-28

Expand Down
2 changes: 1 addition & 1 deletion pyuploadcare/dj/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from django import get_version as django_version
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from pydantic.utils import deep_update

from pyuploadcare import __version__ as library_version
from pyuploadcare.helpers import deep_update


__all__ = [
Expand Down
22 changes: 21 additions & 1 deletion pyuploadcare/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mimetypes
import os
from typing import IO, Iterable, List, TypeVar, Union
from typing import IO, Any, Dict, Iterable, List, TypeVar, Union

from pyuploadcare import File

Expand Down Expand Up @@ -48,3 +48,23 @@ def guess_mime_type(file_object: IO) -> str:
if not mime_type:
mime_type = "application/octet-stream"
return mime_type


KeyType = TypeVar("KeyType")


def deep_update(
mapping: Dict[KeyType, Any], *updating_mappings: Dict[KeyType, Any]
) -> Dict[KeyType, Any]:
updated_mapping = mapping.copy()
for updating_mapping in updating_mappings:
for k, v in updating_mapping.items():
if (
k in updated_mapping
and isinstance(updated_mapping[k], dict)
and isinstance(v, dict)
):
updated_mapping[k] = deep_update(updated_mapping[k], v)
else:
updated_mapping[k] = v
return updated_mapping
Loading