Desusos¶
Pending removal in Python 3.15¶
- The import system: - Setting - __cached__on a module while failing to set- __spec__.cachedis deprecated. In Python 3.15,- __cached__will cease to be set or take into consideration by the import system or standard library. (gh-97879)
- Setting - __package__on a module while failing to set- __spec__.parentis deprecated. In Python 3.15,- __package__will cease to be set or take into consideration by the import system or standard library. (gh-97879)
 
- 
- La función - ctypes.SetPointerType()no documentada ha quedado obsoleta desde Python 3.13.
 
- 
- The obsolete and rarely used - CGIHTTPRequestHandlerhas been deprecated since Python 3.13. No direct replacement exists. Anything is better than CGI to interface a web server with a request handler.
- La bandera - --cgide la interfaz de línea de comandos python -m http.server ha quedado obsoleta desde Python 3.13.
 
- 
- Método - load_module(): utilice- exec_module()en su lugar.
 
- 
- La función - getdefaultlocale()ha quedado obsoleta desde Python 3.11. Su eliminación se había planeado originalmente para Python 3.13 (gh-90817), pero se pospuso hasta Python 3.15. Utilice- getlocale(),- setlocale()y- getencoding()en su lugar. (Contribuido por Hugo van Kemenade en gh-111187.)
 
- 
- .PurePath.is_reserved()has been deprecated since Python 3.13. Use- os.path.isreserved()to detect reserved paths on Windows.
 
- 
- platform.java_ver()has been deprecated since Python 3.13. This function is only useful for Jython support, has a confusing API, and is largely untested.
 
- 
- The check_home argument of - sysconfig.is_python_build()has been deprecated since Python 3.12.
 
- 
- RLock()no acepta argumentos en Python 3.15. El paso de cualquier argumento ha quedado obsoleto desde Python 3.14, ya que la versión de Python no permite ningún argumento, pero la versión de C permite cualquier cantidad de argumentos posicionales o de palabras clave, ignorando todos los argumentos.
 
- 
- types.CodeType: Accessing- co_lnotabwas deprecated in PEP 626 since 3.10 and was planned to be removed in 3.12, but it only got a proper- DeprecationWarningin 3.12. May be removed in 3.15. (Contributed by Nikita Sobolev in gh-101866.)
 
- 
- The undocumented keyword argument syntax for creating - NamedTupleclasses (for example,- Point = NamedTuple("Point", x=int, y=int)) has been deprecated since Python 3.13. Use the class-based syntax or the functional syntax instead.
- When using the functional syntax of - TypedDicts, failing to pass a value to the fields parameter (- TD = TypedDict("TD")) or passing- None(- TD = TypedDict("TD", None)) has been deprecated since Python 3.13. Use- class TD(TypedDict): passor- TD = TypedDict("TD", {})to create a TypedDict with zero field.
- The - typing.no_type_check_decorator()decorator function has been deprecated since Python 3.13. After eight years in the- typingmodule, it has yet to be supported by any major type checker.
 
- Módulos - sre_compile,- sre_constantsy- sre_parse.
- wave:- The - getmark(),- setmark()and- getmarkers()methods of the- Wave_readand- Wave_writeclasses have been deprecated since Python 3.13.
 
- 
- zipimport.zipimporter.load_module()has been deprecated since Python 3.10. Use- exec_module()instead. (gh-125746.)
 
Pending removal in Python 3.16¶
- The import system: - Setting - __loader__on a module while failing to set- __spec__.loaderis deprecated. In Python 3.16,- __loader__will cease to be set or taken into consideration by the import system or the standard library.
 
- 
- El código de formato - 'u'(- wchar_t) ha quedado obsoleto en la documentación desde Python 3.3 y en el entorno de ejecución desde Python 3.13. Utilice el código de formato- 'w'(- Py_UCS4) para caracteres Unicode.
 
- 
- asyncio.iscoroutinefunction()is deprecated and will be removed in Python 3.16; use- inspect.iscoroutinefunction()instead. (Contributed by Jiahao Li and Kumar Aditya in gh-122875.)
- asynciopolicy system is deprecated and will be removed in Python 3.16. In particular, the following classes and functions are deprecated:- Users should use - asyncio.run()or- asyncio.Runnerwith loop_factory to use the desired event loop implementation.- For example, to use - asyncio.SelectorEventLoopon Windows:- import asyncio async def main(): ... asyncio.run(main(), loop_factory=asyncio.SelectorEventLoop) - (Contributed by Kumar Aditya in gh-127949.) 
 
