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
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
11
11
### Changed
12
12
* Improved on the nREPL server exception messages by matching that of the REPL user friendly format (#968)
13
+
* Types created via `deftype` and `reify` may declare supertypes as abstract (taking precedence over true `abc.ABC` types) and specify their member list using `^:abstract-members` metadata (#942)
13
14
14
15
### Removed
15
16
* Removed `python-dateutil` and `readerwriterlock` as dependencies, switching to standard library components instead (#976)
Copy file name to clipboardExpand all lines: docs/concepts.rst
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1243,6 +1243,7 @@ Types may also optionally implement 0 or more Python `"dunder" methods <https://
1243
1243
The best approximation is :external:py:class:`abc.ABC`, although this type is merely advisory and many libraries and applications eschew its use.
1244
1244
1245
1245
For the cases where a host type is not defined as an ``abc.ABC`` instance, users can override the compiler check by setting the ``^:abstract`` meta key on the interface type symbol passed to the ``deftype`` form.
1246
+
This is called "artificial abstractness" and it takes precedence over true abstract base classes via ``abc.ABC``.
1246
1247
For example, take :external:py:class:`argparse.Action` which is required to be implemented for customizing :external:py:mod:`argparse` actions, but which is not defined as an ``abc.ABC``:
1247
1248
1248
1249
.. code-block::
@@ -1255,6 +1256,23 @@ Types may also optionally implement 0 or more Python `"dunder" methods <https://
1255
1256
;; ...
1256
1257
))
1257
1258
1259
+
Python libraries may also include implicit (documentation-only) abstract methods on their ``abc.ABC`` types.
1260
+
Thus, it is sometimes necessary to annotate a base class using ``^{:abstract-members #{...}}`` to designate any methods which should be considered abstract in the base class since the compiler cannot check them for you.
1261
+
Take for example :external:py:class:`io.IOBase` which does not declare ``read`` or ``write`` (or in fact *any* members at all in its ``__abstractmethods__`` set!) as part of the interface, but the documentation specifies that they should be considered part of the interface.
1262
+
Below, we tell the compiler it is artificially abstract and that ``read`` is a member.
1263
+
1264
+
.. code-block::
1265
+
1266
+
(import io)
1267
+
1268
+
(reify
1269
+
^:abstract
1270
+
^{:abstract-members #{:read}}
1271
+
io/TextIOBase
1272
+
(read [n]
1273
+
;; ...
1274
+
))
1275
+
1258
1276
.. warning::
1259
1277
1260
1278
The Basilisp compiler is not currently able to verify that the signature of implemented methods matches the interface or superclass method signature.
0 commit comments