<!-- If you're new to Python and you're not sure whether what you're experiencing is a bug, the CPython issue tracker is not the right place to seek help. Consider the following options instead: - reading the Python tutorial: https://docs.python.org/3/tutorial/ - posting in the "Users" category on discuss.python.org: https://discuss.python.org/c/users/7 - emailing the Python-list mailing list: https://mail.python.org/mailman/listinfo/python-list - searching our issue tracker (https://github.com/python/cpython/issues) to see if your problem has already been reported --> # Bug report When calling `locale.getencoding()` while `_locale.getencoding()` is not available, it shows looking-recursive deprecation warnings. ``` ../Lib/locale.py:657: DeprecationWarning: Use setlocale(), getencoding() and getlocale() instead ``` This is happening because python version `locale.getencoding()` is calling `locale.getdefaultlocale()` https://github.com/python/cpython/blob/v3.12.0a5/Lib/locale.py#L642 and `locale.getdefaultlocale` warns regardless where the call came from https://github.com/python/cpython/blob/v3.12.0a5/Lib/locale.py#L544-L547 # Your environment <!-- Include as many relevant details as possible about the environment you experienced the bug in --> - CPython versions tested on: v3.11.2 Lib with RustPython HEAD - Operating system and architecture: aarch64-apple-darwin <!-- You can freely edit this text. Remove any lines you believe are unnecessary. --> <!-- gh-linked-prs --> ### Linked PRs * gh-103086 <!-- /gh-linked-prs -->