- 
- La inversión bit a bit en tipos booleanos, - ~Trueo- ~False, ha quedado obsoleta desde Python 3.12, ya que produce resultados sorprendentes y poco intuitivos (- -2y- -1). En su lugar, utilice- not xpara la negación lógica de un valor booleano. En el caso poco frecuente de que necesite la inversión bit a bit del entero subyacente, convierta a- intexplícitamente (- ~int(x)).
 
- 
- Calling the Python implementation of - functools.reduce()with function or sequence as keyword arguments has been deprecated since Python 3.14.
 
- 
Support for custom logging handlers with the strm argument is deprecated and scheduled for removal in Python 3.16. Define handlers with the stream argument instead. (Contributed by Mariusz Felisiak in gh-115032.) 
- 
- Valid extensions start with a “.” or are empty for - mimetypes.MimeTypes.add_type(). Undotted extensions are deprecated and will raise a- ValueErrorin Python 3.16. (Contributed by Hugo van Kemenade in gh-75223.)
 
- 
- La excepción - ExecErrorha quedado obsoleta desde Python 3.14. No ha sido utilizada por ninguna función en- shutildesde Python 3.4 y ahora es un alias de- RuntimeError.
 
- 
- El método - Class.get_methodsha quedado obsoleto desde Python 3.14.
 
- sys:- La función - _enablelegacywindowsfsencoding()ha quedado obsoleta desde Python 3.13. En su lugar, utilice la variable de entorno- PYTHONLEGACYWINDOWSFSENCODING.
 
- 
- The - sysconfig.expand_makefile_vars()function has been deprecated since Python 3.14. Use the- varsargument of- sysconfig.get_paths()instead.
 
- 
- El atributo - TarFile.tarfile, no documentado ni utilizado, ha quedado obsoleto desde Python 3.13.
 
Pending removal in Python 3.17¶
- 
- collections.abc.ByteStringis scheduled for removal in Python 3.17.- Use - isinstance(obj, collections.abc.Buffer)to test if- objimplements the buffer protocol at runtime. For use in type annotations, either use- Bufferor a union that explicitly specifies the types your code supports (e.g.,- bytes | bytearray | memoryview).- ByteStringwas originally intended to be an abstract class that would serve as a supertype of both- bytesand- bytearray. However, since the ABC never had any methods, knowing that an object was an instance of- ByteStringnever actually told you anything useful about the object. Other common buffer types such as- memoryviewwere also never understood as subtypes of- ByteString(either at runtime or by static type checkers).- See PEP 688 for more details. (Contributed by Shantanu Jain in gh-91896.) 
 
- 
- Before Python 3.14, old-style unions were implemented using the private class - typing._UnionGenericAlias. This class is no longer needed for the implementation, but it has been retained for backward compatibility, with removal scheduled for Python 3.17. Users should use documented introspection helpers like- typing.get_origin()and- typing.get_args()instead of relying on private implementation details.
- typing.ByteString, deprecated since Python 3.9, is scheduled for removal in Python 3.17.- Use - isinstance(obj, collections.abc.Buffer)to test if- objimplements the buffer protocol at runtime. For use in type annotations, either use- Bufferor a union that explicitly specifies the types your code supports (e.g.,- bytes | bytearray | memoryview).- ByteStringwas originally intended to be an abstract class that would serve as a supertype of both- bytesand- bytearray. However, since the ABC never had any methods, knowing that an object was an instance of- ByteStringnever actually told you anything useful about the object. Other common buffer types such as- memoryviewwere also never understood as subtypes of- ByteString(either at runtime or by static type checkers).- See PEP 688 for more details. (Contributed by Shantanu Jain in gh-91896.) 
 
