V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
watsy0007
V2EX  ›  Python

Python 3.8 即将发布了.

  •  
  •   watsy0007 ·
    watsy0007 · 2019-10-08 09:47:32 +08:00 · 8604 次点击
    这是一个创建于 1633 天前的主题,其中的信息可能已经有所发展或是发生改变。

    准备升级了....

    python 3.8 release date

    3.8.0 candidate 2: Monday, 2019-10-07 (if necessary)
    3.8.0 final: Monday, 2019-10-14 (assuming a single release candidate)

    Features for 3.8 Some of the notable features of Python 3.8 include:

    • PEP 570, Positional-only arguments
    • PEP 572, Assignment Expressions
    • PEP 574, Pickle protocol 5 with out-of-band data
    • PEP 578, Runtime audit hooks
    • PEP 587, Python Initialization Configuration
    • PEP 590, Vectorcall: a fast calling protocol for CPython
    • Typing-related: PEP 591 (Final qualifier), PEP 586 (Literal types), and PEP 589 (TypedDict)
    • Parallel filesystem cache for compiled bytecode
    • Debug builds share ABI as release builds
    • f-strings support a handy = specifier for debugging
    • continue is now legal in finally: blocks
    • on Windows, the default asyncio event loop is now ProactorEventLoop
    • on macOS, the spawn start method is now used by default in multiprocessing
    • multiprocessing can now use shared memory segments to avoid pickling costs between processes
    • typed_ast is merged back to CPython
    • LOAD_GLOBAL is now 40% faster
    • pickle now uses Protocol 4 by default, improving performance
    • There are many other interesting changes, please consult the "What's New" page in the documentation for a full list.
    58 条回复    2019-10-12 00:08:38 +08:00
    alfredsun
        1
    alfredsun  
       2019-10-08 09:49:48 +08:00   ❤️ 13
    即将不能用于完成时
    liuzhaowei55
        2
    liuzhaowei55  
       2019-10-08 09:50:15 +08:00
    哎。。。
    watsy0007
        3
    watsy0007  
    OP
       2019-10-08 09:53:33 +08:00
    @alfredsun 准备升级...
    onmyoji
        4
    onmyoji  
       2019-10-08 09:58:20 +08:00
    官网不是还是 3.7.4 吗?
    xiri
        5
    xiri  
       2019-10-08 10:05:16 +08:00 via Android
    要那么新干嘛,还在用 3.6🐶
    Juszoe
        6
    Juszoe  
       2019-10-08 10:05:29 +08:00
    哪位总结一下有什么好用的特性
    chenstack
        7
    chenstack  
       2019-10-08 10:06:03 +08:00
    上次看到的 final 日期还是 10.28
    youthfire
        8
    youthfire  
       2019-10-08 10:07:44 +08:00 via iPhone
    3.6 升级到 3.7 的时候感觉性能提升明显,平时用的脚步速度提升了约 15%。这次看看了。
    qlhai
        9
    qlhai  
       2019-10-08 10:19:17 +08:00   ❤️ 3
    还在用 2.7 的默默路过
    cmdOptionKana
        10
    cmdOptionKana  
       2019-10-08 10:21:20 +08:00   ❤️ 2
    @alfredsun 中文“了”字结尾不一定是完成时(中文语法本身没有时态)。

    “好了吗?快点出来”
    “快好了,快好了”
    XIVN1987
        11
    XIVN1987  
       2019-10-08 10:46:21 +08:00 via Android
    只有赋值表达式是重大改动吧,,
    deorth
        12
    deorth  
       2019-10-08 11:14:12 +08:00
    子解释器上了吗
    watsy0007
        13
    watsy0007  
    OP
       2019-10-08 11:15:16 +08:00
    @youthfire 是的... 特性的话, [pep 572]( https://www.zhihu.com/question/274823057) 让 python 之父很恼火...
    watsy0007
        14
    watsy0007  
    OP
       2019-10-08 11:20:34 +08:00
    @deorth multiple interpreters ? 这里提案在 [pep 554]( https://www.python.org/dev/peps/pep-0554/) 我看了下 3.9 版本才会发
    mywaiting
        15
    mywaiting  
       2019-10-08 11:21:11 +08:00
    感觉 typing hints 再努力努力,python 就可以考虑分支为动态脚本、静态编译两个实现了

    有哪个大牛去提个 PEP ?
    watsy0007
        16
    watsy0007  
    OP
       2019-10-08 11:22:03 +08:00
    @cmdOptionKana 标注时间了呀. 下周一可以试试了.
    watsy0007
        17
    watsy0007  
    OP
       2019-10-08 11:22:16 +08:00
    @qlhai 升吧.
    watsy0007
        18
    watsy0007  
    OP
       2019-10-08 11:23:04 +08:00
    @mywaiting 不大可能. 可以用 mypy.
    iPhoneXI
        19
    iPhoneXI  
       2019-10-08 11:24:28 +08:00 via Android
    @mywaiting 不太乐观,TypeScript 类型更强,但是也没静态编译到原生二进制吧
    ipwx
        20
    ipwx  
       2019-10-08 11:31:40 +08:00
    我的看法:3.8 也就更新了这两件值得注意的事情

    1、加强了 Type Hinting,增加了 Duck Type Hinting 的支持。
    2、assignment operation。

    小打小闹而已。
    watsy0007
        21
    watsy0007  
    OP
       2019-10-08 11:34:29 +08:00
    @ipwx 嗯, 日常更新. 另外 assignment operation 我还在考虑用不用...
    mywaiting
        22
    mywaiting  
       2019-10-08 11:43:18 +08:00
    @iPhoneXI 我觉得这就是哪天哪个大牛心血来潮搞一下的事情.......
    laike9m
        23
    laike9m  
       2019-10-08 11:51:37 +08:00
    @deorth 没上
    cat9life
        24
    cat9life  
       2019-10-08 11:52:14 +08:00
    @youthfire 会有这种性能提升?
    laike9m
        25
    laike9m  
       2019-10-08 11:53:10 +08:00
    @watsy0007 能用还是尽量用,确实让代码更简洁,毕竟连 C++ 都有类似语法了
    Mohanson
        26
    Mohanson  
       2019-10-08 12:00:40 +08:00 via Android
    @iPhoneXI minits 项目正在做 ts 的静态编译器
    watsy0007
        27
    watsy0007  
    OP
       2019-10-08 12:03:37 +08:00
    @laike9m 是啊...考虑中.
    laike9m
        28
    laike9m  
       2019-10-08 12:04:31 +08:00
    @ipwx Duck Type Hinting 是指?
    youthfire
        29
    youthfire  
       2019-10-08 12:04:35 +08:00
    @cat9life 主要看 changelog 里有没有 performance 提升,当然也和脚本具体内容有关,可能正好是作用到那段代码了,因为平时我都带计时,所以很明显。
    love
        30
    love  
       2019-10-08 12:06:06 +08:00
    python 这越来越复杂,传个参都整这么多花样有必要么,JS 这么简单写起来还比 py 舒服
    watsy0007
        31
    watsy0007  
    OP
       2019-10-08 12:12:14 +08:00
    @love 场景不一样. 不能简单这样比较. 各有各的优劣.
    rogwan
        32
    rogwan  
       2019-10-08 12:12:49 +08:00 via Android
    @watsy0007 我也觉得 pep572 有点画蛇添足。社区那么多人反对,主要理由也是增加的便捷性不大,带来的复杂度提升过冗。
    laike9m
        33
    laike9m  
       2019-10-08 12:18:02 +08:00
    @rogwan 那 Golang 和 C++ 也都在画蛇添足了
    这一期我们稍微聊过一下 572,主要的槽点我认为在于语法没有强制限定使用范围: https://www.pythonhunter.org/episodes/5
    XIVN1987
        34
    XIVN1987  
       2019-10-08 12:22:58 +08:00
    @love
    可是你们还得学 TypeScript 啊,,JS 的很多库(比如 Vue )都用 TypeScript 写了,,
    love
        35
    love  
       2019-10-08 12:28:05 +08:00
    @XIVN1987 我写 js 也全是用 typescript 啊,觉得不难,js 本质是个简单的语言。哪怕在底层 py 的复杂性都完暴 js,元类什么的我以前研究完就觉得过度设计。
    rogwan
        36
    rogwan  
       2019-10-08 12:29:30 +08:00 via Android
    @laike9m 对这点龟叔大概的意思是:有这个方法,你可以不用啊。然后,社区就反对,这不 Pythonic。

    简单说,就是好处坏处都不大,不太符合奥卡姆原理。
    Trim21
        37
    Trim21  
       2019-10-08 12:33:33 +08:00 via Android
    前几天看完了 what's new,感觉不像 3.6 和 3.7 有非常吸引人升级的特性…
    w1573007
        38
    w1573007  
       2019-10-08 12:40:12 +08:00 via Android
    @cmdOptionKana 疑车无据
    ipwx
        39
    ipwx  
       2019-10-08 12:42:57 +08:00 via Android
    XIVN1987
        40
    XIVN1987  
       2019-10-08 12:43:06 +08:00   ❤️ 2
    @love
    元类是给库、框架开发人员用的,我们不需要深究

    正是因为 Python 有这些复杂的语法机制,Python 的用户 API 才能这么易用,,

    如果 Python 没有__xxx__那一堆魔法函数,numpy 就不会出现,,没有 numpy 的话 Python 就不可能在数值计算、数据分析、机器学习、深度学习这些领域流行起来

    Python 里的 ORM 也依赖元类实现,,不知道 JS 中的 ORM 相比于 Python 中的 ORM 使用起来怎么样,,没有对比过,,
    mamahaha
        41
    mamahaha  
       2019-10-08 12:50:02 +08:00   ❤️ 1
    ## Java
    > 百度为您找到相关结果约 69,100,000 个
    ## python
    > 百度为您找到相关结果约 38,500,000 个
    ## c++
    > 百度为您找到相关结果约 59,700,000 个
    ## golang
    > 百度为您找到相关结果约 24,600,000 个
    XIVN1987
        42
    XIVN1987  
       2019-10-08 12:50:45 +08:00
    PEP 572 还是能够接受的,,毕竟使用场景比较明确,,

    PEP 505 -- None-aware operators 就不能接受了,,还好 Deferred 了,希望不要通过
    XIVN1987
        43
    XIVN1987  
       2019-10-08 12:52:50 +08:00
    @mamahaha

    最好再统计下 github、StackOverflow、google、quora、知乎等多种数据来源综合下,,单一数据说服力不够,,
    laike9m
        44
    laike9m  
       2019-10-08 12:54:28 +08:00 via Android
    @ipwx thanks,这个不错
    lrxiao
        45
    lrxiao  
       2019-10-08 13:12:15 +08:00
    LOAD_GLOBAL is now 40% faster
    这不算巨大提升吗...调用函数都要 LOAD GLOBAL 的
    BOYPT
        46
    BOYPT  
       2019-10-08 14:24:45 +08:00
    (学不动了
    watsy0007
        47
    watsy0007  
    OP
       2019-10-08 14:48:07 +08:00
    @lrxiao
    alfredsun
        48
    alfredsun  
       2019-10-08 16:00:04 +08:00
    @cmdOptionKana 中文没有时态不代表了不能表完成啊
    就举的例子里,“好”和“好了”的区别就是一个是原型一个是表完成啊,你把“好了”封装成名词做句子成分当然就看不出来了。
    sangsi
        49
    sangsi  
       2019-10-08 17:32:24 +08:00
    @BOYPT 同感!
    woshi88
        50
    woshi88  
       2019-10-09 09:44:04 +08:00
    弃坑了,始于 2.7 止于 3.6
    prenwang
        51
    prenwang  
       2019-10-09 10:01:19 +08:00
    multiprocessing can now use shared memory segments to avoid pickling costs between processes 这个好
    venster
        52
    venster  
       2019-10-09 11:45:35 +08:00
    @alfredsun “即将发布”是一个确定的状态,已经发生了,用“了”没毛病。
    watsy0007
        53
    watsy0007  
    OP
       2019-10-09 15:09:42 +08:00
    wuwukai007
        54
    wuwukai007  
       2019-10-09 16:21:13 +08:00
    一定要用 3.6+,提升太明显了!
    watsy0007
        55
    watsy0007  
    OP
       2019-10-11 12:41:09 +08:00
    @wuwukai007 https://docs.python.org/3.8/whatsnew/3.8.html#optimizations 看了下优化部分, 还是挺明显的.

    Improved performance of operator.itemgetter() by *33%*. Optimized argument handling and added a fast path for the common case of a single non-negative integer index into a tuple (which is the typical use case in the standard library).


    Sped-up field lookups in `collections.namedtuple()`. They are now more than two times faster, making them the fastest form of instance variable lookup in Python.


    The list constructor does not overallocate the internal item buffer if the input iterable has a known length (the input implements __len__). This makes the created list *12%* smaller on average.


    Reduced an overhead of converting arguments passed to many builtin functions and methods. This sped up calling some simple builtin functions and methods up to *20–50%*.


    LOAD_GLOBAL instruction now uses new “per opcode cache” mechanism. It is about *40%* faster now.
    lrxiao
        57
    lrxiao  
       2019-10-11 14:51:49 +08:00
    @watsy0007 为什么这个测试结果有这么多不一致的地方...
    watsy0007
        58
    watsy0007  
    OP
       2019-10-12 00:08:38 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3265 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 63ms · UTC 12:02 · PVG 20:02 · LAX 05:02 · JFK 08:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.