Skip to content

Commit

Permalink
Merge pull request #284 from uploadcare/bugfix/283-deprecated_deep_up…
Browse files Browse the repository at this point in the history
…date

Moved deep_update from pydantic to pyuploadcare.helpers

fixes #283
  • Loading branch information
evgkirov committed Mar 2, 2024
2 parents a73c47a + b5b3f59 commit 114bc98
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
5 changes: 3 additions & 2 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ The format is based on [Keep a
Changelog](https://keepachangelog.com/en/1.0.0/), and this project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.0.1](https://github.com/uploadcare/pyuploadcare/compare/v5.0.0...v5.0.1) - unreleased
## [5.0.1](https://github.com/uploadcare/pyuploadcare/compare/v5.0.0...v5.0.1) - 2024-03-02

### Changed

- [Blocks](https://github.com/uploadcare/blocks) have been updated to [v0.33.2](https://github.com/uploadcare/blocks/releases)

### 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 114bc98

Please sign in to comment.