Pending removal in Python 3.19¶
- 
- In hash function constructors such as - new()or the direct hash-named constructors such as- md5()and- sha256(), their optional initial data parameter could also be passed a keyword argument named- data=or- string=in various- hashlibimplementations.- Support for the - stringkeyword argument name is now deprecated and slated for removal in Python 3.19.- Before Python 3.13, the - stringkeyword parameter was not correctly supported depending on the backend implementation of hash functions. Prefer passing the initial data as a positional argument for maximum backwards compatibility.
 
Pending removal in Python 3.20¶
- The - __version__attribute has been deprecated in these standard library modules and will be removed in Python 3.20. Use- sys.version_infoinstead.
- ctypes.macholib
- decimal(use- decimal.SPEC_VERSIONinstead)
- logging(- __date__also deprecated)
 - (Contributed by Hugo van Kemenade and Stan Ulbrych in gh-76007.) 
Pending removal in future versions¶
Las siguientes API se eliminarán en el futuro, aunque actualmente no hay una fecha programada para su eliminación.
- 
- Nesting argument groups and nesting mutually exclusive groups are deprecated. 
- Passing the undocumented keyword argument prefix_chars to - add_argument_group()is now deprecated.
- The - argparse.FileTypetype converter is deprecated.
 
- 
- Generadores: las firmas - throw(type, exc, tb)y- athrow(type, exc, tb)están obsoletas: utilice- throw(exc)y- athrow(exc)en su lugar, la firma de argumento único.
- Actualmente, Python acepta literales numéricos seguidos inmediatamente de palabras clave, por ejemplo, - 0in x,- 1or x,- 0if 1else 2. Permite expresiones confusas y ambiguas como- [0x1for x in y](que se puede interpretar como- [0x1 for x in y]o- [0x1f or x in y]). Se genera una advertencia de sintaxis si el literal numérico va seguido inmediatamente de una de las palabras clave- and,- else,- for,- if,- in,- isy- or. En una versión futura, se cambiará a un error de sintaxis. (gh-87999)
- Compatibilidad con los métodos - __index__()y- __int__()que devuelven un tipo que no es int: estos métodos serán necesarios para devolver una instancia de una subclase estricta de- int.
- Compatibilidad con el método - __float__()que devuelve una subclase estricta de- float: estos métodos serán necesarios para devolver una instancia de- float.
- Compatibilidad con el método - __complex__()que devuelve una subclase estricta de- complex: estos métodos serán necesarios para devolver una instancia de- complex.
- Delegación del método - int()al- __trunc__().
- Ahora está obsoleto el paso de un número complejo como argumento real o imag en el constructor - complex(); solo debe pasarse como un único argumento posicional. (Contribuido por Serhiy Storchaka en gh-109218.)
 
- calendar: Las constantes- calendar.Januaryy- calendar.Februaryhan quedado obsoletas y han sido reemplazadas por- calendar.JANUARYy- calendar.FEBRUARY. (Contribuido por Prince Roshan en gh-103636.)
- codecs: use- open()instead of- codecs.open(). (gh-133038)
- codeobject.co_lnotab: utilice el método- codeobject.co_lines()en su lugar.
- 
- utcnow(): utilice- datetime.datetime.now(tz=datetime.UTC).
- utcfromtimestamp(): utilice- datetime.datetime.fromtimestamp(timestamp, tz=datetime.UTC).
 
- gettext: El valor plural debe ser un número entero.
- 
- cache_from_source()El parámetro debug_override está obsoleto: utilice el parámetro optimization en su lugar.
 
- 
- Interfaz de tupla - EntryPoints.
- Noneimplícito en los valores de retorno.
 
