منسوخشدهها¶
در انتظار حذف در پایتون 3.17¶
-
strptime()calls using a format string containing%e(day of month) without a year. This has been deprecated since Python 3.15. (Contributed by Stan Ulbrych in gh-70647.)
-
collections.abc.ByteStringبرای حذف در پایتون 3.17 برنامهریزی شده است.از
isinstance(obj, collections.abc.Buffer)استفاده کنید تا در زمان اجرا بررسی کنید که آیاobjپروتکل بافر را پیادهسازی میکند. برای استفاده در حاشیهنویسی نوع، یا ازBufferاستفاده کنید یا از یک اجتماع (union) که بهطور صریح نوعهایی را که کد شما از آنها پشتیبانی میکند مشخص میکند (مثلاًbytes | bytearray | memoryview).ByteStringدر اصل قرار بود یک کلاس انتزاعی باشد که بهعنوان ابرنوعی برای هر دوbytesوbytearrayعمل کند. با این حال، از آنجا که این کلاس پایه انتزاعی هرگز هیچ متدی نداشت، دانستن اینکه شیئی نمونهای ازByteStringاست، هرگز در واقع هیچ چیز مفیدی دربارهی آن شیء به شما نمیگفت. سایر نوعهای رایج بافر مانندmemoryviewنیز هرگز بهعنوان زیرنوعهایی ازByteStringشناخته نمیشدند (نه در رانتایم و نه توسط بررسیگرهای نوع ایستا).برای جزئیات بیشتر به PEP 688 مراجعه کنید. (مشارکتشده توسط Shantanu Jain در gh-91896.)
-
Passing non-ascii encoding names to
encodings.normalize_encoding()is deprecated and scheduled for removal in Python 3.17. (Contributed by Stan Ulbrych in gh-136702.)
-
The
profilemodule is deprecated and will be removed in Python 3.17. Useprofiling.tracinginstead, which provides a compatible API. See PEP 799 for details. (Contributed by Pablo Galindo and László Kiss Kollár in gh-138122.)
-
webbrowser.MacOSXOSAScriptis deprecated in favour ofwebbrowser.MacOS. (gh-137586)
-
پیش از پایتون 3.14، اجتماعهای سبک قدیمی (old-style unions) با استفاده از کلاس خصوصی
typing._UnionGenericAliasپیادهسازی میشدند. این کلاس دیگر برای پیادهسازی لازم نیست، اما برای سازگاری با نسخههای پیشین حفظ شده است و حذف آن برای پایتون 3.17 برنامهریزی شده است. کاربران باید بهجای اتکا به جزئیات پیادهسازی خصوصی، از ابزارهای کمکی دروننگری مستند مانندtyping.get_origin()وtyping.get_args()استفاده کنند.typing.ByteStringکه از پایتون 3.9 منسوخ شده است، برای حذف در پایتون 3.17 برنامهریزی شده است.از
isinstance(obj, collections.abc.Buffer)استفاده کنید تا در زمان اجرا بررسی کنید که آیاobjپروتکل بافر را پیادهسازی میکند. برای استفاده در حاشیهنویسی نوع، یا ازBufferاستفاده کنید یا از یک اجتماع (union) که بهطور صریح نوعهایی را که کد شما از آنها پشتیبانی میکند مشخص میکند (مثلاًbytes | bytearray | memoryview).ByteStringدر اصل قرار بود یک کلاس انتزاعی باشد که بهعنوان ابرنوعی برای هر دوbytesوbytearrayعمل کند. با این حال، از آنجا که این کلاس پایه انتزاعی هرگز هیچ متدی نداشت، دانستن اینکه شیئی نمونهای ازByteStringاست، هرگز در واقع هیچ چیز مفیدی دربارهی آن شیء به شما نمیگفت. سایر نوعهای رایج بافر مانندmemoryviewنیز هرگز بهعنوان زیرنوعهایی ازByteStringشناخته نمیشدند (نه در رانتایم و نه توسط بررسیگرهای نوع ایستا).برای جزئیات بیشتر به PEP 688 مراجعه کنید. (مشارکتشده توسط Shantanu Jain در gh-91896.)
-
The
tkinter.Variablemethodstrace_variable(),trace()(an alias oftrace_variable()),trace_vdelete()andtrace_vinfo(), deprecated since Python 3.14, are scheduled for removal in Python 3.17. Usetrace_add(),trace_remove()andtrace_info()instead. (Contributed by Serhiy Storchaka in gh-120220.)
در انتظار حذف در پایتون 3.18¶
در انتظار حذف در پایتون 3.19¶
-
In hash function constructors such as
new()or the direct hash-named constructors such asmd5()andsha256(), their optional initial data parameter could also be passed a keyword argument nameddata=orstring=in varioushashlibimplementations.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.
-
http.cookies.Morsel.js_output()is deprecated and will be removed in Python 3.19.http.cookies.BaseCookie.js_output()is deprecated and will be removed in Python 3.19.
-
Altering
IMAP4.fileis now deprecated and slated for removal in Python 3.19. This property is now unused and changing its value does not automatically close the current file.Before Python 3.14, this property was used to implement the corresponding
read()andreadline()methods forIMAP4but this is no longer the case since then.
-
tkinter.filedialog.askopenfiles()has been deprecated since Python 3.16. Iterate over the names returned byaskopenfilenames()and open them one by one instead. (Contributed by Serhiy Storchaka in gh-152638.)
Pending removal in Python 3.20¶
Calling the
__new__()method ofstruct.Structwithout the format argument is deprecated and will be removed in Python 3.20. Calling__init__()method on initializedStructobjects is deprecated and will be removed in Python 3.20.(Contributed by Sergey B Kirpichev and Serhiy Storchaka in gh-143715.)
The
__version__,versionandVERSIONattributes have been deprecated in these standard library modules and will be removed in Python 3.20. Usesys.version_infoinstead.ctypes.macholibdecimal(usedecimal.SPEC_VERSIONinstead)logging(__date__also deprecated)xml.sax.expatreader
(Contributed by Hugo van Kemenade and Stan Ulbrych in gh-76007.)
Deprecations defined by PEP 829:
Warnings are produced for
importlines found inname.pthfiles.name.pthfiles are no longer decoded in the locale encoding by default. They MUST be encoded inutf-8-sig.
(Contributed by Barry Warsaw in gh-148641.)
ast:Creating instances of abstract AST nodes (such as
ast.ASTorast.expr) is deprecated and will raise an error in Python 3.20.
-
It is deprecated to call
isinstance()andissubclass()checks on protocol classes that were not explicitly decorated withruntime_checkable()but that inherit from a runtime-checkable protocol class. This will raise aTypeErrorin Python 3.20.(Contributed by Bartosz Sławecki in gh-132604.)
Pending removal in Python 3.21¶
-
Soft-deprecated since Python 3.3
abc.abstractclassmethod,abc.abstractstaticmethod, andabc.abstractpropertynow raise aDeprecationWarning. These classes will be removed in Python 3.21, instead useabc.abstractmethod()withclassmethod(),staticmethod(), andpropertyrespectively.
ast:Classes
slice,Index,ExtSlice,Suite,Param,AugLoadandAugStore, will be removed in Python 3.21. These types are not generated by the parser or accepted by the code generator.The
dimsproperty ofast.Tuplewill be removed in Python 3.21. Use theast.Tuple.eltsproperty instead.
-
Soft-deprecated since Python 3.15, using
'F'and'D'type codes are now deprecated. These codes will be removed in Python 3.21. Use instead two-letter forms'Zf'and'Zd'.
-
tempfile._TemporaryFileWrapperwill be removed in Python 3.21. Use the publictempfile.TemporaryFileWrapperinstead.
در انتظار حذف در نسخههای آینده¶
APIهای زیر در آینده حذف خواهند شد، اگرچه در حال حاضر تاریخی برای حذف آنها برنامهریزی نشده است.
-
تودرتو کردن گروههای آرگومان و تودرتو کردن گروههای انحصاری متقابل منسوخ شدهاند.
گذراندن آرگومان کلیدواژهای مستندنشدهی prefix_chars به
add_argument_group()اکنون منسوخ شده است.مبدل نوع
argparse.FileTypeمنسوخ شده است.
-
تولیدگرها: امضای
throw(type, exc, tb)وathrow(type, exc, tb)منسوخ شده است؛ به جای آن ازthrow(exc)وathrow(exc)استفاده کنید — امضای تکآرگومانی.در حال حاضر پایتون مقادیر لفظی عددی را میپذیرد که بلافاصله کلیدواژهای پس از آنها میآید، برای مثال
0in x،1or x،0if 1else 2. این اجازه میدهد عبارتهای گیجکننده و مبهمی مانند[0x1for x in y]نوشته شوند (که میتوان آن را به صورت[0x1 for x in y]یا[0x1f or x in y]تفسیر کرد). اگر مقدار لفظی عددی بلافاصله با یکی از کلیدواژههایand،else،for،if،in،isوorدنبال شود، یک هشدار سینتکس اکسپورت میشود. در یک نسخهی آینده این مورد به یک خطای سینتکس تبدیل خواهد شد. (gh-87999)پشتیبانی از بازگرداندن نوعی غیر از int توسط متدهای
__index__()و__int__(): این متدها ملزم خواهند شد که نمونهای از یک زیرکلاس محضِintرا بازگردانند.پشتیبانی از متد
__float__()که زیرکلاس اکیدی ازfloatرا برمیگرداند: این متدها ملزم خواهند شد که نمونهای ازfloatرا بازگردانند.پشتیبانی از متد
__complex__()که زیرکلاس اکیدِcomplexرا برمیگرداند: این متدها ملزم خواهند شد که نمونهای ازcomplexرا برگردانند.گذراندن یک عدد مختلط بهعنوان آرگومان real یا imag در سازندهی
complex()اکنون منسوخ شده است؛ این عدد باید فقط بهصورت یک آرگومان جایگاهی واحد ارسال شود. (مشارکت Serhiy Storchaka در gh-109218.)
calendar: ثابتهایcalendar.Januaryوcalendar.Februaryمنسوخ شدهاند و باcalendar.JANUARYوcalendar.FEBRUARYجایگزین شدهاند. (مشارکتشده توسط Prince Roshan در gh-103636.)codecs: بهجایcodecs.open()ازopen()استفاده کنید. (gh-133038)codeobject.co_lnotab: use thecodeobject.co_lines()method instead.-
utcnow(): ازdatetime.datetime.now(tz=datetime.UTC)استفاده کنید.utcfromtimestamp(): ازdatetime.datetime.fromtimestamp(timestamp, tz=datetime.UTC)استفاده کنید.
gettext: مقدار جمع باید یک عدد صحیح باشد.-
پارامتر debug_override در
cache_from_source()منسوخ شده است: به جای آن از پارامتر optimization استفاده کنید.
-
رابط تاپلیِ
EntryPoints.Noneضمنی در مقادیر بازگشتی.
logging: متدwarn()از پایتون 3.3 به بعد منسوخ شده است؛ به جای آن ازwarning()استفاده کنید.mailbox: استفاده از ورودی StringIO و حالت متنی منسوخ شده است؛ بهجای آن از BytesIO و حالت دودویی استفاده کنید.os: Callingos.register_at_fork()in a multi-threaded process.os.path:os.path.commonprefix()is deprecated, useos.path.commonpath()for path prefixes. Theos.path.commonprefix()function is being deprecated due to having a misleading name and module. The function is not safe to use for path prefixes despite being included in a module about path manipulation, meaning it is easy to accidentally introduce path traversal vulnerabilities into Python programs by using this function.pydoc.ErrorDuringImport: مقدار تاپل برای پارامتر exc_info منسوخ شده است؛ از یک نمونه استثنا استفاده کنید.re: اکنون قواعد سختگیرانهتری برای ارجاعهای عددی گروه و نام گروهها در عبارتهای باقاعده اعمال میشود. اکنون فقط دنبالهای از ارقام اسکی بهعنوان ارجاع عددی پذیرفته میشود. نام گروه در الگوهای بایتی و رشتههای جایگزین اکنون فقط میتواند شامل حروف و ارقام اسکی و زیرخط باشد. (مشارکتشده توسط Serhiy Storchaka در gh-91760.)shutil: پارامتر onerror درrmtree()در پایتون 3.12 منسوخ شده است؛ بهجای آن از پارامتر onexc استفاده کنید.گزینهها و پروتکلهای
ssl:ssl.SSLContextبدون آرگومان پروتکل، منسوخ شده است.ssl.SSLContext: متدهایset_npn_protocols()وselected_npn_protocol()منسوخ شدهاند: بهجای آنها از ALPN استفاده کنید.گزینههای
ssl.OP_NO_SSL*گزینههای
ssl.OP_NO_TLS*ssl.PROTOCOL_SSLv3ssl.PROTOCOL_TLSssl.PROTOCOL_TLSv1ssl.PROTOCOL_TLSv1_1ssl.PROTOCOL_TLSv1_2ssl.TLSVersion.SSLv3ssl.TLSVersion.TLSv1ssl.TLSVersion.TLSv1_1
متدهای
threading:threading.Condition.notifyAll(): ازnotify_all()استفاده کنید.threading.Event.isSet(): ازis_set()استفاده کنید.threading.Thread.isDaemon()،threading.Thread.setDaemon(): از ویژگیthreading.Thread.daemonاستفاده کنید.threading.Thread.getName()،threading.Thread.setName(): از ویژگیthreading.Thread.nameاستفاده کنید.threading.currentThread(): ازthreading.current_thread()استفاده کنید.threading.activeCount(): ازthreading.active_count()استفاده کنید.
کلاس داخلی
typing._UnionGenericAliasدیگر برای پیادهسازیtyping.Unionاستفاده نمیشود. برای حفظ سازگاری با کاربرانی که از این کلاس خصوصی استفاده میکنند، یک لایهی سازگاری (shim) تا دستکم Python 3.17 ارائه خواهد شد. (مشارکتشده توسط Jelle Zijlstra در gh-105499.)unittest.IsolatedAsyncioTestCase: برگرداندن مقداری غیر ازNoneاز یک مورد آزمون منسوخ شده است.توابع منسوخ
urllib.parse: بهجای آنهاurlparse()splitattr()splithost()splitnport()splitpasswd()splitport()splitquery()splittag()splittype()splituser()splitvalue()to_bytes()
wsgiref:SimpleHandler.stdout.write()نباید نوشتن جزئی (partial write) انجام دهد.xml.etree.ElementTree: آزمودن مقدار درستی یکElementمنسوخ شده است. در نسخهای در آینده، همیشهTrueبازگردانده خواهد شد. به جای آن، آزمونهای صریحlen(elem)یاelem is not Noneرا ترجیح دهید.sys._clear_type_cache()منسوخ شده است: به جای آن ازsys._clear_internal_caches()استفاده کنید.
Soft deprecations¶
There are no plans to remove soft deprecated APIs.
re.match()andre.Pattern.match()are now soft deprecated in favor of the newre.prefixmatch()andre.Pattern.prefixmatch()APIs, which have been added as alternate, more explicit names. These are intended to be used to alleviate confusion around what match means by following the Zen of Python's "Explicit is better than implicit" mantra. Most other language regular expression libraries use an API named match to mean what Python has always called search.We do not plan to remove the older
match()name, as it has been used in code for over 30 years. Code supporting older versions of Python should continue to usematch(), while new code should preferprefixmatch(). See prefixmatch() vs. match().(Contributed by Gregory P. Smith in gh-86519 and Hugo van Kemenade in gh-148100.)
منسوخشدههای C API¶
در انتظار حذف در پایتون 3.18¶
توابع خصوصی زیر منسوخ شدهاند و حذف آنها در پایتون 3.18 برنامهریزی شده است:
_PyBytes_Join(): ازPyBytes_Join()استفاده کنید._PyDict_GetItemStringWithError(): ازPyDict_GetItemStringRef()استفاده کنید._PyDict_Pop(): ازPyDict_Pop()استفاده کنید._PyLong_Sign(): ازPyLong_GetSign()استفاده کنید._PyLong_FromDigits()و_PyLong_New(): ازPyLongWriter_Create()استفاده کنید._PyThreadState_UncheckedGet(): ازPyThreadState_GetUnchecked()استفاده کنید._PyUnicode_AsString(): ازPyUnicode_AsUTF8()استفاده کنید._PyUnicodeWriter_Init():_PyUnicodeWriter_Init(&writer)را باwriter = PyUnicodeWriter_Create(0)جایگزین کنید._PyUnicodeWriter_Finish(): عبارت_PyUnicodeWriter_Finish(&writer)را باPyUnicodeWriter_Finish(writer)جایگزین کنید._PyUnicodeWriter_Dealloc():_PyUnicodeWriter_Dealloc(&writer)را باPyUnicodeWriter_Discard(writer)جایگزین کنید._PyUnicodeWriter_WriteChar():_PyUnicodeWriter_WriteChar(&writer, ch)را باPyUnicodeWriter_WriteChar(writer, ch)جایگزین کنید._PyUnicodeWriter_WriteStr():_PyUnicodeWriter_WriteStr(&writer, str)را باPyUnicodeWriter_WriteStr(writer, str)جایگزین کنید._PyUnicodeWriter_WriteSubstring(): عبارت_PyUnicodeWriter_WriteSubstring(&writer, str, start, end)را باPyUnicodeWriter_WriteSubstring(writer, str, start, end)جایگزین کنید._PyUnicodeWriter_WriteASCIIString():_PyUnicodeWriter_WriteASCIIString(&writer, str)را باPyUnicodeWriter_WriteASCII(writer, str)جایگزین کنید._PyUnicodeWriter_WriteLatin1String():_PyUnicodeWriter_WriteLatin1String(&writer, str)را باPyUnicodeWriter_WriteUTF8(writer, str)جایگزین کنید._PyUnicodeWriter_Prepare(): (بدون جایگزین)._PyUnicodeWriter_PrepareKind(): (بدون جایگزین)._Py_HashPointer(): ازPy_HashPointer()استفاده کنید._Py_fopen_obj(): ازPy_fopen()استفاده کنید.PyGen_New(): (no replacement).PyGen_NewWithQualName(): (no replacement).PyCoro_New(): (no replacement).PyAsyncGen_New(): (no replacement).
میتوان از پروژهی pythoncapi-compat برای به دست آوردن این توابع عمومی جدید در پایتون 3.13 و نسخههای قدیمیتر استفاده کرد. (مشارکتشده توسط Victor Stinner در gh-128863.)
در انتظار حذف در پایتون 3.19¶
PEP 456 embedders support for the string hashing scheme definition.
Pending removal in Python 3.20¶
_PyObject_CallMethodId(),_PyObject_GetAttrId()and_PyUnicode_FromId()are deprecated since 3.15 and will be removed in 3.20. Instead, usePyUnicode_InternFromString()and cache the result in the module state, then callPyObject_CallMethod()orPyObject_GetAttr(). (Contributed by Victor Stinner in gh-141049.)The
cvalfield inPyComplexObject(gh-128813). UsePyComplex_AsCComplex()andPyComplex_FromCComplex()to convert a Python complex number to/from the CPy_complexrepresentation.Macros
Py_MATH_PIlandPy_MATH_El.
در انتظار حذف در نسخههای آینده¶
APIهای زیر منسوخ شدهاند و حذف خواهند شد، اگرچه در حال حاضر هیچ تاریخی برای حذف آنها تعیین نشده است.
Py_TPFLAGS_HAVE_FINALIZE: از پایتون 3.8 به بعد مورد نیاز نیست.PyErr_Fetch(): بهجای آن ازPyErr_GetRaisedException()استفاده کنید.PyErr_NormalizeException(): به جای آن ازPyErr_GetRaisedException()استفاده کنید.PyErr_Restore(): بهجای آن ازPyErr_SetRaisedException()استفاده کنید.PyModule_GetFilename(): بهجای آن ازPyModule_GetFilenameObject()استفاده کنید.PyOS_AfterFork(): بهجای آن ازPyOS_AfterFork_Child()استفاده کنید.PySlice_GetIndicesEx(): بهجای آن ازPySlice_Unpack()وPySlice_AdjustIndices()استفاده کنید.PyUnicode_READY(): از پایتون 3.12 به بعد نیازی به آن نیستPyErr_Display(): بهجای آن ازPyErr_DisplayException()استفاده کنید._PyErr_ChainExceptions(): بهجای آن از_PyErr_ChainExceptions1()استفاده کنید.عضو
PyBytesObject.ob_shash: به جای آنPyObject_Hash()را فراخوانی کنید.API ذخیرهسازی محلی نخ (TLS):
PyThread_create_key(): بهجای آن ازPyThread_tss_alloc()استفاده کنید.PyThread_delete_key(): بهجای آن ازPyThread_tss_free()استفاده کنید.PyThread_set_key_value(): بهجای آن ازPyThread_tss_set()استفاده کنید.PyThread_get_key_value(): بهجای آن ازPyThread_tss_get()استفاده کنید.PyThread_delete_key_value(): به جای آن ازPyThread_tss_delete()استفاده کنید.PyThread_ReInitTLS(): از پایتون 3.7 به بعد لازم نیست.