New submission from Tim Mitchell <tim.mitch...@seequent.com>:

The new functools.singledispatchmethod (issue32380) class interacts poorly with 
subclasses.
There is no way for a sub-class to override or extend the dispatch registry.
E.g.

class BaseVistor:
   @singledispatchmethod
   def visit(self, obj):
      raise ValueError('Explict vistor implementation missing)

class AVisitor(BaseVisitor):
   # problem: here we can only register against base class method
   @BaseVistor.visit.reister(int)
   def visit_int(self, obj):
       print ('integer')

The AVistor class has now changed the dispatch registry for BaseVistor class 
which is bad.

To fix this the dispatch registry needs to be copied for each subclass and an 
alternate register mechanism provided for subclasses to register against a 
subclass method.
See attached file and pypi methoddispatch for details :)

----------
components: Library (Lib)
files: methoddispatch36.py
messages: 339008
nosy: Tim Mitchell2, inada.naoki
priority: normal
severity: normal
status: open
title: functools.singledispatchmethod interacts poorly with subclasses
type: behavior
versions: Python 3.8
Added file: https://bugs.python.org/file48235/methoddispatch36.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36457>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to