- logging: el método- warn()ha quedado obsoleto desde Python 3.3, utilice- warning()en su lugar.
- mailbox: El uso del modo de entrada y texto StringIO está obsoleto; en su lugar, utilice BytesIO y el modo binario.
- os: Llamada a- os.register_at_fork()en un proceso multiproceso.
- pydoc.ErrorDuringImport: Un valor de tupla para el parámetro exc_info está obsoleto, utilice una instancia de excepción.
- re: Ahora se aplican reglas más estrictas para las referencias numéricas de grupos y los nombres de grupos en expresiones regulares. Ahora solo se aceptan secuencias de dígitos ASCII como referencia numérica. El nombre de grupo en patrones de bytes y cadenas de reemplazo ahora solo puede contener letras y dígitos ASCII y guiones bajos. (Contribuido por Serhiy Storchaka en gh-91760.)
- shutil: El parámetro onerror de- rmtree()está obsoleto en Python 3.12; utilice el parámetro onexc en su lugar.
- Opciones y protocolos - ssl:- ssl.SSLContextsin argumento de protocolo está obsoleto.
- ssl.SSLContext:- set_npn_protocols()y- selected_npn_protocol()están obsoletos: utilice ALPN en su lugar.
- Opciones de - ssl.OP_NO_SSL*
- Opciones de - ssl.OP_NO_TLS*
- ssl.PROTOCOL_SSLv3
- ssl.PROTOCOL_TLS
- ssl.PROTOCOL_TLSv1
- ssl.PROTOCOL_TLSv1_1
- ssl.PROTOCOL_TLSv1_2
- ssl.TLSVersion.SSLv3
- ssl.TLSVersion.TLSv1
- ssl.TLSVersion.TLSv1_1
 
- Métodos - threading:- threading.Condition.notifyAll(): utilice- notify_all().
- threading.Event.isSet(): utilice- is_set().
- threading.Thread.isDaemon(),- threading.Thread.setDaemon(): utilice el atributo- threading.Thread.daemon.
- threading.Thread.getName(),- threading.Thread.setName(): utilice el atributo- threading.Thread.name.
- threading.currentThread(): utilice- threading.current_thread().
- threading.activeCount(): utilice- threading.active_count().
 
- The internal class - typing._UnionGenericAliasis no longer used to implement- typing.Union. To preserve compatibility with users using this private class, a compatibility shim will be provided until at least Python 3.17. (Contributed by Jelle Zijlstra in gh-105499.)
- unittest.IsolatedAsyncioTestCase: está obsoleto devolver un valor que no sea- Nonede un caso de prueba.
- Funciones obsoletas de - urllib.parse:- urlparse()en su lugar- splitattr()
- splithost()
- splitnport()
- splitpasswd()
- splitport()
- splitquery()
- splittag()
- splittype()
- splituser()
- splitvalue()
- to_bytes()
 
- wsgiref:- SimpleHandler.stdout.write()no debería realizar escrituras parciales.
- xml.etree.ElementTree: La prueba del valor de verdad de un- Elementestá obsoleta. En una versión futura, siempre devolverá- True. En su lugar, es preferible realizar pruebas explícitas- len(elem)o- elem is not None.
- sys._clear_type_cache()is deprecated: use- sys._clear_internal_caches()instead.
C API deprecations¶
Pending removal in Python 3.15¶
- The - PyImport_ImportModuleNoBlock(): Use- PyImport_ImportModule()instead.
- PyWeakref_GetObject()and- PyWeakref_GET_OBJECT(): Use- PyWeakref_GetRef()instead. The pythoncapi-compat project can be used to get- PyWeakref_GetRef()on Python 3.12 and older.
- Tipo - Py_UNICODEy macro- Py_UNICODE_WIDE: utilice- wchar_ten su lugar.
- PyUnicode_AsDecodedObject(): Utilice- PyCodec_Decode()en su lugar.
- PyUnicode_AsDecodedUnicode(): Use- PyCodec_Decode()instead; Note that some codecs (for example, «base64») may return a type other than- str, such as- bytes.
- PyUnicode_AsEncodedObject(): Utilice- PyCodec_Encode()en su lugar.
- PyUnicode_AsEncodedUnicode(): Use- PyCodec_Encode()instead; Note that some codecs (for example, «base64») may return a type other than- bytes, such as- str.
- Python initialization functions, deprecated in Python 3.13: - Py_GetPath(): Use- PyConfig_Get("module_search_paths")(- sys.path) instead.
- Py_GetPrefix(): Use- PyConfig_Get("base_prefix")(- sys.base_prefix) instead. Use- PyConfig_Get("prefix")(- sys.prefix) if virtual environments need to be handled.
- Py_GetExecPrefix(): Use- PyConfig_Get("base_exec_prefix")(- sys.base_exec_prefix) instead. Use- PyConfig_Get("exec_prefix")(- sys.exec_prefix) if virtual environments need to be handled.
- Py_GetProgramFullPath(): Use- PyConfig_Get("executable")(- sys.executable) instead.
- Py_GetProgramName(): Use- PyConfig_Get("executable")(- sys.executable) instead.
- Py_GetPythonHome(): Use- PyConfig_Get("home")or the- PYTHONHOMEenvironment variable instead.
 - The pythoncapi-compat project can be used to get - PyConfig_Get()on Python 3.13 and older.
