# HG changeset patch # User Gerald Klix (speedy) # Date 1538312811 -7200 # Sun Sep 30 15:06:51 2018 +0200 # Node ID e1c71ef8a7d6eefc6d1a4753d3c16a6a8b5f2936 # Parent 104f27a4ec0ae7a122f6bbffa20ab09432b051c3 SUM: More documentation. diff --git a/docs/api.rst b/docs/api.rst --- a/docs/api.rst +++ b/docs/api.rst @@ -226,6 +226,10 @@ This decorator is the variadic variant of :func:`.method`. +Advanced Usage +-------------- +The follows section describe advanced uses cases of :mod:`gf`. + Calling Other Multi-Methods of The Same Generic ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :mod:`gf` implements two ways to calls other methods of @@ -447,8 +451,6 @@ >>> im(str) 'Class' - - As mentioned above, it is also possible to dispatch on instances with the default dispatch type :attr:`Dispatch.ON_OBJECT`: @@ -461,8 +463,70 @@ 'Integer' -Advanced Usage --------------- +Merging Generics +~~~~~~~~~~~~~~~~ + +Two generic functions can merged into one generic function +with the help of the :func:`merge` function like this [#]_: + + >>> g_one = generic() + >>> @method() + ... def g_one(a: 1): + ... return 'one' + >>> g_two = generic() + >>> @method() + ... def g_two(a: 2): + ... return 'two' + +Both can be called with mixed results: + + >>> g_one(1) + 'one' + >>> g_two(2) + 'two' + >>> g_one(2) + Traceback (most recent call last): + ... + NotImplementedError: Generic None has no implementation for type(s): builtins.int + >>> g_two(1) + Traceback (most recent call last): + ... + NotImplementedError: Generic None has no implementation for type(s): builtins.int + +Both generics can be merged into one generic by using the generic function +:func:`merge`: + + >>> from gf import merge + >>> g_both = merge(g_one, g_two) + >>> g_both(1) + 'one' + >>> g_both(2) + 'two' + + +Testing For Being a Generic Function +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If the need arises one can test any object for being a generic function +with the help of the :func:`isgeneric` generic function + +>>> from gf import isgeneric +>>> isgeneric(0) +False +>>> isgeneric(object) +False +>>> isgeneric(g_one) +True +>>> isgeneric(g_both) +True +>>> isgeneric(isgeneric) +True +>>> isgeneric(generic) +True + + +The Generic :class:`Object`-Library +----------------------------------- The :mod:`gf`-package also provides an abstract base class called :class:`gf.AbstractObject` and class called :class:`gf.Object`. @@ -483,3 +547,7 @@ .. automodule:: gf.go :members: :special-members: + + +.. [#] This functionality was necessary for one of my own projects, + but my be rather useless for ordinary Python projects. diff --git a/docs/conf.py b/docs/conf.py --- a/docs/conf.py +++ b/docs/conf.py @@ -58,7 +58,7 @@ # The short X.Y version. version = '0.2' # The full version, including alpha/beta/rc tags. -release = '0.2.1' +release = '0.2.2' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/overview.rst b/docs/overview.rst --- a/docs/overview.rst +++ b/docs/overview.rst @@ -106,6 +106,15 @@ http://docs.python.org/2/reference/datamodel.html#special-method-names +Installation +------------ + +As usual :mod:`gf3` can be installed with `pip`, like this: + +.. code-block:: shell + + pip install gf3 + Documentation ------------- @@ -123,11 +132,21 @@ A short sketch of the changes done in each release. +Release 0.2.2 +~~~~~~~~~~~~~ + +The following was change in Release 0.2.2: + + * Write more documentation. + Especially documented the :func:`merge` and the :func:`isgeneric` + functions. + * Consistency between the long text and on PyPi and the documentation. + Release 0.2.1 ~~~~~~~~~~~~~ Needed to bump the version information, because the homepage -in the package-information was wrong [#]_. +in the package-information was wrong [#]_ and a new upload was needed. Release 0.2.0 ~~~~~~~~~~~~~ @@ -143,6 +162,7 @@ This is the generic function equivalent of a class-method. * Added some means to dispatch on single objects. This is the equivalent adding methods to class-instances [#]_. + * The package name for PyPi is now ``gf3``. .. _parameter annotations: https://docs.python.org/3/reference/compound_stmts.html#grammar-token-parameter diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ sys.path.insert(0, "tests") setup(name="gf3", - version='0.2.1', + version='0.2.2', description="A package with lisp-like generic functions for python 3.", long_description = long_description, keywords="generic-function multi-method",