From 4ce0e4d331c34ea1fb8b7f7ec50a0036f3ddcab3 Mon Sep 17 00:00:00 2001 From: doe1080 <98906116+doe1080@users.noreply.github.com> Date: Wed, 19 Aug 2026 12:55:26 +0900 Subject: [PATCH] [utils] Deprecate `number_of_digits` (#17300) Authored by: doe1080 --- pyproject.toml | 1 + yt_dlp/YoutubeDL.py | 5 ++--- yt_dlp/utils/_deprecated.py | 4 ++++ yt_dlp/utils/_utils.py | 4 ---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d53cd80235..125e969c4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -396,6 +396,7 @@ banned-from = [ "yt_dlp.utils.intlist_to_bytes".msg = "Use `bytes` instead." "yt_dlp.utils.jwt_encode_hs256".msg = "Use `yt_dlp.utils.jwt_encode` instead." "yt_dlp.utils.make_dir".msg = "Use `yt_dlp.utils.make_parent_dirs` instead." +"yt_dlp.utils.number_of_digits".msg = "Do not use" "yt_dlp.utils.decodeArgument".msg = "Do not use" "yt_dlp.utils.decodeFilename".msg = "Do not use" "yt_dlp.utils.encodeFilename".msg = "Do not use" diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index a2675bd44d..051d1b0fb4 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -140,7 +140,6 @@ from .utils import ( locked_file, make_archive_id, make_parent_dirs, - number_of_digits, orderedSet, orderedSet_from_options, parse_filesize, @@ -1286,8 +1285,8 @@ class YoutubeDL: # For fields playlist_index, playlist_autonumber and autonumber convert all occurrences # of %(field)s to %(field)0Nd for backward compatibility field_size_compat_map = { - 'playlist_index': number_of_digits(info_dict.get('__last_playlist_index') or 0), - 'playlist_autonumber': number_of_digits(info_dict.get('n_entries') or 0), + 'playlist_index': len(str(info_dict.get('__last_playlist_index') or 0)), + 'playlist_autonumber': len(str(info_dict.get('n_entries') or 0)), 'autonumber': self.params.get('autonumber_size') or 5, } diff --git a/yt_dlp/utils/_deprecated.py b/yt_dlp/utils/_deprecated.py index 9fada27fd8..3f8aea1b20 100644 --- a/yt_dlp/utils/_deprecated.py +++ b/yt_dlp/utils/_deprecated.py @@ -58,4 +58,8 @@ def make_dir(path, to_screen=None): return False +def number_of_digits(number): + return len('%d' % number) + + compiled_regex_type = type(re.compile('')) diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py index a6e0baffcd..526d1ab9eb 100644 --- a/yt_dlp/utils/_utils.py +++ b/yt_dlp/utils/_utils.py @@ -4864,10 +4864,6 @@ def remove_terminal_sequences(string): return _terminal_sequences_re.sub('', string) -def number_of_digits(number): - return len('%d' % number) - - def join_nonempty(*values, delim='-', from_dict=None): if from_dict is not None: values = (traversal.traverse_obj(from_dict, variadic(v)) for v in values)