- Funciones para configurar la inicialización de Python, obsoletas en Python 3.11: - PySys_SetArgvEx(): Establezca- PyConfig.argven su lugar.
- PySys_SetArgv(): Establezca- PyConfig.argven su lugar.
- Py_SetProgramName(): Establezca- PyConfig.program_nameen su lugar.
- Py_SetPythonHome(): Establezca- PyConfig.homeen su lugar.
- PySys_ResetWarnOptions(): Clear- sys.warnoptionsand- warnings.filtersinstead.
 - La API - Py_InitializeFromConfig()debe utilizarse con- PyConfig.
- Variables de configuración global: - Py_DebugFlag: Use- PyConfig.parser_debugor- PyConfig_Get("parser_debug")instead.
- Py_VerboseFlag: Use- PyConfig.verboseor- PyConfig_Get("verbose")instead.
- Py_QuietFlag: Use- PyConfig.quietor- PyConfig_Get("quiet")instead.
- Py_InteractiveFlag: Use- PyConfig.interactiveor- PyConfig_Get("interactive")instead.
- Py_InspectFlag: Use- PyConfig.inspector- PyConfig_Get("inspect")instead.
- Py_OptimizeFlag: Use- PyConfig.optimization_levelor- PyConfig_Get("optimization_level")instead.
- Py_NoSiteFlag: Use- PyConfig.site_importor- PyConfig_Get("site_import")instead.
- Py_BytesWarningFlag: Use- PyConfig.bytes_warningor- PyConfig_Get("bytes_warning")instead.
- Py_FrozenFlag: Use- PyConfig.pathconfig_warningsor- PyConfig_Get("pathconfig_warnings")instead.
- Py_IgnoreEnvironmentFlag: Use- PyConfig.use_environmentor- PyConfig_Get("use_environment")instead.
- Py_DontWriteBytecodeFlag: Use- PyConfig.write_bytecodeor- PyConfig_Get("write_bytecode")instead.
- Py_NoUserSiteDirectory: Use- PyConfig.user_site_directoryor- PyConfig_Get("user_site_directory")instead.
- Py_UnbufferedStdioFlag: Use- PyConfig.buffered_stdioor- PyConfig_Get("buffered_stdio")instead.
- Py_HashRandomizationFlag: Use- PyConfig.use_hash_seedand- PyConfig.hash_seedor- PyConfig_Get("hash_seed")instead.
- Py_IsolatedFlag: Use- PyConfig.isolatedor- PyConfig_Get("isolated")instead.
- Py_LegacyWindowsFSEncodingFlag: Use- PyPreConfig.legacy_windows_fs_encodingor- PyConfig_Get("legacy_windows_fs_encoding")instead.
- Py_LegacyWindowsStdioFlag: Use- PyConfig.legacy_windows_stdioor- PyConfig_Get("legacy_windows_stdio")instead.
- Py_FileSystemDefaultEncoding,- Py_HasFileSystemDefaultEncoding: Use- PyConfig.filesystem_encodingor- PyConfig_Get("filesystem_encoding")instead.
- Py_FileSystemDefaultEncodeErrors: Use- PyConfig.filesystem_errorsor- PyConfig_Get("filesystem_errors")instead.
- Py_UTF8Mode: Use- PyPreConfig.utf8_modeor- PyConfig_Get("utf8_mode")instead. (see- Py_PreInitialize())
 - The - Py_InitializeFromConfig()API should be used with- PyConfigto set these options. Or- PyConfig_Get()can be used to get these options at runtime.
