From 9e7204e940b862bd3b3eb54b22bc306e21d0a70c Mon Sep 17 00:00:00 2001 From: apalala Date: Tue, 14 Nov 2023 10:21:23 -0400 Subject: [PATCH] =?UTF-8?q?make=20=E5=8C=85=20an=20alias=20for=20`latst`?= =?UTF-8?q?=20`=5F=5F`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 +++++++++++ late/__init__.py | 4 +--- ruff.toml | 2 +- test/simple_test.py | 12 +++++++++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a5e5505..be039d8 100644 --- a/README.md +++ b/README.md @@ -223,3 +223,14 @@ $ pip install Late **Late** is licensed as reads in [LICENSE](https://github.com/neogeny/late/blob/master/LICENSE). + + +## And now,... this! + +You can use ``包``, the Kanji for _"wrap"_, instead of ``__`` to late-bind +an argument. + +```python +@latebinding +def f(x: list[Any] = 包([])) -> list[Any]: +``` diff --git a/late/__init__.py b/late/__init__.py index 64ea1b1..7e2fb33 100644 --- a/late/__init__.py +++ b/late/__init__.py @@ -24,9 +24,7 @@ def late(o: _T | Iterator[_V] | Callable[[], _R]) -> _T | _V | _R: __ = late - - -__ = late +包 = late def _lateargs(func: Callable, **kwargs) -> dict[str, Any]: diff --git a/ruff.toml b/ruff.toml index da03fa2..79ed03f 100644 --- a/ruff.toml +++ b/ruff.toml @@ -19,7 +19,7 @@ ignore = [ 'TRY003', 'TRY300', 'PGH003', 'PLW1514', 'PLR6301', - 'PLC0415', + 'PLC0415', 'PLC2401', 'PLC2403', 'PLR0913', 'PLR2004', 'PLR0904', 'PLR0915', 'PLW0603', 'PLW2901', 'PLW3201', 'RET505', diff --git a/test/simple_test.py b/test/simple_test.py index 634e33b..3844236 100644 --- a/test/simple_test.py +++ b/test/simple_test.py @@ -1,7 +1,7 @@ import inspect from typing import Any -from late import __, _LateBound, latebinding +from late import __, _LateBound, latebinding, 包 def test_with_list(): @@ -25,3 +25,13 @@ def f(x: frozenset[Any] = __(frozenset()), y: set = __(set())): assert type(param.default) is frozenset param = inspect.signature(f).parameters['y'] assert type(param.default) is _LateBound + + +def test_kanji(): + @latebinding + def f(x: list[Any] = 包([])) -> list[Any]: + x.append(1) + return x + + assert f() == [1] + assert f() == [1]