mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-10-30 22:25:19 +00:00 
			
		
		
		
	[utils] Add deprecation_warning
				
					
				
			See https://github.com/yt-dlp/yt-dlp/pull/2173#issuecomment-1097021515
This commit is contained in:
		| @@ -828,8 +828,8 @@ def escapeHTML(text): | ||||
| 
 | ||||
| 
 | ||||
| def process_communicate_or_kill(p, *args, **kwargs): | ||||
|     write_string('DeprecationWarning: yt_dlp.utils.process_communicate_or_kill is deprecated ' | ||||
|                  'and may be removed in a future version. Use yt_dlp.utils.Popen.communicate_or_kill instead') | ||||
|     deprecation_warning(f'"{__name__}.process_communicate_or_kill" is deprecated and may be removed ' | ||||
|                         f'in a future version. Use "{__name__}.Popen.communicate_or_kill" instead') | ||||
|     return Popen.communicate_or_kill(p, *args, **kwargs) | ||||
| 
 | ||||
| 
 | ||||
| @@ -1934,7 +1934,7 @@ class DateRange: | ||||
| 
 | ||||
| def platform_name(): | ||||
|     """ Returns the platform name as a str """ | ||||
|     write_string('DeprecationWarning: yt_dlp.utils.platform_name is deprecated, use platform.platform instead') | ||||
|     deprecation_warning(f'"{__name__}.platform_name" is deprecated, use "platform.platform" instead') | ||||
|     return platform.platform() | ||||
| 
 | ||||
| 
 | ||||
| @@ -1980,6 +1980,23 @@ def write_string(s, out=None, encoding=None): | ||||
|     out.flush() | ||||
| 
 | ||||
| 
 | ||||
| def deprecation_warning(msg, *, printer=None, stacklevel=0, **kwargs): | ||||
|     from . import _IN_CLI | ||||
|     if _IN_CLI: | ||||
|         if msg in deprecation_warning._cache: | ||||
|             return | ||||
|         deprecation_warning._cache.add(msg) | ||||
|         if printer: | ||||
|             return printer(f'{msg}{bug_reports_message()}', **kwargs) | ||||
|         return write_string(f'ERROR: {msg}{bug_reports_message()}\n', **kwargs) | ||||
|     else: | ||||
|         import warnings | ||||
|         warnings.warn(DeprecationWarning(msg), stacklevel=stacklevel + 3) | ||||
| 
 | ||||
| 
 | ||||
| deprecation_warning._cache = set() | ||||
| 
 | ||||
| 
 | ||||
| def bytes_to_intlist(bs): | ||||
|     if not bs: | ||||
|         return [] | ||||
| @@ -4862,8 +4879,8 @@ def decode_base_n(string, n=None, table=None): | ||||
| 
 | ||||
| 
 | ||||
| def decode_base(value, digits): | ||||
|     write_string('DeprecationWarning: yt_dlp.utils.decode_base is deprecated ' | ||||
|                  'and may be removed in a future version. Use yt_dlp.decode_base_n instead') | ||||
|     deprecation_warning(f'{__name__}.decode_base is deprecated and may be removed ' | ||||
|                         f'in a future version. Use {__name__}.decode_base_n instead') | ||||
|     return decode_base_n(value, table=digits) | ||||
| 
 | ||||
| 
 | ||||
| @@ -5332,8 +5349,8 @@ def traverse_obj( | ||||
| 
 | ||||
| 
 | ||||
| def traverse_dict(dictn, keys, casesense=True): | ||||
|     write_string('DeprecationWarning: yt_dlp.utils.traverse_dict is deprecated ' | ||||
|                  'and may be removed in a future version. Use yt_dlp.utils.traverse_obj instead') | ||||
|     deprecation_warning(f'"{__name__}.traverse_dict" is deprecated and may be removed ' | ||||
|                         f'in a future version. Use "{__name__}.traverse_obj" instead') | ||||
|     return traverse_obj(dictn, keys, casesense=casesense, is_user_input=True, traverse_string=True) | ||||
| 
 | ||||
| 
 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 pukkandan
					pukkandan