From 3ee178c33f0f665c13107ffd1d5f70a3277f5dc7 Mon Sep 17 00:00:00 2001 From: Evgeniy Kirov Date: Fri, 9 Feb 2024 17:23:29 +0100 Subject: [PATCH 1/2] Moved deep_update from pydantic to pyuploadcare.helpers, fixes #283 --- HISTORY.md | 3 ++- pyuploadcare/dj/conf.py | 2 +- pyuploadcare/helpers.py | 22 +++++++++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index ae2461fa..4756ab37 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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 diff --git a/pyuploadcare/dj/conf.py b/pyuploadcare/dj/conf.py index e614992f..a1ae1f3a 100644 --- a/pyuploadcare/dj/conf.py +++ b/pyuploadcare/dj/conf.py @@ -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__ = [ diff --git a/pyuploadcare/helpers.py b/pyuploadcare/helpers.py index 0b2ec04c..b9f0fa7d 100644 --- a/pyuploadcare/helpers.py +++ b/pyuploadcare/helpers.py @@ -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 @@ -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 From b5b3f5970d75305e704cb7c1a544c98514e733c2 Mon Sep 17 00:00:00 2001 From: Evgeniy Kirov Date: Sat, 2 Mar 2024 20:43:35 +0100 Subject: [PATCH 2/2] changelog for 5.0.1 --- HISTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index f1d74fe4..63644def 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,7 +6,7 @@ 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