New submission from Tim Graham:

As requested by Nick [0], this is a usability issue against CPython 3.6 to 
provide a better chained TypeError in this case:

class _TokenType(tuple):
    parent = None

    def __getattr__(self, name):
        new = _TokenType(self + (name,))
        setattr(self, name, new)
        new.parent = self
        return new

Token = _TokenType()

Keyword = Token.Keyword

class KeywordCaseFilter(object):
    ttype = Keyword

Traceback (most recent call last):
  File "", line 14, in <module>
    class KeywordCaseFilter(object):
TypeError: '_TokenType' object is not callable

The exception should report the specific object with the problematic 
__set_name__ attribute (rather than just passing along the underlying 
exception), as well as supporting __set_name__ = None to explicitly disable 
further lookup processing.

Follow up to #27366.


components: Interpreter Core
messages: 277027
nosy: Tim.Graham, ncoghlan
priority: normal
severity: normal
status: open
title: Improve exception reporting for problematic __set_name__ attributes
type: behavior
versions: Python 3.6, Python 3.7

Python tracker <>
Python-bugs-list mailing list

Reply via email to