diff --git a/CHANGES/1363.breaking.rst b/CHANGES/1363.breaking.rst new file mode 120000 index 000000000..c90094766 --- /dev/null +++ b/CHANGES/1363.breaking.rst @@ -0,0 +1 @@ +1348.breaking.rst \ No newline at end of file diff --git a/tests/test_cache.py b/tests/test_cache.py index 12024e3db..683fb72e7 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -36,6 +36,39 @@ def test_cache_configure_None() -> None: ) +def test_cache_configure_None_including_deprecated() -> None: + msg = ( + r"cache_configure\(\) no longer accepts the ip_address_size " + r"or host_validate_size arguments, they are used to set the " + r"encode_host_size instead and will be removed in the future" + ) + with pytest.warns(DeprecationWarning, match=msg): + yarl.cache_configure( + idna_decode_size=None, + idna_encode_size=None, + encode_host_size=None, + ip_address_size=None, + host_validate_size=None, + ) + assert yarl.cache_info()["idna_decode"].maxsize is None + assert yarl.cache_info()["idna_encode"].maxsize is None + assert yarl.cache_info()["encode_host"].maxsize is None + + +def test_cache_configure_None_only_deprecated() -> None: + msg = ( + r"cache_configure\(\) no longer accepts the ip_address_size " + r"or host_validate_size arguments, they are used to set the " + r"encode_host_size instead and will be removed in the future" + ) + with pytest.warns(DeprecationWarning, match=msg): + yarl.cache_configure( + ip_address_size=None, + host_validate_size=None, + ) + assert yarl.cache_info()["encode_host"].maxsize is None + + def test_cache_configure_explicit() -> None: yarl.cache_configure( idna_decode_size=128, diff --git a/yarl/_url.py b/yarl/_url.py index 966fd3743..0e3677e54 100644 --- a/yarl/_url.py +++ b/yarl/_url.py @@ -1430,27 +1430,30 @@ def cache_configure( global _idna_decode, _idna_encode, _encode_host # ip_address_size, host_validate_size are no longer # used, but are kept for backwards compatibility. - if encode_host_size is _SENTINEL: - encode_host_size = _DEFAULT_ENCODE_SIZE + if ip_address_size is not _SENTINEL or host_validate_size is not _SENTINEL: + warnings.warn( + "cache_configure() no longer accepts the " + "ip_address_size or host_validate_size arguments, " + "they are used to set the encode_host_size instead " + "and will be removed in the future", + DeprecationWarning, + stacklevel=2, + ) + + if encode_host_size is not None: for size in (ip_address_size, host_validate_size): - if size is not _SENTINEL: - warnings.warn( - "cache_configure() no longer accepts the " - "ip_address_size or host_validate_size arguments, " - "they are used to set the encode_host_size instead " - "and will be removed in the future", - DeprecationWarning, - stacklevel=2, - ) if size is None: encode_host_size = None - break - elif size is _SENTINEL: - size = _DEFAULT_ENCODE_SIZE - if TYPE_CHECKING: - assert not isinstance(size, object) - if size > encode_host_size: - encode_host_size = size + elif encode_host_size is _SENTINEL: + if size is not _SENTINEL: + encode_host_size = size + elif size is not _SENTINEL: + if TYPE_CHECKING: + assert isinstance(size, int) + assert isinstance(encode_host_size, int) + encode_host_size = max(size, encode_host_size) + if encode_host_size is _SENTINEL: + encode_host_size = _DEFAULT_ENCODE_SIZE if TYPE_CHECKING: assert not isinstance(encode_host_size, object)