Remove the Py_TPFLAGS_BASETYPE flag from the gdb.Color type. This
effectively makes gdb.Color final; users can no longer create classes
that inherit from gdb.Color.
Right now I cannot think of any cases where inheritance would be
needed over composition for a simple type like gdb.Color. If I'm
wrong, then it's easy to add Py_TPFLAGS_BASETYPE back in later, this
would be an extension of the API. But it's much harder to remove the
flag later as that might break existing user code (note: there has
been no release of GDB yet that includes the gdb.Color type).
Introducing this restriction makes the next commit easier.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
@end table
+It is not possible to sub-class the @code{Color} class.
+
@node Architectures In Python
@subsubsection Python representation of architectures
@cindex Python architectures
get_attr, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ Py_TPFLAGS_DEFAULT, /*tp_flags*/
"GDB color object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
"\033\\\[31m\033\\\[42mred on green\033\\\[49m red on default\033\\\[39m" \
"escape sequences"
+gdb_test_multiline "Try to sub-class gdb.Color" \
+ "python" "" \
+ "class my_color(gdb.Color):" "" \
+ " def __init__(self):" "" \
+ " super().__init__('red')" "" \
+ "end" \
+ [multi_line \
+ "Python Exception <class 'TypeError'>: type 'gdb\\.Color' is not an acceptable base type" \
+ "Error occurred in Python: type 'gdb\\.Color' is not an acceptable base type"]
+