Pending removal in Python 3.18¶
- The following private functions are deprecated and planned for removal in Python 3.18: - _PyBytes_Join(): use- PyBytes_Join().
- _PyDict_GetItemStringWithError(): use- PyDict_GetItemStringRef().
- _PyDict_Pop(): use- PyDict_Pop().
- _PyLong_Sign(): use- PyLong_GetSign().
- _PyLong_FromDigits()and- _PyLong_New(): use- PyLongWriter_Create().
- _PyThreadState_UncheckedGet(): use- PyThreadState_GetUnchecked().
- _PyUnicode_AsString(): use- PyUnicode_AsUTF8().
- _PyUnicodeWriter_Init(): replace- _PyUnicodeWriter_Init(&writer)with- writer = PyUnicodeWriter_Create(0).
- _PyUnicodeWriter_Finish(): replace- _PyUnicodeWriter_Finish(&writer)with- PyUnicodeWriter_Finish(writer).
- _PyUnicodeWriter_Dealloc(): replace- _PyUnicodeWriter_Dealloc(&writer)with- PyUnicodeWriter_Discard(writer).
- _PyUnicodeWriter_WriteChar(): replace- _PyUnicodeWriter_WriteChar(&writer, ch)with- PyUnicodeWriter_WriteChar(writer, ch).
- _PyUnicodeWriter_WriteStr(): replace- _PyUnicodeWriter_WriteStr(&writer, str)with- PyUnicodeWriter_WriteStr(writer, str).
- _PyUnicodeWriter_WriteSubstring(): replace- _PyUnicodeWriter_WriteSubstring(&writer, str, start, end)with- PyUnicodeWriter_WriteSubstring(writer, str, start, end).
- _PyUnicodeWriter_WriteASCIIString(): replace- _PyUnicodeWriter_WriteASCIIString(&writer, str)with- PyUnicodeWriter_WriteASCII(writer, str).
- _PyUnicodeWriter_WriteLatin1String(): replace- _PyUnicodeWriter_WriteLatin1String(&writer, str)with- PyUnicodeWriter_WriteUTF8(writer, str).
- _PyUnicodeWriter_Prepare(): (no replacement).
- _PyUnicodeWriter_PrepareKind(): (no replacement).
- _Py_HashPointer(): use- Py_HashPointer().
- _Py_fopen_obj(): use- Py_fopen().
 - The pythoncapi-compat project can be used to get these new public functions on Python 3.13 and older. (Contributed by Victor Stinner in gh-128863.) 
Pending removal in Python 3.20¶
- The - cvalfield in- PyComplexObject(gh-128813). Use- PyComplex_AsCComplex()and- PyComplex_FromCComplex()to convert a Python complex number to/from the C- Py_complexrepresentation.
Pending removal in future versions¶
Las siguientes API están obsoletas y se eliminarán, aunque actualmente no hay una fecha programada para su eliminación.
- Py_TPFLAGS_HAVE_FINALIZE: Innecesario desde Python 3.8.
- PyErr_Fetch(): Utilice- PyErr_GetRaisedException()en su lugar.
- PyErr_NormalizeException(): Utilice- PyErr_GetRaisedException()en su lugar.
- PyErr_Restore(): Utilice- PyErr_SetRaisedException()en su lugar.
- PyModule_GetFilename(): Utilice- PyModule_GetFilenameObject()en su lugar.
- PyOS_AfterFork(): Utilice- PyOS_AfterFork_Child()en su lugar.
- PySlice_GetIndicesEx(): Utilice- PySlice_Unpack()y- PySlice_AdjustIndices()en su lugar.
- PyUnicode_READY(): Innecesario desde Python 3.12
- PyErr_Display(): Utilice- PyErr_DisplayException()en su lugar.
- _PyErr_ChainExceptions(): Utilice- _PyErr_ChainExceptions1()en su lugar.
- Miembro de - PyBytesObject.ob_shash: llame a- PyObject_Hash()en su lugar.
- API de almacenamiento local de subprocesos (TLS): - PyThread_create_key(): Utilice- PyThread_tss_alloc()en su lugar.
- PyThread_delete_key(): Utilice- PyThread_tss_free()en su lugar.
- PyThread_set_key_value(): Utilice- PyThread_tss_set()en su lugar.
- PyThread_get_key_value(): Utilice- PyThread_tss_get()en su lugar.
- PyThread_delete_key_value(): Utilice- PyThread_tss_delete()en su lugar.
- PyThread_ReInitTLS(): Innecesario desde Python 3.7.