Skip to content

Commit

Permalink
Moved deep_update from pydantic to pyuploadcare.helpers, fixes #283
Browse files Browse the repository at this point in the history
  • Loading branch information
evgkirov committed Feb 9, 2024
1 parent 91aac73 commit 3ee178c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
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

0 comments on commit 3ee178c

Please sign in to comment.