Ho lokolloa ha puo ea lenaneo la Python 3.9

Kamora selemo sa ntshetsopele hlahisoa tokollo ea bohlokoa ea puo ea lenaneo python 3.9. Python 3.9 e bile tokollo ea pele kamora moo phetoho morero on potoloho e ncha boitokisetso le tšehetso ea litokollo. Litokollo tse ncha tse kholo joale li tla hlahisoa hang ka selemo, 'me lintlafatso tsa tokiso li tla lokolloa likhoeling tse ling le tse ling tse peli. Lekala le leng le le leng la bohlokoa le tla tšehetsoa ka selemo le halofo, ebe ka mor'a moo ho tla ntlafatsoa lilemo tse ling tse tharo le halofo bakeng sa ho lokisa mefokolo.

Mosebetsi lekaleng le lecha joale o qala likhoeli tse hlano pele ho lokolloa lekala le latelang, i.e. e tsamaellanang le ho lokolloa ha Python 3.9 qadile tlhahlobo ea alpha ea lekala la Python 3.10. Lekala la Python 3.10 le tla ba ka har'a tokollo ea alpha ka likhoeli tse supileng, moo likarolo tse ncha li tla eketsoa le ho lokisoa liphoso. Ka mor'a sena, liphetolelo tsa beta li tla lekoa ka likhoeli tse tharo, moo ho eketsa likarolo tse ncha ho tla thibeloa 'me tlhokomelo eohle e tla lefshoa ho lokisa liphoso. Likhoeli tse peli tsa ho qetela pele ho lokolloa, lekala le tla be le le boemong ba mokhethoa oa ho lokolloa, moo ho tla etsoa botsitso ba ho qetela.

