You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*Changed in 0.14.2.*[A bug in `frozendict` pickling](https://github.com/Technologicat/unpythonic/issues/55) has been fixed. Now also the empty `frozendict` pickles and unpickles correctly.
433
+
**Changed in 0.14.2**. *[A bug in `frozendict` pickling](https://github.com/Technologicat/unpythonic/issues/55) has been fixed. Now also the empty `frozendict` pickles and unpickles correctly.*
431
434
432
435
433
436
### `cons` and friends: pythonic lispy linked lists
@@ -512,13 +515,13 @@ We provide a ``JackOfAllTradesIterator`` as a compromise that understands both t
512
515
513
516
### ``box``: a mutable single-item container
514
517
515
-
*Changed in v0.14.2.**The `box` container APIis now `b.set(newvalue)` to rebind, returning the new value as a convenience. The equivalent syntactic sugar is`b << newvalue`. The item inside the box can be extracted with`b.get()`. The equivalent syntactic sugar is`unbox(b)`.*
518
+
**Changed in v0.14.2**.*The `box` container APIis now `b.set(newvalue)` to rebind, returning the new value as a convenience. The equivalent syntactic sugar is`b << newvalue`. The item inside the box can be extracted with`b.get()`. The equivalent syntactic sugar is`unbox(b)`.*
516
519
517
-
*Added in v0.14.2.**`ThreadLocalBox`: like `box`, but with thread-local contents. It also holds a default object, which is used when a particular thread has not placed anyobject into the box.*
520
+
**Added in v0.14.2**.*`ThreadLocalBox`: like `box`, but with thread-local contents. It also holds a default object, which is used when a particular thread has not placed anyobject into the box.*
518
521
519
-
*Added in v0.14.2.**`Some`: like `box`, but immutable. Useful to mark an optional attribute. `Some(None)` indicates a value that isset to `None`, in contrast to a bare `None`, which can then be used indicate the absence of a value.*
522
+
**Added in v0.14.2**.*`Some`: like `box`, but immutable. Useful to mark an optional attribute. `Some(None)` indicates a value that isset to `None`, in contrast to a bare `None`, which can then be used indicate the absence of a value.*
520
523
521
-
*Changed in v0.14.2.**Accessing the `.x` attribute of a `box` directly is now deprecated. It will continue to work with`box` at least until 0.15, but it does notand cannot work with`ThreadLocalBox`, which must handle things differently due to implementation reasons. Use the API mentioned above; it supports both kinds of boxes with the same syntax.*
524
+
**Changed in v0.14.2**.*Accessing the `.x` attribute of a `box` directly is now deprecated. It will continue to work with`box` at least until 0.15, but it does notand cannot work with`ThreadLocalBox`, which must handle things differently due to implementation reasons. Use the API mentioned above; it supports both kinds of boxes with the same syntax.*
522
525
523
526
No doubt anyone programming in an imperative language has run into the situation caricatured by this highly artificial example:
524
527
@@ -667,7 +670,7 @@ We also provide an **immutable** box, `Some`. This can be useful for optional da
667
670
668
671
### ``Shim``: redirect attribute accesses
669
672
670
-
*Added in v0.14.2.*
673
+
**Added in v0.14.2**.
671
674
672
675
A `Shim`is an attribute access proxy. The shim holds a `box` (or a `ThreadLocalBox`), and redirects attribute accesses on the shim to whatever object happens to currently be in the box. The point is that the objectin the box can be replaced with a different one later (by sending another object into the box), and the code accessing the proxied object through the shim doesn't need to be aware that anything has changed.
673
676
@@ -906,7 +909,7 @@ We also provide ``pipec``, which curries the functions before applying them. Use
906
909
907
910
Optional **shell-like syntax**, with purely functional updates.
908
911
909
-
*Changed in v0.14.2*. Both `getvalue`and`runpipe` are now known by the single unified name `exitpipe`. This is just a rename, with no functionality changes. The old names are now deprecated, and will be removed in0.15.0.
912
+
**Changed in v0.14.2**. *Both `getvalue`and`runpipe` are now known by the single unified name `exitpipe`. This is just a rename, with no functionality changes. The old names are now deprecated, and will be removed in0.15.0.*
While all other pure-Python features of `unpythonic` live in the main `unpythonic` package, the network-related features are placed in the subpackage `unpythonic.net`. This subpackage also contains the [REPL server and client](repl.md) for hot-patching live processes.
1542
1545
@@ -1869,6 +1872,8 @@ There is the read-only cousin ``roview``, which behaves the same except it has n
1869
1872
1870
1873
### ``mogrify``: update a mutable container in-place
1871
1874
1875
+
**Changed in v0.14.3.***`mogrify` now skips `nil`, actually making it useful for processing `ll` linked lists.*
1876
+
1872
1877
Recurse on given container, apply a function to each atom. If the container is mutable, then update in-place; ifnot, then construct a new copy like ``map`` does.
1873
1878
1874
1879
If the container is a mapping, the function is applied to the values; keys are left untouched.
@@ -2012,7 +2017,7 @@ Inspired by Haskell.
2012
2017
2013
2018
### ``sym``, ``gensym``, ``Singleton``: symbols and singletons
2014
2019
2015
-
*Added in v0.14.2.*
2020
+
**Added in v0.14.2**.
2016
2021
2017
2022
We provide **lispy symbols**, an **uninterned symbol generator**, and a **pythonic singleton abstraction**. These are all pickle-aware, and instantiation is thread-safe.
2018
2023
@@ -2830,6 +2835,12 @@ The implementation is based on the List monad, and a bastardized variant of do-n
2830
2835
2831
2836
**Added in v0.14.2**.
2832
2837
2838
+
**Changed in v0.14.3**. *Conditions can now inherit from`BaseException`, not only from`Exception.``with handlers` catches also derived types, e.g. a handler for`Exception` now catches a signaled `ValueError`.*
2839
+
2840
+
*When an unhandled `error`or`cerror` occurs, the original unhandled error is now available in the `__cause__` attribute of the `ControlError` exception that is raised in this situation.*
2841
+
2842
+
*Signaling a class, asin`signal(SomeExceptionClass)`, now implicitly creates an instance with no arguments, just like the `raise` statement does. On Python 3.7+, `signal` now automatically equips the condition instance with a traceback, just like the `raise` statement does for an exception.*
2843
+
2833
2844
One of the killer features of Common Lisp are *conditions*, which are essentially **resumable exceptions**.
2834
2845
2835
2846
Following Peter Seibel ([Practical Common Lisp, chapter 19](http://www.gigamonkeys.com/book/beyond-exception-handling-conditions-and-restarts.html)), we define *errors*as the consequences of [Murphy's Law](https://en.wikipedia.org/wiki/Murphy%27s_law), i.e. situations where circumstances cause interaction between the program and the outside world to fail. An error is no bug, but failing to handle an error certainly is.
@@ -2966,6 +2977,8 @@ The core idea can be expressed in fewer than 100 lines of Python; ours is (as of
2966
2977
2967
2978
**Changed in v0.14.3**. *The multiple-dispatch decorator `@generic` no longer takes a master definition. Methods are registered directly with`@generic`; the first method definition implicitly creates the generic function.*
2968
2979
2980
+
**Changed in v0.14.3***The `@generic`and`@typed` decorators can now decorate also instance methods, class methods and static methods (beside regular functions, as previously in0.14.2).*
We also provide some friendly utilities: ``typed`` creates a single-method generic with the same syntax (i.e. provides a compact notation for writing dynamic type checking code), and``isoftype`` (which powers the first two) is the big sister of ``isinstance``, with support for many (but unfortunately notall) features of the ``typing`` standard library module.
@@ -3038,6 +3051,22 @@ See [the unit tests](../unpythonic/test/test_dispatch.py) for more. For which fe
3038
3051
3039
3052
Inspired by the [multi-methods of CLOS](http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html) (the Common Lisp Object System), and the [generic functions of Julia](https://docs.julialang.org/en/v1/manual/methods/).
3040
3053
3054
+
##### ``@generic`` and OOP
3055
+
3056
+
As of version 0.14.3, `@generic`and`@typed` can decorate instance methods, class methods and static methods (beside regular functions asin0.14.2).
3057
+
3058
+
When using both `@generic`or`@typed`andOOP:
3059
+
3060
+
-**`self`and`cls` parameters**.
3061
+
- The `self`and`cls` parameters do not participate in dispatching, and need no type annotation.
3062
+
- Beside appearing as the first positional-or-keyword parameter, the self-like parameter **must be named** one of `self`, `this`, `cls`, or`klass` to be detected by the ignore mechanism. This limitation is due to implementation reasons; while a class body is being evaluated, the context needed to distinguish a method (OOP sense) from a regular function isnot yet present.
3063
+
3064
+
-**OOP inheritance**.
3065
+
- When `@generic`is installed on an OOP method (instance method, or`@classmethod`), then at call time, classes are tried in [MRO](https://en.wikipedia.org/wiki/C3_linearization) order. All generic-function methods of the OOP method defined in the class currently being looked up are tested for matches first, before moving on to the nextclassin the MRO. (This has subtle consequences, related to in which classin the hierarchy the various generic-function methods for a particular OOP method are defined.)
3066
+
- To work withOOP inheritance, `@generic` must be the outermost decorator (except`@classmethod`or`@staticmethod`, which are essentially compiler annotations).
3067
+
- However, when installed on a `@staticmethod`, the `@generic` decorator does not support MRO lookup, because that would make no sense. See discussions on interaction between `@staticmethod`and`super`in Python: [[1]](https://bugs.python.org/issue31118) [[2]](https://stackoverflow.com/questions/26788214/super-and-staticmethod-interaction/26807879).
3068
+
3069
+
3041
3070
##### Notes
3042
3071
3043
3072
*Terminology*: in both CLOSandin Julia, *function*is the generic entity, while*method* refers to its specialization to a particular combination of argument types. Note that *no object instance orclassis needed*. Contrast with the classical OOP sense of *method*, i.e. a function that is associated with an object instance orclass, with single dispatch based on the class (orin exotic cases, such as monkey-patched instances, on the instance).
Inspired by *Function application with$*in [LYAH: Higher Order Functions](http://learnyouahaskell.com/higher-order-functions).
3343
3372
3344
3373
3345
-
### ``raisef``: ``raise`` as a function
3374
+
### ``raisef``, ``tryf``: ``raise`` and ``try`` as functions
3375
+
3376
+
**Changed in v0.14.3**. *Now we have also `tryf`.*
3346
3377
3347
-
*Changed in v0.14.2.*The parameters of `raisef` now more closely match what would be passed to `raise`. See examples below. Old-style parameters are now deprecated, and support for them will be dropped in v0.15.0.
3378
+
**Changed in v0.14.2**. *The parameters of `raisef` now more closely match what would be passed to `raise`. See examples below. Old-style parameters are now deprecated, and support for them will be dropped in v0.15.0.*
3348
3379
3349
3380
Raise an exception from an expression position:
3350
3381
@@ -3359,6 +3390,50 @@ exc = TypeError("oof")
3359
3390
g=lambdax: raisef(RuntimeError("I'm in ur lambda raising exceptions"), cause=exc)
(ValueError, lambdaerr: "got a ValueError: '{}'".format(err.args[0]))) =="got a ValueError: 'all ok'"]
3401
+
```
3402
+
3403
+
The exception handler is a function. It may optionally accept one argument, the exception instance.
3404
+
3405
+
Functions can also be specified for the `else`and`finally` behavior; see the docstring of `unpythonic.misc.tryf`for details.
3406
+
3407
+
3408
+
### ``equip_with_traceback``
3409
+
3410
+
**Added in v0.14.3**.
3411
+
3412
+
Equip a manually created exception instance with a traceback. This is useful mainly in special cases, where `raise` cannot be used for some reason. (The `signal` function in the conditions-and-restarts system uses this.)
3413
+
3414
+
```python
3415
+
e= SomeException(...)
3416
+
e= equip_with_traceback(e)
3417
+
```
3418
+
3419
+
The traceback is automatically extracted from the call stack of the calling thread.
3420
+
3421
+
Optionally, you can cull a number of the topmost frames by passing the optional argument `stacklevel=...`. Typically, for direct use of this function `stacklevel` should be the default `1` (so it excludes `equip_with_traceback` itself, but shows all stack levels from your code), andfor use in a utility function that itself is called from your code, it should be `2` (so it excludes the utility function, too).
3422
+
3423
+
3424
+
### ``callsite_filename``
3425
+
3426
+
**Added in v0.14.3**.
3427
+
3428
+
Return the filename from which this function is being called. Useful as a building block for debug utilities and similar.
3429
+
3430
+
3431
+
### ``safeissubclass``
3432
+
3433
+
**Added in v0.14.3**.
3434
+
3435
+
Convenience function. Like `issubclass(cls)`, but if`cls`isnot a class, swallow the `TypeError`andreturn`False`.
### ``arities``, ``kwargs``, ``resolve_bindings``: Function signature inspection utilities
3451
3526
3452
-
*Added in v0.14.2*: `resolve_bindings`. Get the parameter bindings a given callable would establish if it was called with the given args and kwargs. This is mainly of interest for implementing memoizers, since this allows them to see (e.g.) `f(1)`and`f(a=1)`as the same thing for`def f(a): pass`.
3527
+
**Added in v0.14.2**: `resolve_bindings`. *Get the parameter bindings a given callable would establish if it was called with the given args and kwargs. This is mainly of interest for implementing memoizers, since this allows them to see (e.g.) `f(1)`and`f(a=1)`as the same thing for`def f(a): pass`.*
3453
3528
3454
3529
Convenience functions providing an easy-to-use APIfor inspecting a function's signature. The heavy lifting is done by ``inspect``.
3455
3530
@@ -3620,7 +3695,7 @@ For more reading, see [David Goldberg (1991): What every computer scientist shou
3620
3695
3621
3696
### ``async_raise``: inject an exception to another thread
3622
3697
3623
-
*Added in v0.14.2.*
3698
+
**Added in v0.14.2**.
3624
3699
3625
3700
*Currently CPython only, because as of this writing (March 2020) PyPy3 does not expose the required functionality to the Python level, nor there seem to be any plans to do so.*
0 commit comments