Coconut v3.2.02025-12-31
Coconut本次更新主打对Python3.14的适配与警告瘦身。
新增方面,语言层加入了t-string模板字符串(t"...")的支持:3.14及以上走原生语法,3.10至3.13则编译到tstr兼容库。memoize新增RECURSIVE选项,递归期间缓存可自由增长,最外层调用结束即自动清空,既支持递归函数又不泄漏内存。
编译器侧,strict模式下的全部错误与警告现在都能用# NOQA注释单独关闭;v2兼容警告被移除,v3语法警告也仅在strict下出现,日常编译不再被提示刷屏。
同时修复了Jupyter内核默认安装后无法使用、导入包时报IsADirectoryError、JupyterLab末尾分号误触发CoconutSyntaxWarning,以及数组字面量解析和Unicode空值合并运算符??不被识别等问题。
Coconut v3.1.22024-09-01
本次更新集中在模式匹配与调用细节上。先说修复:Jupyter内核中括号内注释引发的报错已解决(#851、#852)。语言特性方面,reduce、takewhile、dropwhile现在可以接收关键字参数;类模式与数据模式也支持关键字参数的名称省略(name elision),只写值、省去参数名即可;此外新增了一套模式匹配语法,用于匹配匿名具名元组(anonymous named tuple)。编译器则会在部分场景下对未定义变量发出警告,便于提前揪出拼写错误。更多细节可查阅项目文档。
Coconut v3.1.12024-06-09
Coconut本次更新在语言层面加入了case def语法,用于更直观地定义多分支的模式匹配函数;新增f(name=)简写形式,等价于f(name=name),原先的f(...=name)写法已被弃用;同时提供了内置的CoconutWarning用于运行时警告。
编译器方面,隐式字符串拼接现在会触发警告,--strict模式下直接禁用;单独使用addpattern def而没有先前的match def也会给出提示,官方推荐的多分支写法已改为case def;另外通过--pyright标志提供了初步的pyright类型检查支持。
修复部分解决了一些f-string解析问题、空zip对象的len计算错误,并改进了彩色输出在部分终端下的表现以及Python3.12上对PEP695的支持。
Coconut v3.1.02024-03-02
See Coconut's documentation for more information on all of the features listed below.
Language features:
* #814: Changes to statement lambda scoping rules, including capturing names introduced in the surrounding expression.
* #618: Changes to handling of pattern-matching function defaults including support for e.g. match def f(x, y=x) = (x, y).
* #809: New array concatenation implicit partials (e.g. [. ; a]).
* #823: New (x := .) implicit partial syntax (only available in pipes).
#807: New liftapart built-in combinator.
* #813: New (if) operator function.
* #826 (thanks @JayXon!): Better universalization and fmap support for bytes and bytearray.
* #816: Support for xarray to match existing numpy/pandas support.
#817: New to argument to allequal.
* #821 (thanks @GolfingSuccess!): Expanded implicit function application syntax to support string literal methods.
Compiler features:
* #799: coconut-run and coconut --run now work on packages rather than just files.
* #812: Better formatting of Coconut exceptions.
Bugfixes:
* #810: Fixed an issue compiling certain syntax constructs in the Coconut Jupyter kernel.
* #818, #825 (thanks @kg583, @dokutan!): Fixed parsing of different Unicode line break characters.
* #822 (thanks @JayXon!): Fixed parsing of Unicode backward pipe operators.
* #819, #820 (thanks @kg583!): Fixed some incompatibilities between Python and Coconut syntax.
Coconut v3.0.42023-11-28
This is primarily a bugfix release to resolve #804. See Coconut's documentation for more information on all of the features listed below.
Language changes:
* #784: where statements now use temporary variable names to limit the scope of contained assignments.
#795: New asyncmap function utilizing anyio to work with asyncio or trio.
#793: New mapreduce, collectby.usingthreads, collectby.usingprocesses, mapreduce.usingthreads, and mapreduce.using_processes built-ins.
* #787: Support for .method[index] implicit partials.
* #749, #792: Some built-ins have been renamed for clarity (the old names will still work unless --strict is passed). Specifically:
- recursiveiterator -> recursivegenerator
- parallelmap -> processmap
- concurrentmap -> threadmap
#797: Partial application objects now preserve the original function's name__ attribute.
* #789: Coconut will automatically backport ExceptionGroup using the exceptiongroup module.
Compiler changes:
* #772: Substantial improvements to recompilation speed for most files.
#798: New api.findpackages and api.findandcompile_packages utilities for working with Coconut packages.
* #803: New --fail-fast option to fail upon the first error when compiling multiple files.
#778: The --history-file command-line option has been removed; use COCONUTHISTORY_FILE environment variable if you really need it.
Bugfixes:
* #804: Fixed an incompatibility with new cPyparsing versions.
* #781, #794: Improved formatting for compilation errors/warnings.
* #800: override now works in conjunction with classmethod and staticmethod.
Coconut v3.0.32023-07-29
See Coconut's documentation for more information on all of the features listed below.
New features:
#738: New andthen and andthenawait built-ins for async function composition.
Language changes:
* #763: Lambdas now support fat arrows (x => x) as an alternative to skinny arrows (x -> x) to better distinguish them from type annotations. Skinny arrow lambdas will be deprecated at some later date.
* #756: Coconut now fully supports Python 3.12's enhanced f-string syntax on all targets.
* #773: f-strings with no expressions in them (e.g. f"why does this have an f" will now show a warning by default and an error on --strict.
Compiler changes:
* #761: --line-numbers are now on by default. Pass --no-line-numbers to turn them off.
* #768 (thanks @kxmh42!): Automatic compilation now uses a cache directory rather than compiling files in-place; additionally, automatic compilation options can now be set via coconut-run.
* #767: New --target psf support for targeting all versions not considered end-of-life.
* #765 (thanks @rtbs-dev!): New coconut --jupyter install command for easily installing all Jupyter kernels added as an alternative to the existing coconut --jupyter syntax.
* #766: Coconut now internally supports an incremental parsing mode that is used in some situations (e.g. in the Jupyter kernel) to substantially improve recompilation times.
Bugfixes:
* #759 (thanks @Starwort!): multiset methods should now always return multisets when the arguments are all multisets rather than Counters.
* #764 (thanks @koraa!): An issue that caused function definitions to take much longer to compile when compiling from the interpreter has now been fixed.
* #762 (thanks @Starwort!): Semicolon-separated commands should now always work properly on xonsh.
* #775: Coconut should no longer set the MYPYPATH to include the entire directory that Coconut has been installed into when running with --mypy.
* #777: Docstrings should now show up properly in any third-party tools that look at Coconut's stub files.
Coconut v3.0.22023-05-30
这是Coconut3.0.x系列的又一个补丁版本,主要围绕#751和#755两个问题展开。
新增了async with for循环,用更简洁的语法实现异步生成器(async generator)的推荐处理模式。语言层面,typing的导入会尽量重定向到typingextensions,保证各Python版本都能拿到最新的实现;异步生成器及相关工具在3.5上自动经由asyncgenerator库回移;同时删掉了几种容易混淆的Unicode运算符替代写法。
编译器方面,coconut.convenience更名为coconut.api,旧名保留为别名,现有代码不受影响。
修复了Coconut在xonsh中特定场景下报错的问题,也解决了此前3.0.x版本文档无法正常渲染的故障。
Coconut v3.0.12023-05-25
Coconut这版补丁主要修复#746,同时带来几项新特性与改进。语法层面新增f(...=longname)写法,等价于f(longname=longname)的简写;f ..> g现在在inspect.signature检查时会保留f的签名。fmap遇到未知类型改为抛出TypeError,不再回退到默认实现,如需旧行为可传fmap$(fallbackto_init=True),另外它对multiset的支持也已修好。修复方面,Jupyter内核的语法错误如今能正常显示而非直接报错,xonsh扩展下分号分隔的命令不再出错,--stand-alone模式编译单个目录时可正确利用--jobs,安装时的弃用警告也已消除。
Coconut v3.0.02023-05-02
Coconut v3! See Coconut's documentation for more information on all of the features listed below.
Note that v3 is a major version release that comes with some breaking changes, though Coconut will do its best to warn you if your code does anything that changed from v2 to v3.
Breaking changes:
#714: set patterns now work like dict patterns where they allow extra keys, such that {1, 2} will match {1, 2, 3}. To get back the strict behavior, use the {1, 2, 3, ()} pattern. Coconut will warn you if your code contains set patterns without an explicit strictness marker.
#707: the precedence of implicit function application has been changed to be compatible with implicit coefficients, such that f x2 is now equivalent to f(x2) rather than f(x)2. Coconut will warn you if your code contains expressions with new precedence.
#733: .$[] will now only default to using an existing getitem if the object is registered as a collections.abc.Sequence. itergetitem will still always be used. Lets you do things like {"k": "v"}$[0].
* #730: obj. syntax as a shorthand for getattr$(obj) deprecated.
* #732: --jobs now defaults to sys rather than 0.
New features:
#707: New implicit coefficient syntax! Polynomials are just a x2 + b x + c, with support for single variable names and numeric constants as coefficients.
* #731: New copyclosure def functions that copy their closures on function creation, allowing them to e.g. hold on to loop variables.
* #709: (+) syntax in a typing context now yields a typing.Protocol that requires supporting that operator.
* #709: New &: operator for combining multiple typing.Protocol's into a single protocol.
* #718 (thanks @yggdr!): You can now use addpattern def even if there's no existing function of that name, allowing you to use addpattern def for every pattern rather than having to use match def for the first one.
* #727: New x |> await syntax for using await in pipes.
* #734: Substantially improved pandas support.
* #714: New frozenset and multiset patterns.
Bugfixes:
* #725 (thanks @yggdr!): Fixed (in) operator function argument ordering.
* #721 (thanks @yggdr!): is not and not in operator functions now supported.
* #724 (thanks @Starwort!): Coconut no longer slows down xonsh loading and fixed xontrib unload coconut.
* #726 (thanks @caedmon-kitty!): Fixed certain xonsh commands when using Coconut's xonsh plugin.
* #723: dict now always functions as on the latest Python 3 on any Python version.
* #728 (thanks @yggdr!): Fixed super compatibility across Python versions and some cases where super() wouldn't work.
* #717 (thanks @kksgandhi!): Fixed coconut --jupyter qtconsole.
Coconut v2.2.02022-12-31
See Coconut's documentation for more information on all of the features listed below.
Major changes:
- #694: New multiset built-in based on collections.Counter, including new multiset literal syntax (m{1, 1, 2, 3, 3, 4}).
- #691: New Expected built-in based on Haskell's Either, plus new safe_call built-in that calls a function while collecting any errors into an Expected. Additionally, the of built-in has been renamed to call (of is still available as a deprecated alias when compiled without --strict).
- #701: New windowsof built-in for iterating over sliding windows of the given iterable.
- #688: New cartesian_product built-in as an enhanced version of itertools.product including numpy support.
- #690: New cycle built-in as an enhanced version of itertools.cycle.
- #704, #703, #702, #693, #692: Lots of improvements to existing built-ins:
* map now supports a strict=True keyword-only argument that works as in zip.
* flatten now supports a levels argument for how many levels to flatten.
* groupsof now supports a fillvalue argument to pad the last group.
* addpattern now accepts any number of pattern-matching functions.
* memoize now accepts a function to memoize as the first argument.
- #710: New None-aware function composition pipes (e.g. f ..?> g).
Minor changes:
- #686: Type parameter bounds can (and should) now use <: syntax instead of : or <= (e.g. def f[T <: int[])(xs: T) -> T = ...).
- #711: Backwards None-aware pipes now supported (e.g. <?|).
- #708: Pattern-matching against data types with default arguments now allows those defaults to be elided in the match.
- #697: :: now produces a reiterable object when called on reiterable objects.
- #706: Multiple Coconut projects should now be able to seamlessly use each other's MatchErrors when compiled in --package mode.
- #695: Set literal syntax now supports star unpacking.
- #699: Support for bool magic method fixed on Python 2.
- #687: Jupyter kernel and other automatic compilations now uses --no-wrap.
- #685, #684: Improved detection of code issues on and off --strict.
- #700: Some confusing unicode alternatives were removed.
- #698: Typing for fmap has been improved.
- #689: Improved numpy support for some built-ins.
- #705: Many Coconut built-ins have now been made weakrefable.