diff --git a/Lib/encodings/__init__.py b/Lib/encodings/__init__.py index dff22a4b27f452..6d69b573361764 100644 --- a/Lib/encodings/__init__.py +++ b/Lib/encodings/__init__.py @@ -152,20 +152,5 @@ def search_function(encoding): # Return the registry entry return entry -if sys.platform == 'win32': - def _alias_mbcs(encoding): - try: - import _winapi - ansi_code_page = "cp%s" % _winapi.GetACP() - if encoding == ansi_code_page: - import encodings.mbcs - return encodings.mbcs.getregentry() - except ImportError: - # Imports may fail while we are shutting down - pass - - # It must be registered before search_function() - codecs.register(_alias_mbcs) - # Register the search_function in the Python codec registry codecs.register(search_function) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index d30ff8f82db9a5..dddce11b21ec04 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -3190,15 +3190,6 @@ def test_incremental(self): False) self.assertEqual(decoded, ('abc', 3)) - def test_mbcs_alias(self): - # On Windows, the encoding name must be the ANSI code page - encoding = locale.getpreferredencoding(False) - self.assertTrue(encoding.startswith('cp'), encoding) - - # The encodings module create a "mbcs" alias to the ANSI code page - codec = codecs.lookup(encoding) - self.assertEqual(codec.name, "mbcs") - @support.bigmemtest(size=2**31, memuse=7, dry_run=False) def test_large_input(self, size): # Test input longer than INT_MAX. diff --git a/Misc/NEWS.d/next/Library/2022-02-07-00-15-26.bpo-46668._JVAGD.rst b/Misc/NEWS.d/next/Library/2022-02-07-00-15-26.bpo-46668._JVAGD.rst new file mode 100644 index 00000000000000..57d383a2cbc163 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-02-07-00-15-26.bpo-46668._JVAGD.rst @@ -0,0 +1,3 @@ +Python no longer creates an alias for the ANSI code page to the "mbcs" +codec: always use the Python implementation of the code page. Patch by +Victor Stinner.