har'a eketsoe boiqapelo ho Python 3.9:

  • Ho lidikishinari tse hlalosoang ho sebelisoa sehlopha sa dict se hahiloeng, e hlahile tšehetso bakeng sa ho kopanya basebelisi "|" le "|=" diapdeite, tse tlatselletsang {**d1, **d2} le dict.update mekhoa e neng e sisintswe pele bakeng sa ho kopanya dikishinari.

    >>> x = {"key1": "boleng1 ho tloha ho x", "key2": "boleng2 ho tloha ho x"}
    >>> y = {"key2": "boleng2 ho tloha ho y", "key3": "boleng3 ho tloha ho y"}

    >>> x | y
    {'key1': 'boleng1 ho tswa ho x', 'key2': 'boleng2 ho tswa ho y', 'key3': 'boleng3 ho tswa ho y'}

    >>> ke | x
    {'key2': 'boleng2 ho tloha ho x', 'key3': 'boleng3 ho tloha ho y', 'key1': 'boleng1 ho tloha ho x'}

  • Pokello e hahelletsoeng ka hare ea mefuta e kenyelletsa lethathamo, dict, le tuple, tse ka sebelisoang e le mefuta ea motheo ntle le ho reka kantle ho mochini oa ho thaepa. Tseo. sebakeng sa ho thaepa.Lethathamo, ho tlanya.Dict le ho thaepa.Tuple jwale o ka hlakisa
    lethathamo feela, dict le tuple:

    def greet_all(mabitso: list[str]) -> Ha ho letho:
    bakeng sa mabitso ka mabitso:
    print("Hello", lebitso)

  • Li fanoe lisebelisoa tse feto-fetohang bakeng sa lits'ebetso le mefuta e fapaneng. Bakeng sa ho hokela litlhaloso, ho kentsoe mofuta o mocha oa Annotated mojulung oa ho thaepa, ho atolosa mefuta e teng ka metadata e eketsehileng e ka sebelisoang bakeng sa tlhahlobo e tsitsitseng kapa bakeng sa ho ntlafatsa nako ea ho sebetsa. Ho fihlella metadata ho tsoa khouto, ho kenyellelitsoe_extras parameter mokhoeng oa typing.get_type_hints().

    charType = Annotated[int, ctype("char")] UnsignedShort = Annotated[int, struct2.ctype('H')]

  • E fokotsehile litlhoko tsa sebōpeho-puo bakeng sa ba khabisang - polelo leha e le efe e loketseng ho sebelisoa ha li-blocks joale li ka sebelisoa e le mokhabiso. Phetoho e ntlafalitse haholo ho baloa ha khoutu ea PyQt5 mme ea nolofatsa tlhokomelo ea mojule ona:

    E ne e le:
    button_0 = likonopo[0] @button_0.clicked.connect

    Joale u ka ngola:
    @buttons[0].clicked.connect

  • Ho ea laebraring e tloaelehileng eketsa mojule libaka, e kenyeletsang lintlha tse tsoang ho database tsa sebaka sa nako sa IANA.

    >>> ho tsoa ho zoneinfo import ZoneInfo
    >>> ho tloha ho datetime import datetime, timedelta
    >>> # Nako ea lehlabula
    >>> dt = nako (2020, 10, 31, 12, tzinfo=ZoneInfo("America/Los_Angeles"))
    >>> hatisa(dt)
    2020-10-31 12:00:00-07:00

    >>> dt.tzname()
    'PDT'

    >>> # Nako e tloaelehileng
    >>> dt += timedelta(matsatsi=7)
    >>> hatisa(dt)
    2020-11-07 12:00:00-08:00

    >>> hatisa(dt.tzname())
    PST

  • E kenyellelitsoe graphlib module, eo ho eona kenngwa tshebetsong tshehetso bakeng sa ho hlopha dikerafo tsa hodimo.
  • E sisintsweng mekgwa e metjha ya ho tlosa dihlongwapele le methalo ya mela - str.removeprefix(prefix) le str.tlosa sehlomathi (sehlongoana). Mekhoa e kenyelelitsoe ho str, byte, bytearray le pokello.UserString objects.

    >>> s = "FooBar"
    >>> s.removeprefix("Foo")
    'Bar'

  • Kenyelelitsoe mohlahlobi e mocha PEG (Parsing Expression Grammar), e nkileng sebaka sa mohlahlobi LL(1). Tšebeliso ea parser e ncha e entse hore ho khonehe ho tlosa tse ling tsa "hacks" tse sebelisoang ho tlōla lithibelo ho LL (1), 'me li fokotse haholo litšenyehelo tsa basebetsi bakeng sa ho boloka mohlahlobi. Mabapi le ts'ebetso, parser e ncha e batla e le boemong bo lekanang le ba pele, empa e ka pele ho eona haholo mabapi le ho feto-fetoha ha maemo, e leng se u lumellang hore u ikutloe u lokolohile haholoanyane ha u qapa likarolo tse ncha tsa puo. Khoutu ea khale ea parser e bolokiloe hajoale 'me e ka khutlisoa ho sebelisoa folakha ea "-X oldparser" kapa "PYTHONOLDPARSER=1" e fapaneng ea tikoloho, empa e tla tlosoa tokollong ea 3.10.
  • Fanetsoe bokhoni ba mekhoa ea katoloso ea C ho fihlella boemo ba li-module tseo li hlalosoang ho tsona ho sebelisoa li-pointer dereference ho e-na le ho batla boemo ba module ho sebelisa mosebetsi oa PyState_FindModule. Phetoho e u lumella ho eketsa ts'ebetso ea li-module tsa C ka ho fokotsa kapa ho felisa ka ho feletseng ho hlahloba boemo ba module. Ho amahanya mojule le sehlopha, ho entsoe tlhahiso ea C-function PyType_FromModuleAndSpec(), ho fumana mojule le boemo ba eona, C-functions PyType_GetModule() le PyType_GetModuleState() lia sisinngoa, le ho fana ka mokhoa oa phihlello ho sehlopha. moo e hlalosoang teng, ho sisinyeha C-function PyCMethod le METH_METHOD folakha.
  • 'mokelli oa lithōle hlahisitsoe ho tsoa ho lipokello tsa ho notlela tse nang le lintho tse phetoang tse lulang li fumaneha ka ntle ka mor'a hore motho ea qetellang a sebetse.
  • Mokhoa o ekelitsoeng os.pidfd_open, e lumellang Linux kernel subsystem "pidfd" hore e sebelisoe ho sebetsana le boemo ba ho sebelisa PID hape (pidfd e amahanngoa le ts'ebetso e itseng 'me ha e fetohe, ha PID e ka amahanngoa le ts'ebetso e' ngoe ka mor'a hore ts'ebetso ea hona joale e amanang le PID eo e fele. ).
  • Ts'ehetso ea litlhaloso tsa Unicode e ntlafalitsoe hore e be mofuta oa 13.0.0.
  • E felisitsoe ho dutla mohopolong ha o qala mofetoleli oa Python ka mokhoa o ts'oanang.
  • Ts'ebetso ea mefuta e hahelletsoeng kahare, tuple, set, frozenset, list le dict e ntlafalitsoe. kenngwa tshebetsong ka tšebeliso ea protocol ea tsela e khaoletsang ea Vectorcall bakeng sa phihlello e potlakileng ea lintho tse ngotsoeng ka puo ea C.
  • Li-module _abc, audioop, _bz2, _codecs, _contextvars, _crypt, _functools, _json, _locale, opareitara, mohlodi, nako le _weakref li kentsoe qalo ka mekhahlelo e mengata.
  • Li-module tse tloaelehileng tsa laeborari ea audioop, ast, grp, _hashlib, pwd, _posixsubprocess, random, select, struct, termios le zlib li fetotsoe ho sebelisoa ho thibetsoe. ABI e tsitsitseng, e rarollang bothata ba ho sebetsa ha likopano tsa li-module tsa katoloso bakeng sa liphetolelo tse fapaneng tsa Python (ha ho ntlafatsoa phetolelo, ha ho hlokahale ho tsosolosa li-module tsa katoloso, 'me li-module tse hlophisitsoeng bakeng sa 3.9 li tla khona ho sebetsa lekaleng la 3.10).
  • Mojule oa asyncio o theohile tšehetso bakeng sa paramente ea reuse_address ka lebaka la litaba tse ka bang teng tsa ts'ireletso (ho sebelisa SO_REUSEADDR bakeng sa UDP ho Linux ho lumella lits'ebetso tse fapaneng ho hokela li-sockets tsa ho mamela boema-kepeng ba UDP).
  • Lintlafatso tse ncha li kenyellelitsoe, mohlala, ts'ebetso e ntlafetseng ea batšoantšisi ba matšoao lits'ebetsong tse nang le likhoele tse ngata, lebelo le eketsehileng la mojule oa subprocess tikolohong ea FreeBSD, le kabelo e potlakileng ea mefuta-futa ea nakoana (ho fana ka phetoho polelong "bakeng sa y in [expr ]” e sebetsa joalo ka poleloana “y = expr” "). Ka kakaretso, liteko tse ngata bonts'a ho fokotseha ha ts'ebetso ha ho bapisoa le lekala la 3.8 (ho potlakisa ho bonoa feela litekong tsa write_local and write_deque):

    Phetolelo ea Python 3.4 3.5 3.6 3.7 3.8 3.9
    ———————————

    Ho fihlella ho feto-fetoha le sebopeho sa ho bala:
    bala_ea sebakeng 7.1 7.1 5.4 5.1 3.9 4.0
    bala_e seng sebakeng 7.1 8.1 5.8 5.4 4.4 4.8
    bala_global 15.5 19.0 14.3 13.6 7.6 7.7
    bala_hahiloe 21.1 21.6 18.5 19.0 7.5 7.7
    bala_classvar_from_class 25.6 26.5 20.7 19.5 18.4 18.6
    bala_classvar_from_instance 22.8 23.5 18.8 17.1 16.4 20.1
    bala_instancevar 32.4 33.1 28.0 26.3 25.4 27.7
    bala_instancevar_slots 27.8 31.3 20.8 20.8 20.2 24.5
    bala_lebitso-lebitso 73.8 57.5 45.0 46.8 18.4 23.2
    bala_mokhoa oa moeli 37.6 37.9 29.6 26.9 27.7 45.9

    Phihlello ea ho ngola e feto-fetohang:
    ngola_sebakeng 8.7 9.3 5.5 5.3 4.3 4.2
    ngola_nonlocal 10.5 11.1 5.6 5.5 4.7 4.9
    ngola_global 19.7 21.2 18.0 18.0 15.8 17.2
    ngola_classvar 92.9 96.0 104.6 102.1 39.2 43.2
    ngola_instancevar 44.6 45.8 40.0 38.9 35.5 40.7
    ngola_instancevar_slots 35.6 36.1 27.3 26.6 25.7 27.7

    Mokhoa oa ho fumana mokhoa oa ho fumana boitsebiso:
    bala_lethathamo 24.2 24.5 20.8 20.8 19.0 21.1
    bala_deque 24.7 25.5 20.2 20.6 19.8 21.6
    bala_dict 24.3 25.7 22.3 23.0 21.0 22.5
    bala_stradict 22.6 24.3 19.5 21.2 18.9 21.6

    Phihlello ea ho ngola sebopeho sa data:
    ngola_lethathamo 27.1 28.5 22.5 21.6 20.0 21.6
    ngola_deque 28.7 30.1 22.7 21.8 23.5 23.2
    ngola_dict 31.4 33.3 29.3 29.2 24.7 27.8
    ngola_stradict 28.4 29.9 27.5 25.2 23.1 29.8

    Ts'ebetso ea stack (kapa queue):
    list_append_pop 93.4 112.7 75.4 74.2 50.8 53.9
    deque_append_pop 43.5 57.0 49.4 49.2 42.5 45.5
    deque_append_popleft 43.7 57.3 49.7 49.7 42.8 45.5

    Loop ea nako:
    loop_overhead 0.5 0.6 0.4 0.3 0.3 0.3

  • E tlositsoe mesebetsi le mekhoa e mengata ea Python 2.7 e neng e tlositsoe pele 'me ea baka Tlhokomeliso tokollong e fetileng, ho kenyeletsoa mokhoa oa unescape() ho html.parser.HTMLParser,
    tostring() and fromstring() in array.array, isAlive() in threading.Thread, getchildren() and getiterator() in ElementTree, sys.getcheckinterval(), sys.setcheckinterval(), asyncio.Task.current_task(), asyncio.Task.all_tasks(), base64.encodestring() le base64.decodestring().

Source: opennet.ru

Eketsa ka tlhaloso