Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-singledispatch for openSUSE:Factory checked in at 2022-09-15 23:00:14 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-singledispatch (Old) and /work/SRC/openSUSE:Factory/.python-singledispatch.new.2083 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-singledispatch" Thu Sep 15 23:00:14 2022 rev:3 rq:1003957 version:3.7.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-singledispatch/python-singledispatch.changes 2022-01-13 00:22:12.083922938 +0100 +++ /work/SRC/openSUSE:Factory/.python-singledispatch.new.2083/python-singledispatch.changes 2022-09-15 23:01:30.049606782 +0200 @@ -1,0 +2,7 @@ +Thu Sep 15 18:27:47 UTC 2022 - Dirk M??ller <dmuel...@suse.com> + +- update to 3.7.0: + * Add ``singledispatchmethod`` from Python 3.8. + * bpo-23572: Fix behavior when metaclass implements bool. + +------------------------------------------------------------------- Old: ---- singledispatch-3.6.1.tar.gz New: ---- singledispatch-3.7.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-singledispatch.spec ++++++ --- /var/tmp/diff_new_pack.XwkR7o/_old 2022-09-15 23:01:30.477607992 +0200 +++ /var/tmp/diff_new_pack.XwkR7o/_new 2022-09-15 23:01:30.481608002 +0200 @@ -18,7 +18,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-singledispatch -Version: 3.6.1 +Version: 3.7.0 Release: 0 Summary: Provides functools.singledispatch for Python 2.x License: MIT AND Python-2.0 ++++++ singledispatch-3.6.1.tar.gz -> singledispatch-3.7.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/.coveragerc new/singledispatch-3.7.0/.coveragerc --- old/singledispatch-3.6.1/.coveragerc 2021-02-25 20:32:26.000000000 +0100 +++ new/singledispatch-3.7.0/.coveragerc 2021-08-14 04:37:54.000000000 +0200 @@ -1,5 +1,7 @@ [run] -omit = .tox/* +omit = + # leading `*/` for pytest-dev/pytest-cov#456 + */.tox/* [report] show_missing = True diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/.github/dependabot.yml new/singledispatch-3.7.0/.github/dependabot.yml --- old/singledispatch-3.6.1/.github/dependabot.yml 1970-01-01 01:00:00.000000000 +0100 +++ new/singledispatch-3.7.0/.github/dependabot.yml 2021-08-14 04:37:54.000000000 +0200 @@ -0,0 +1,8 @@ +version: 2 +updates: + - package-ecosystem: "pip" + directory: "/" + schedule: + interval: "daily" + allow: + - dependency-type: "all" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/.github/workflows/automerge.yml new/singledispatch-3.7.0/.github/workflows/automerge.yml --- old/singledispatch-3.6.1/.github/workflows/automerge.yml 2021-02-25 20:32:26.000000000 +0100 +++ new/singledispatch-3.7.0/.github/workflows/automerge.yml 1970-01-01 01:00:00.000000000 +0100 @@ -1,27 +0,0 @@ -name: automerge -on: - pull_request: - types: - - labeled - - unlabeled - - synchronize - - opened - - edited - - ready_for_review - - reopened - - unlocked - pull_request_review: - types: - - submitted - check_suite: - types: - - completed - status: {} -jobs: - automerge: - runs-on: ubuntu-latest - steps: - - name: automerge - uses: "pascalgn/automerge-action@v0.12.0" - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/.github/workflows/main.yml new/singledispatch-3.7.0/.github/workflows/main.yml --- old/singledispatch-3.6.1/.github/workflows/main.yml 2021-02-25 20:32:26.000000000 +0100 +++ new/singledispatch-3.7.0/.github/workflows/main.yml 2021-08-14 04:37:54.000000000 +0200 @@ -6,7 +6,12 @@ test: strategy: matrix: - python: [2.7, 3.5, 3.6, 3.8, 3.9] + python: + - 2.7 + - 3.5 + - 3.6 + - 3.9 + - 3.10.0-alpha - 3.10.99 platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/.pre-commit-config.yaml new/singledispatch-3.7.0/.pre-commit-config.yaml --- old/singledispatch-3.6.1/.pre-commit-config.yaml 2021-02-25 20:32:26.000000000 +0100 +++ new/singledispatch-3.7.0/.pre-commit-config.yaml 2021-08-14 04:37:54.000000000 +0200 @@ -3,8 +3,3 @@ rev: 20.8b1 hooks: - id: black - -- repo: https://github.com/asottile/blacken-docs - rev: v1.9.1 - hooks: - - id: blacken-docs diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/CHANGES.rst new/singledispatch-3.7.0/CHANGES.rst --- old/singledispatch-3.6.1/CHANGES.rst 2021-02-25 20:32:26.000000000 +0100 +++ new/singledispatch-3.7.0/CHANGES.rst 2021-08-14 04:37:54.000000000 +0200 @@ -1,3 +1,15 @@ +v3.7.0 +====== + +#4: Add ``singledispatchmethod`` from Python 3.8. + +Incorporate minor changes from Python 3.8. + +v3.6.2 +====== + +#3 and bpo-23572: Fix behavior when metaclass implements bool. + v3.6.1 ====== diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/PKG-INFO new/singledispatch-3.7.0/PKG-INFO --- old/singledispatch-3.6.1/PKG-INFO 2021-02-25 20:32:43.947456400 +0100 +++ new/singledispatch-3.7.0/PKG-INFO 2021-08-14 04:38:13.857883500 +0200 @@ -1,172 +1,11 @@ Metadata-Version: 2.1 Name: singledispatch -Version: 3.6.1 +Version: 3.7.0 Summary: Backport functools.singledispatch from Python 3.4 to Python 2.6-3.3. Home-page: https://github.com/jaraco/singledispatch Author: Jason R. Coombs Author-email: jar...@jaraco.com License: UNKNOWN -Description: .. image:: https://img.shields.io/pypi/v/singledispatch.svg - :target: `PyPI link`_ - - .. image:: https://img.shields.io/pypi/pyversions/singledispatch.svg - :target: `PyPI link`_ - - .. _PyPI link: https://pypi.org/project/singledispatch - - .. image:: https://github.com/jaraco/singledispatch/workflows/tests/badge.svg - :target: https://github.com/jaraco/singledispatch/actions?query=workflow%3A%22tests%22 - :alt: tests - - .. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black - :alt: Code style: Black - - .. .. image:: https://readthedocs.org/projects/skeleton/badge/?version=latest - .. :target: https://skeleton.readthedocs.io/en/latest/?badge=latest - - `PEP 443 <http://www.python.org/dev/peps/pep-0443/>`_ proposed to expose - a mechanism in the ``functools`` standard library module in Python 3.4 - that provides a simple form of generic programming known as - single-dispatch generic functions. - - This library is a backport of this functionality to Python 2.6 - 3.3. - - To define a generic function, decorate it with the ``@singledispatch`` - decorator. Note that the dispatch happens on the type of the first - argument, create your function accordingly:: - - >>> from singledispatch import singledispatch - >>> @singledispatch - ... def fun(arg, verbose=False): - ... if verbose: - ... print("Let me just say,", end=" ") - ... print(arg) - - To add overloaded implementations to the function, use the - ``register()`` attribute of the generic function. It is a decorator, - taking a type parameter and decorating a function implementing the - operation for that type:: - - >>> @fun.register(int) - ... def _(arg, verbose=False): - ... if verbose: - ... print("Strength in numbers, eh?", end=" ") - ... print(arg) - ... - >>> @fun.register(list) - ... def _(arg, verbose=False): - ... if verbose: - ... print("Enumerate this:") - ... for i, elem in enumerate(arg): - ... print(i, elem) - - To enable registering lambdas and pre-existing functions, the - ``register()`` attribute can be used in a functional form:: - - >>> def nothing(arg, verbose=False): - ... print("Nothing.") - ... - >>> fun.register(type(None), nothing) - - The ``register()`` attribute returns the undecorated function which - enables decorator stacking, pickling, as well as creating unit tests for - each variant independently:: - - >>> @fun.register(float) - ... @fun.register(Decimal) - ... def fun_num(arg, verbose=False): - ... if verbose: - ... print("Half of your number:", end=" ") - ... print(arg / 2) - ... - >>> fun_num is fun - False - - When called, the generic function dispatches on the type of the first - argument:: - - >>> fun("Hello, world.") - Hello, world. - >>> fun("test.", verbose=True) - Let me just say, test. - >>> fun(42, verbose=True) - Strength in numbers, eh? 42 - >>> fun(['spam', 'spam', 'eggs', 'spam'], verbose=True) - Enumerate this: - 0 spam - 1 spam - 2 eggs - 3 spam - >>> fun(None) - Nothing. - >>> fun(1.23) - 0.615 - - Where there is no registered implementation for a specific type, its - method resolution order is used to find a more generic implementation. - The original function decorated with ``@singledispatch`` is registered - for the base ``object`` type, which means it is used if no better - implementation is found. - - To check which implementation will the generic function choose for - a given type, use the ``dispatch()`` attribute:: - - >>> fun.dispatch(float) - <function fun_num at 0x1035a2840> - >>> fun.dispatch(dict) # note: default implementation - <function fun at 0x103fe0000> - - To access all registered implementations, use the read-only ``registry`` - attribute:: - - >>> fun.registry.keys() - dict_keys([<class 'NoneType'>, <class 'int'>, <class 'object'>, - <class 'decimal.Decimal'>, <class 'list'>, - <class 'float'>]) - >>> fun.registry[float] - <function fun_num at 0x1035a2840> - >>> fun.registry[object] - <function fun at 0x103fe0000> - - The vanilla documentation is available at - http://docs.python.org/3/library/functools.html#functools.singledispatch. - - - Maintenance - ----------- - - This backport is maintained on Github by Jason R. Coombs, one of the - members of the core CPython team: - - * `repository <https://github.com/jaraco/singledispatch>`_ - - * `issue tracker <https://github.com/jaraco/singledispatch/issues>`_ - - - Conversion Process - ------------------ - - This section is technical and should bother you only if you are - wondering how this backport is produced. If the implementation details - of this backport are not important for you, feel free to ignore the - following content. - - ``singledispatch`` is converted using `six - <http://pypi.python.org/pypi/six>`_ so that a single codebase can be - used for all compatible Python versions. Because a fully automatic - conversion was not doable, I took the following branching approach: - - * the ``upstream`` branch holds unchanged files synchronized from the - upstream CPython repository. The synchronization is currently done by - manually copying the required code parts and stating from which - CPython changeset they come from. The tests should pass on Python 3.4 - on this branch. - - * the ``default`` branch holds the manually translated version and this - is where all tests are run for all supported Python versions using - Tox. - Keywords: single,dispatch,generic,functions,singledispatch,genericfunctions,decorator,backport Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable @@ -185,6 +24,57 @@ Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 +Classifier: Programming Language :: Python :: 3.10 Requires-Python: >=2.6 Provides-Extra: testing Provides-Extra: docs +License-File: LICENSE + +.. image:: https://img.shields.io/pypi/v/singledispatch.svg + :target: `PyPI link`_ + +.. image:: https://img.shields.io/pypi/pyversions/singledispatch.svg + :target: `PyPI link`_ + +.. _PyPI link: https://pypi.org/project/singledispatch + +.. image:: https://github.com/jaraco/singledispatch/workflows/tests/badge.svg + :target: https://github.com/jaraco/singledispatch/actions?query=workflow%3A%22tests%22 + :alt: tests + +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/psf/black + :alt: Code style: Black + +.. .. image:: https://readthedocs.org/projects/skeleton/badge/?version=latest +.. :target: https://skeleton.readthedocs.io/en/latest/?badge=latest + +.. image:: https://img.shields.io/badge/skeleton-2021-informational + :target: https://blog.jaraco.com/skeleton + +`PEP 443 <http://www.python.org/dev/peps/pep-0443/>`_ proposed to expose +a mechanism in the ``functools`` standard library module in Python 3.4 +that provides a simple form of generic programming known as +single-dispatch generic functions. + +This library is a backport of this functionality and its evolution. + +Refer to the `upstream documentation +<http://docs.python.org/3/library/functools.html#functools.singledispatch>`_ +for API guidance. To use the backport, simply use +``from singledispatch import singledispatch, singledispatchmethod`` in place of +``from functools import singledispatch, singledispatchmethod``. + + + +Maintenance +----------- + +This backport is maintained on Github by Jason R. Coombs, one of the +members of the core CPython team: + +* `repository <https://github.com/jaraco/singledispatch>`_ + +* `issue tracker <https://github.com/jaraco/singledispatch/issues>`_ + + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/README.rst new/singledispatch-3.7.0/README.rst --- old/singledispatch-3.6.1/README.rst 2021-02-25 20:32:26.000000000 +0100 +++ new/singledispatch-3.7.0/README.rst 2021-08-14 04:37:54.000000000 +0200 @@ -17,112 +17,22 @@ .. .. image:: https://readthedocs.org/projects/skeleton/badge/?version=latest .. :target: https://skeleton.readthedocs.io/en/latest/?badge=latest +.. image:: https://img.shields.io/badge/skeleton-2021-informational + :target: https://blog.jaraco.com/skeleton + `PEP 443 <http://www.python.org/dev/peps/pep-0443/>`_ proposed to expose a mechanism in the ``functools`` standard library module in Python 3.4 that provides a simple form of generic programming known as single-dispatch generic functions. -This library is a backport of this functionality to Python 2.6 - 3.3. +This library is a backport of this functionality and its evolution. -To define a generic function, decorate it with the ``@singledispatch`` -decorator. Note that the dispatch happens on the type of the first -argument, create your function accordingly:: - - >>> from singledispatch import singledispatch - >>> @singledispatch - ... def fun(arg, verbose=False): - ... if verbose: - ... print("Let me just say,", end=" ") - ... print(arg) - -To add overloaded implementations to the function, use the -``register()`` attribute of the generic function. It is a decorator, -taking a type parameter and decorating a function implementing the -operation for that type:: - - >>> @fun.register(int) - ... def _(arg, verbose=False): - ... if verbose: - ... print("Strength in numbers, eh?", end=" ") - ... print(arg) - ... - >>> @fun.register(list) - ... def _(arg, verbose=False): - ... if verbose: - ... print("Enumerate this:") - ... for i, elem in enumerate(arg): - ... print(i, elem) - -To enable registering lambdas and pre-existing functions, the -``register()`` attribute can be used in a functional form:: - - >>> def nothing(arg, verbose=False): - ... print("Nothing.") - ... - >>> fun.register(type(None), nothing) - -The ``register()`` attribute returns the undecorated function which -enables decorator stacking, pickling, as well as creating unit tests for -each variant independently:: - - >>> @fun.register(float) - ... @fun.register(Decimal) - ... def fun_num(arg, verbose=False): - ... if verbose: - ... print("Half of your number:", end=" ") - ... print(arg / 2) - ... - >>> fun_num is fun - False - -When called, the generic function dispatches on the type of the first -argument:: - - >>> fun("Hello, world.") - Hello, world. - >>> fun("test.", verbose=True) - Let me just say, test. - >>> fun(42, verbose=True) - Strength in numbers, eh? 42 - >>> fun(['spam', 'spam', 'eggs', 'spam'], verbose=True) - Enumerate this: - 0 spam - 1 spam - 2 eggs - 3 spam - >>> fun(None) - Nothing. - >>> fun(1.23) - 0.615 - -Where there is no registered implementation for a specific type, its -method resolution order is used to find a more generic implementation. -The original function decorated with ``@singledispatch`` is registered -for the base ``object`` type, which means it is used if no better -implementation is found. - -To check which implementation will the generic function choose for -a given type, use the ``dispatch()`` attribute:: - - >>> fun.dispatch(float) - <function fun_num at 0x1035a2840> - >>> fun.dispatch(dict) # note: default implementation - <function fun at 0x103fe0000> - -To access all registered implementations, use the read-only ``registry`` -attribute:: - - >>> fun.registry.keys() - dict_keys([<class 'NoneType'>, <class 'int'>, <class 'object'>, - <class 'decimal.Decimal'>, <class 'list'>, - <class 'float'>]) - >>> fun.registry[float] - <function fun_num at 0x1035a2840> - >>> fun.registry[object] - <function fun at 0x103fe0000> +Refer to the `upstream documentation +<http://docs.python.org/3/library/functools.html#functools.singledispatch>`_ +for API guidance. To use the backport, simply use +``from singledispatch import singledispatch, singledispatchmethod`` in place of +``from functools import singledispatch, singledispatchmethod``. -The vanilla documentation is available at -http://docs.python.org/3/library/functools.html#functools.singledispatch. Maintenance @@ -134,27 +44,3 @@ * `repository <https://github.com/jaraco/singledispatch>`_ * `issue tracker <https://github.com/jaraco/singledispatch/issues>`_ - - -Conversion Process ------------------- - -This section is technical and should bother you only if you are -wondering how this backport is produced. If the implementation details -of this backport are not important for you, feel free to ignore the -following content. - -``singledispatch`` is converted using `six -<http://pypi.python.org/pypi/six>`_ so that a single codebase can be -used for all compatible Python versions. Because a fully automatic -conversion was not doable, I took the following branching approach: - -* the ``upstream`` branch holds unchanged files synchronized from the - upstream CPython repository. The synchronization is currently done by - manually copying the required code parts and stating from which - CPython changeset they come from. The tests should pass on Python 3.4 - on this branch. - -* the ``default`` branch holds the manually translated version and this - is where all tests are run for all supported Python versions using - Tox. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/docs/conf.py new/singledispatch-3.7.0/docs/conf.py --- old/singledispatch-3.6.1/docs/conf.py 2021-02-25 20:32:26.000000000 +0100 +++ new/singledispatch-3.7.0/docs/conf.py 2021-08-14 04:37:54.000000000 +0200 @@ -24,3 +24,6 @@ ], ) } + +# Be strict about any broken references: +nitpicky = True diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/pytest.ini new/singledispatch-3.7.0/pytest.ini --- old/singledispatch-3.6.1/pytest.ini 2021-02-25 20:32:26.000000000 +0100 +++ new/singledispatch-3.7.0/pytest.ini 2021-08-14 04:37:54.000000000 +0200 @@ -5,3 +5,7 @@ # workaround for warning pytest-dev/pytest#6178 junit_family=xunit2 filterwarnings= + # Suppress deprecation warning in flake8 + ignore:SelectableGroups dict interface is deprecated::flake8 + # Suppress deprecation warning in pypa/packaging#433 + ignore:The distutils package is deprecated::packaging.tags diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/setup.cfg new/singledispatch-3.7.0/setup.cfg --- old/singledispatch-3.6.1/setup.cfg 2021-02-25 20:32:43.947456400 +0100 +++ new/singledispatch-3.7.0/setup.cfg 2021-08-14 04:38:13.857883500 +0200 @@ -27,6 +27,7 @@ Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 keywords = single dispatch @@ -44,7 +45,6 @@ install_requires = six ordereddict; python_version < "2.7" -setup_requires = setuptools_scm[toml] >= 3.4.1 [options.packages.find] exclude = @@ -56,12 +56,13 @@ [options.extras_require] testing = pytest >= 4.6 - pytest-checkdocs >= 1.2.3 + pytest-checkdocs >= 2.4; python_version > "3.6" pytest-flake8 - pytest-black >= 0.3.7; python_implementation != "PyPy" + pytest-black >= 0.3.7; \ + python_implementation != "PyPy" pytest-cov - unittest2; python_version < "2.7" + unittest2; python_version < "3" docs = sphinx jaraco.packaging >= 8.2 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/singledispatch/__init__.py new/singledispatch-3.7.0/singledispatch/__init__.py --- old/singledispatch-3.6.1/singledispatch/__init__.py 2021-02-25 20:32:26.000000000 +0100 +++ new/singledispatch-3.7.0/singledispatch/__init__.py 2021-08-14 04:37:54.000000000 +0200 @@ -6,12 +6,11 @@ from __future__ import print_function from __future__ import unicode_literals -__all__ = ['singledispatch'] +__all__ = ['singledispatch', 'singledispatchmethod'] -from functools import update_wrapper from weakref import WeakKeyDictionary -from .helpers import MappingProxyType, get_cache_token, get_type_hints +from .helpers import MappingProxyType, get_cache_token, get_type_hints, update_wrapper ################################################################################ ### singledispatch() - single-dispatch generic function decorator @@ -36,7 +35,7 @@ break # reject the current head, it appears later else: break - if not candidate: + if candidate is None: raise RuntimeError("Inconsistent hierarchy") result.append(candidate) # remove the chosen candidate @@ -164,6 +163,23 @@ match = t return registry.get(match) +def _validate_annotation(annotation): + """Determine if an annotation is valid for registration. + + An annotation is considered valid for use in registration if it is an + instance of ``type`` and not a generic type from ``typing``. + """ + try: + # In Python earlier than 3.7, the classes in typing are considered + # instances of type, but they invalid for registering single dispatch + # functions so check against GenericMeta instead. + from typing import GenericMeta + valid = not isinstance(annotation, GenericMeta) + except ImportError: + # In Python 3.7+, classes in typing are not instances of type. + valid = isinstance(annotation, type) + return valid + def singledispatch(func): """Single-dispatch generic function decorator. @@ -172,7 +188,6 @@ function acts as the default implementation, and additional implementations can be registered using the register() attribute of the generic function. - """ registry = {} dispatch_cache = WeakKeyDictionary() @@ -220,7 +235,7 @@ func = cls argname, cls = next(iter(get_type_hints(func).items())) - if not isinstance(cls, type): + if not _validate_annotation(cls): raise TypeError( "Invalid annotation for {argname!r}. " "{cls!r} is not a class.".format(**locals()) @@ -232,8 +247,13 @@ return func def wrapper(*args, **kw): + if not args: + raise TypeError('{0} requires at least ' + '1 positional argument'.format(funcname)) + return dispatch(args[0].__class__)(*args, **kw) + funcname = getattr(func, '__name__', 'singledispatch function') registry[object] = func wrapper.register = register wrapper.dispatch = dispatch @@ -242,3 +262,39 @@ update_wrapper(wrapper, func) return wrapper + +# Descriptor version +class singledispatchmethod(object): + """Single-dispatch generic method descriptor. + + Supports wrapping existing descriptors and handles non-descriptor + callables as instance methods. + """ + + def __init__(self, func): + if not callable(func) and not hasattr(func, "__get__"): + raise TypeError("{!r} is not callable or a descriptor".format(func)) + + self.dispatcher = singledispatch(func) + self.func = func + + def register(self, cls, method=None): + """generic_method.register(cls, func) -> func + + Registers a new implementation for the given *cls* on a *generic_method*. + """ + return self.dispatcher.register(cls, func=method) + + def __get__(self, obj, cls=None): + def _method(*args, **kwargs): + method = self.dispatcher.dispatch(args[0].__class__) + return method.__get__(obj, cls)(*args, **kwargs) + + _method.__isabstractmethod__ = self.__isabstractmethod__ + _method.register = self.register + update_wrapper(_method, self.func) + return _method + + @property + def __isabstractmethod__(self): + return getattr(self.func, '__isabstractmethod__', False) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/singledispatch/helpers.py new/singledispatch-3.7.0/singledispatch/helpers.py --- old/singledispatch-3.6.1/singledispatch/helpers.py 2021-02-25 20:32:26.000000000 +0100 +++ new/singledispatch-3.7.0/singledispatch/helpers.py 2021-08-14 04:37:54.000000000 +0200 @@ -181,3 +181,37 @@ # only import typing if annotation parsing is necessary from typing import get_type_hints return get_type_hints(func) or getattr(func, '__annotations__', {}) + + +WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__qualname__', '__doc__', + '__annotations__') +WRAPPER_UPDATES = ('__dict__',) +def update_wrapper(wrapper, + wrapped, + assigned = WRAPPER_ASSIGNMENTS, + updated = WRAPPER_UPDATES): + """Update a wrapper function to look like the wrapped function + + wrapper is the function to be updated + wrapped is the original function + assigned is a tuple naming the attributes assigned directly + from the wrapped function to the wrapper function (defaults to + functools.WRAPPER_ASSIGNMENTS) + updated is a tuple naming the attributes of the wrapper that + are updated with the corresponding attribute from the wrapped + function (defaults to functools.WRAPPER_UPDATES) + """ + for attr in assigned: + try: + value = getattr(wrapped, attr) + except AttributeError: + pass + else: + setattr(wrapper, attr, value) + for attr in updated: + getattr(wrapper, attr).update(getattr(wrapped, attr, {})) + # Issue #17482: set __wrapped__ last so we don't inadvertently copy it + # from the wrapped function when updating __dict__ + wrapper.__wrapped__ = wrapped + # Return the wrapper so this can be used as a decorator via partial() + return wrapper diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/singledispatch.egg-info/PKG-INFO new/singledispatch-3.7.0/singledispatch.egg-info/PKG-INFO --- old/singledispatch-3.6.1/singledispatch.egg-info/PKG-INFO 2021-02-25 20:32:43.000000000 +0100 +++ new/singledispatch-3.7.0/singledispatch.egg-info/PKG-INFO 2021-08-14 04:38:13.000000000 +0200 @@ -1,172 +1,11 @@ Metadata-Version: 2.1 Name: singledispatch -Version: 3.6.1 +Version: 3.7.0 Summary: Backport functools.singledispatch from Python 3.4 to Python 2.6-3.3. Home-page: https://github.com/jaraco/singledispatch Author: Jason R. Coombs Author-email: jar...@jaraco.com License: UNKNOWN -Description: .. image:: https://img.shields.io/pypi/v/singledispatch.svg - :target: `PyPI link`_ - - .. image:: https://img.shields.io/pypi/pyversions/singledispatch.svg - :target: `PyPI link`_ - - .. _PyPI link: https://pypi.org/project/singledispatch - - .. image:: https://github.com/jaraco/singledispatch/workflows/tests/badge.svg - :target: https://github.com/jaraco/singledispatch/actions?query=workflow%3A%22tests%22 - :alt: tests - - .. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black - :alt: Code style: Black - - .. .. image:: https://readthedocs.org/projects/skeleton/badge/?version=latest - .. :target: https://skeleton.readthedocs.io/en/latest/?badge=latest - - `PEP 443 <http://www.python.org/dev/peps/pep-0443/>`_ proposed to expose - a mechanism in the ``functools`` standard library module in Python 3.4 - that provides a simple form of generic programming known as - single-dispatch generic functions. - - This library is a backport of this functionality to Python 2.6 - 3.3. - - To define a generic function, decorate it with the ``@singledispatch`` - decorator. Note that the dispatch happens on the type of the first - argument, create your function accordingly:: - - >>> from singledispatch import singledispatch - >>> @singledispatch - ... def fun(arg, verbose=False): - ... if verbose: - ... print("Let me just say,", end=" ") - ... print(arg) - - To add overloaded implementations to the function, use the - ``register()`` attribute of the generic function. It is a decorator, - taking a type parameter and decorating a function implementing the - operation for that type:: - - >>> @fun.register(int) - ... def _(arg, verbose=False): - ... if verbose: - ... print("Strength in numbers, eh?", end=" ") - ... print(arg) - ... - >>> @fun.register(list) - ... def _(arg, verbose=False): - ... if verbose: - ... print("Enumerate this:") - ... for i, elem in enumerate(arg): - ... print(i, elem) - - To enable registering lambdas and pre-existing functions, the - ``register()`` attribute can be used in a functional form:: - - >>> def nothing(arg, verbose=False): - ... print("Nothing.") - ... - >>> fun.register(type(None), nothing) - - The ``register()`` attribute returns the undecorated function which - enables decorator stacking, pickling, as well as creating unit tests for - each variant independently:: - - >>> @fun.register(float) - ... @fun.register(Decimal) - ... def fun_num(arg, verbose=False): - ... if verbose: - ... print("Half of your number:", end=" ") - ... print(arg / 2) - ... - >>> fun_num is fun - False - - When called, the generic function dispatches on the type of the first - argument:: - - >>> fun("Hello, world.") - Hello, world. - >>> fun("test.", verbose=True) - Let me just say, test. - >>> fun(42, verbose=True) - Strength in numbers, eh? 42 - >>> fun(['spam', 'spam', 'eggs', 'spam'], verbose=True) - Enumerate this: - 0 spam - 1 spam - 2 eggs - 3 spam - >>> fun(None) - Nothing. - >>> fun(1.23) - 0.615 - - Where there is no registered implementation for a specific type, its - method resolution order is used to find a more generic implementation. - The original function decorated with ``@singledispatch`` is registered - for the base ``object`` type, which means it is used if no better - implementation is found. - - To check which implementation will the generic function choose for - a given type, use the ``dispatch()`` attribute:: - - >>> fun.dispatch(float) - <function fun_num at 0x1035a2840> - >>> fun.dispatch(dict) # note: default implementation - <function fun at 0x103fe0000> - - To access all registered implementations, use the read-only ``registry`` - attribute:: - - >>> fun.registry.keys() - dict_keys([<class 'NoneType'>, <class 'int'>, <class 'object'>, - <class 'decimal.Decimal'>, <class 'list'>, - <class 'float'>]) - >>> fun.registry[float] - <function fun_num at 0x1035a2840> - >>> fun.registry[object] - <function fun at 0x103fe0000> - - The vanilla documentation is available at - http://docs.python.org/3/library/functools.html#functools.singledispatch. - - - Maintenance - ----------- - - This backport is maintained on Github by Jason R. Coombs, one of the - members of the core CPython team: - - * `repository <https://github.com/jaraco/singledispatch>`_ - - * `issue tracker <https://github.com/jaraco/singledispatch/issues>`_ - - - Conversion Process - ------------------ - - This section is technical and should bother you only if you are - wondering how this backport is produced. If the implementation details - of this backport are not important for you, feel free to ignore the - following content. - - ``singledispatch`` is converted using `six - <http://pypi.python.org/pypi/six>`_ so that a single codebase can be - used for all compatible Python versions. Because a fully automatic - conversion was not doable, I took the following branching approach: - - * the ``upstream`` branch holds unchanged files synchronized from the - upstream CPython repository. The synchronization is currently done by - manually copying the required code parts and stating from which - CPython changeset they come from. The tests should pass on Python 3.4 - on this branch. - - * the ``default`` branch holds the manually translated version and this - is where all tests are run for all supported Python versions using - Tox. - Keywords: single,dispatch,generic,functions,singledispatch,genericfunctions,decorator,backport Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable @@ -185,6 +24,57 @@ Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 +Classifier: Programming Language :: Python :: 3.10 Requires-Python: >=2.6 Provides-Extra: testing Provides-Extra: docs +License-File: LICENSE + +.. image:: https://img.shields.io/pypi/v/singledispatch.svg + :target: `PyPI link`_ + +.. image:: https://img.shields.io/pypi/pyversions/singledispatch.svg + :target: `PyPI link`_ + +.. _PyPI link: https://pypi.org/project/singledispatch + +.. image:: https://github.com/jaraco/singledispatch/workflows/tests/badge.svg + :target: https://github.com/jaraco/singledispatch/actions?query=workflow%3A%22tests%22 + :alt: tests + +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/psf/black + :alt: Code style: Black + +.. .. image:: https://readthedocs.org/projects/skeleton/badge/?version=latest +.. :target: https://skeleton.readthedocs.io/en/latest/?badge=latest + +.. image:: https://img.shields.io/badge/skeleton-2021-informational + :target: https://blog.jaraco.com/skeleton + +`PEP 443 <http://www.python.org/dev/peps/pep-0443/>`_ proposed to expose +a mechanism in the ``functools`` standard library module in Python 3.4 +that provides a simple form of generic programming known as +single-dispatch generic functions. + +This library is a backport of this functionality and its evolution. + +Refer to the `upstream documentation +<http://docs.python.org/3/library/functools.html#functools.singledispatch>`_ +for API guidance. To use the backport, simply use +``from singledispatch import singledispatch, singledispatchmethod`` in place of +``from functools import singledispatch, singledispatchmethod``. + + + +Maintenance +----------- + +This backport is maintained on Github by Jason R. Coombs, one of the +members of the core CPython team: + +* `repository <https://github.com/jaraco/singledispatch>`_ + +* `issue tracker <https://github.com/jaraco/singledispatch/issues>`_ + + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/singledispatch.egg-info/SOURCES.txt new/singledispatch-3.7.0/singledispatch.egg-info/SOURCES.txt --- old/singledispatch-3.6.1/singledispatch.egg-info/SOURCES.txt 2021-02-25 20:32:43.000000000 +0100 +++ new/singledispatch-3.7.0/singledispatch.egg-info/SOURCES.txt 2021-08-14 04:38:13.000000000 +0200 @@ -11,10 +11,9 @@ pytest.ini setup.cfg setup.py -skeleton.md test_singledispatch.py tox.ini -.github/workflows/automerge.yml +.github/dependabot.yml .github/workflows/main.yml docs/conf.py docs/history.rst diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/singledispatch.egg-info/requires.txt new/singledispatch-3.7.0/singledispatch.egg-info/requires.txt --- old/singledispatch-3.6.1/singledispatch.egg-info/requires.txt 2021-02-25 20:32:43.000000000 +0100 +++ new/singledispatch-3.7.0/singledispatch.egg-info/requires.txt 2021-08-14 04:38:13.000000000 +0200 @@ -10,12 +10,14 @@ [testing] pytest>=4.6 -pytest-checkdocs>=1.2.3 pytest-flake8 pytest-cov [testing:platform_python_implementation != "PyPy"] pytest-black>=0.3.7 -[testing:python_version < "2.7"] +[testing:python_version < "3"] unittest2 + +[testing:python_version > "3.6"] +pytest-checkdocs>=2.4 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/skeleton.md new/singledispatch-3.7.0/skeleton.md --- old/singledispatch-3.6.1/skeleton.md 2021-02-25 20:32:26.000000000 +0100 +++ new/singledispatch-3.7.0/skeleton.md 1970-01-01 01:00:00.000000000 +0100 @@ -1,166 +0,0 @@ -# Overview - -This project is merged with [skeleton](https://github.com/jaraco/skeleton). What is skeleton? It's the scaffolding of a Python project jaraco [introduced in his blog](https://blog.jaraco.com/a-project-skeleton-for-python-projects/). It seeks to provide a means to re-use techniques and inherit advances when managing projects for distribution. - -## An SCM-Managed Approach - -While maintaining dozens of projects in PyPI, jaraco derives best practices for project distribution and publishes them in the [skeleton repo](https://github.com/jaraco/skeleton), a Git repo capturing the evolution and culmination of these best practices. - -It's intended to be used by a new or existing project to adopt these practices and honed and proven techniques. Adopters are encouraged to use the project directly and maintain a small deviation from the technique, make their own fork for more substantial changes unique to their environment or preferences, or simply adopt the skeleton once and abandon it thereafter. - -The primary advantage to using an SCM for maintaining these techniques is that those tools help facilitate the merge between the template and its adopting projects. - -Another advantage to using an SCM-managed approach is that tools like GitHub recognize that a change in the skeleton is the _same change_ across all projects that merge with that skeleton. Without the ancestry, with a traditional copy/paste approach, a [commit like this](https://github.com/jaraco/skeleton/commit/12eed1326e1bc26ce256e7b3f8cd8d3a5beab2d5) would produce notifications in the upstream project issue for each and every application, but because it's centralized, GitHub provides just the one notification when the change is added to the skeleton. - -# Usage - -## new projects - -To use skeleton for a new project, simply pull the skeleton into a new project: - -``` -$ git init my-new-project -$ cd my-new-project -$ git pull gh://jaraco/skeleton -``` - -Now customize the project to suit your individual project needs. - -## existing projects - -If you have an existing project, you can still incorporate the skeleton by merging it into the codebase. - -``` -$ git merge skeleton --allow-unrelated-histories -``` - -The `--allow-unrelated-histories` is necessary because the history from the skeleton was previously unrelated to the existing codebase. Resolve any merge conflicts and commit to the master, and now the project is based on the shared skeleton. - -## Updating - -Whenever a change is needed or desired for the general technique for packaging, it can be made in the skeleton project and then merged into each of the derived projects as needed, recommended before each release. As a result, features and best practices for packaging are centrally maintained and readily trickle into a whole suite of packages. This technique lowers the amount of tedious work necessary to create or maintain a project, and coupled with other techniques like continuous integration and deployment, lowers the cost of creating and maintaining refined Python projects to just a few, familiar Git operations. - -For example, here's a session of the [path project](https://pypi.org/project/path) pulling non-conflicting changes from the skeleton: - -<img src="https://raw.githubusercontent.com/jaraco/skeleton/gh-pages/docs/refresh.svg"> - -Thereafter, the target project can make whatever customizations it deems relevant to the scaffolding. The project may even at some point decide that the divergence is too great to merit renewed merging with the original skeleton. This approach applies maximal guidance while creating minimal constraints. - -## Periodic Collapse - -In late 2020, this project [introduced](https://github.com/jaraco/skeleton/issues/27) the idea of a periodic but infrequent (O(years)) collapse of commits to limit the number of commits a new consumer will need to accept to adopt the skeleton. - -The full history of commits is collapsed into a single commit and that commit becomes the new mainline head. - -When one of these collapse operations happens, any project that previously pulled from the skeleton will no longer have a related history with that new main branch. For those projects, the skeleton provides a "handoff" branch that reconciles the two branches. Any project that has previously merged with the skeleton but now gets an error "fatal: refusing to merge unrelated histories" should instead use the handoff branch once to incorporate the new main branch. - -``` -$ git pull https://github.com/jaraco/skeleton 2020-handoff -``` - -This handoff needs to be pulled just once and thereafter the project can pull from the main head. - -The archive and handoff branches from prior collapses are indicate here: - -| refresh | archive | handoff | -|---------|-----------------|--------------| -| 2020-12 | archive/2020-12 | 2020-handoff | - -# Features - -The features/techniques employed by the skeleton include: - -- PEP 517/518-based build relying on Setuptools as the build tool -- Setuptools declarative configuration using setup.cfg -- tox for running tests -- A README.rst as reStructuredText with some popular badges, but with Read the Docs and AppVeyor badges commented out -- A CHANGES.rst file intended for publishing release notes about the project -- Use of [Black](https://black.readthedocs.io/en/stable/) for code formatting (disabled on unsupported Python 3.5 and earlier) -- Integrated type checking through [mypy](https://github.com/python/mypy/). - -## Packaging Conventions - -A pyproject.toml is included to enable PEP 517 and PEP 518 compatibility and declares the requirements necessary to build the project on Setuptools (a minimum version compatible with setup.cfg declarative config). - -The setup.cfg file implements the following features: - -- Assumes universal wheel for release -- Advertises the project's LICENSE file (MIT by default) -- Reads the README.rst file into the long description -- Some common Trove classifiers -- Includes all packages discovered in the repo -- Data files in the package are also included (not just Python files) -- Declares the required Python versions -- Declares install requirements (empty by default) -- Declares setup requirements for legacy environments -- Supplies two 'extras': - - testing: requirements for running tests - - docs: requirements for building docs - - these extras split the declaration into "upstream" (requirements as declared by the skeleton) and "local" (those specific to the local project); these markers help avoid merge conflicts -- Placeholder for defining entry points - -Additionally, the setup.py file declares `use_scm_version` which relies on [setuptools_scm](https://pypi.org/project/setuptools_scm) to do two things: - -- derive the project version from SCM tags -- ensure that all files committed to the repo are automatically included in releases - -## Running Tests - -The skeleton assumes the developer has [tox](https://pypi.org/project/tox) installed. The developer is expected to run `tox` to run tests on the current Python version using [pytest](https://pypi.org/project/pytest). - -Other environments (invoked with `tox -e {name}`) supplied include: - - - a `docs` environment to build the documentation - - a `release` environment to publish the package to PyPI - -A pytest.ini is included to define common options around running tests. In particular: - -- rely on default test discovery in the current directory -- avoid recursing into common directories not containing tests -- run doctests on modules and invoke Flake8 tests -- in doctests, allow Unicode literals and regular literals to match, allowing for doctests to run on Python 2 and 3. Also enable ELLIPSES, a default that would be undone by supplying the prior option. -- filters out known warnings caused by libraries/functionality included by the skeleton - -Relies on a .flake8 file to correct some default behaviors: - -- disable mutually incompatible rules W503 and W504 -- support for Black format - -## Continuous Integration - -The project is pre-configured to run Continuous Integration tests. - -### Github Actions - -[Github Actions](https://docs.github.com/en/free-pro-team@latest/actions) are the preferred provider as they provide free, fast, multi-platform services with straightforward configuration. Configured in `.github/workflows`. - -Features include: -- test against multiple Python versions -- run on late (and updated) platform versions -- automated releases of tagged commits -- [automatic merging of PRs](https://github.com/marketplace/actions/merge-pull-requests) (requires [protecting branches with required status checks](https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/enabling-required-status-checks), [not possible through API](https://github.community/t/set-all-status-checks-to-be-required-as-branch-protection-using-the-github-api/119493)) - - -### Continuous Deployments - -In addition to running tests, an additional publish stage is configured to automatically release tagged commits to PyPI using [API tokens](https://pypi.org/help/#apitoken). The release process expects an authorized token to be configured with each Github project (or org) `PYPI_TOKEN` [secret](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets). Example: - -``` -pip-run -q jaraco.develop -- -m jaraco.develop.add-github-secrets -``` - -## Building Documentation - -Documentation is automatically built by [Read the Docs](https://readthedocs.org) when the project is registered with it, by way of the .readthedocs.yml file. To test the docs build manually, a tox env may be invoked as `tox -e docs`. Both techniques rely on the dependencies declared in `setup.cfg/options.extras_require.docs`. - -In addition to building the Sphinx docs scaffolded in `docs/`, the docs build a `history.html` file that first injects release dates and hyperlinks into the CHANGES.rst before incorporating it as history in the docs. - -## Cutting releases - -By default, tagged commits are released through the continuous integration deploy stage. - -Releases may also be cut manually by invoking the tox environment `release` with the PyPI token set as the TWINE_PASSWORD: - -``` -TWINE_PASSWORD={token} tox -e release -``` diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/test_singledispatch.py new/singledispatch-3.7.0/test_singledispatch.py --- old/singledispatch-3.6.1/test_singledispatch.py 2021-02-25 20:32:26.000000000 +0100 +++ new/singledispatch-3.7.0/test_singledispatch.py 2021-08-14 04:37:54.000000000 +0200 @@ -6,12 +6,15 @@ from __future__ import print_function from __future__ import unicode_literals +import abc import sys import collections import decimal from itertools import permutations import singledispatch as functools from singledispatch.helpers import Support +import typing +import six try: from collections import ChainMap except ImportError: @@ -40,6 +43,9 @@ del _prefix +str = type("") + + class TestSingleDispatch(unittest.TestCase): def test_simple_overloads(self): @functools.singledispatch @@ -293,6 +299,31 @@ many_abcs = [c.Mapping, c.Sized, c.Callable, c.Container, c.Iterable] self.assertEqual(mro(X, abcs=many_abcs), expected) + def test_false_meta(self): + # see issue23572 + class MetaA(type): + def __len__(self): + return 0 + if sys.version_info < (3,): + class A(object): + __metaclass__ = MetaA + else: + """ + class A(metaclass=MetaA): + pass + """ + A = MetaA('A', (), {}) + class AA(A): + pass + @functools.singledispatch + def fun(a): + return 'base A' + @fun.register(A) + def _(a): + return 'fun A' + aa = AA() + self.assertEqual(fun(aa), 'fun A') + def test_mro_conflicts(self): c = coll_abc @functools.singledispatch @@ -562,6 +593,182 @@ return self.arg == other self.assertEqual(i("str"), "str") + def test_method_register(self): + class A(object): + @functools.singledispatchmethod + def t(self, arg): + self.arg = "base" + @t.register(int) + def _(self, arg): + self.arg = "int" + @t.register(str) + def _(self, arg): + self.arg = "str" + a = A() + + a.t(0) + self.assertEqual(a.arg, "int") + aa = A() + self.assertFalse(hasattr(aa, 'arg')) + a.t('') + self.assertEqual(a.arg, "str") + aa = A() + self.assertFalse(hasattr(aa, 'arg')) + a.t(0.0) + self.assertEqual(a.arg, "base") + aa = A() + self.assertFalse(hasattr(aa, 'arg')) + + def test_staticmethod_register(self): + class A(object): + @functools.singledispatchmethod + @staticmethod + def t(arg): + return arg + @t.register(int) + @staticmethod + def _(arg): + return isinstance(arg, int) + @t.register(str) + @staticmethod + def _(arg): + return isinstance(arg, str) + a = A() + + self.assertTrue(A.t(0)) + self.assertTrue(A.t('')) + self.assertEqual(A.t(0.0), 0.0) + + def test_classmethod_register(self): + class A(object): + def __init__(self, arg): + self.arg = arg + + @functools.singledispatchmethod + @classmethod + def t(cls, arg): + return cls("base") + @t.register(int) + @classmethod + def _(cls, arg): + return cls("int") + @t.register(str) + @classmethod + def _(cls, arg): + return cls("str") + + self.assertEqual(A.t(0).arg, "int") + self.assertEqual(A.t('').arg, "str") + self.assertEqual(A.t(0.0).arg, "base") + + def test_callable_register(self): + class A(object): + def __init__(self, arg): + self.arg = arg + + @functools.singledispatchmethod + @classmethod + def t(cls, arg): + return cls("base") + + @A.t.register(int) + @classmethod + def _(cls, arg): + return cls("int") + @A.t.register(str) + @classmethod + def _(cls, arg): + return cls("str") + + self.assertEqual(A.t(0).arg, "int") + self.assertEqual(A.t('').arg, "str") + self.assertEqual(A.t(0.0).arg, "base") + + def test_abstractmethod_register(self): + class Abstract(abc.ABCMeta): + + @functools.singledispatchmethod + @abc.abstractmethod + def add(self, x, y): + pass + + self.assertTrue(Abstract.add.__isabstractmethod__) + + def test_type_ann_register(self): + class A(object): + @functools.singledispatchmethod + def t(self, arg): + return "base" + # @t.register + # def _(self, arg: int): + def _(self, arg): + return "int" + _.__annotations__ = dict(arg=int) + t.register(_) + # @t.register + # def _(self, arg: str): + def _(self, arg): + return "str" + _.__annotations__ = dict(arg=str) + t.register(_) + + a = A() + + self.assertEqual(a.t(0), "int") + self.assertEqual(a.t(''), "str") + self.assertEqual(a.t(0.0), "base") + + def test_invalid_registrations(self): + msg_prefix = "Invalid first argument to `register()`: " + msg_suffix = ( + ". Use either `@register(some_class)` or plain `@register` on an " + "annotated function." + ) + @functools.singledispatch + def i(arg): + return "base" + with self.assertRaises(TypeError) as exc: + @i.register(42) + def _(arg): + return "I annotated with a non-type" + self.assertTrue(str(exc.exception).startswith(msg_prefix + "42")) + self.assertTrue(str(exc.exception).endswith(msg_suffix)) + with self.assertRaises(TypeError) as exc: + @i.register + def _(arg): + return "I forgot to annotate" + scope = "TestSingleDispatch.test_invalid_registrations.<locals>." * six.PY3 + self.assertTrue(str(exc.exception).startswith(msg_prefix + + "<function " + scope + "_" + )) + self.assertTrue(str(exc.exception).endswith(msg_suffix)) + + with self.assertRaises(TypeError) as exc: + # @i.register + # def _(arg: typing.Iterable[str]): + def _(arg): + # At runtime, dispatching on generics is impossible. + # When registering implementations with singledispatch, avoid + # types from `typing`. Instead, annotate with regular types + # or ABCs. + return "I annotated with a generic collection" + _.__annotations__ = dict(arg=typing.Iterable[str]) + i.register(_) + self.assertTrue(str(exc.exception).startswith( + "Invalid annotation for 'arg'." + )) + self.assertTrue(str(exc.exception).endswith( + 'typing.Iterable[' + str.__name__ + '] is not a class.' + )) + + def test_invalid_positional_argument(self): + @functools.singledispatch + def f(*args): + pass + msg = 'f requires at least 1 positional argument' + with self.assertRaisesRegex(TypeError, msg): + f() + def _mro_compat(classes): if sys.version_info < (3, 6): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/singledispatch-3.6.1/tox.ini new/singledispatch-3.7.0/tox.ini --- old/singledispatch-3.6.1/tox.ini 2021-02-25 20:32:26.000000000 +0100 +++ new/singledispatch-3.7.0/tox.ini 2021-08-14 04:37:54.000000000 +0200 @@ -19,14 +19,13 @@ testing changedir = docs commands = - python -m sphinx . {toxinidir}/build/html + python -m sphinx -W --keep-going . {toxinidir}/build/html [testenv:release] skip_install = True deps = build - twine[keyring]>=1.13 - path + twine>=3 jaraco.develop>=7.1 passenv = TWINE_PASSWORD @@ -34,7 +33,7 @@ setenv = TWINE_USERNAME = {env:TWINE_USERNAME:__token__} commands = - python -c "import path; path.Path('dist').rmtree_p()" + python -c "import shutil; shutil.rmtree('dist', ignore_errors=True)" python -m build python -m twine upload dist/* python -m jaraco.develop.create-github-release