[PYTHON MATRIX-SIG] __doc__ string problems?

Konrad Hinsen hinsen@physik.rwth-aachen.de
Thu, 21 Dec 1995 16:02:53 +0100


      Sorry to disturb everyone. Is anyone else having a problem using __
   doc__ strings since installing the Matrix module? Before rebuilding, I

My fault! It has to do with the power operator patch. I have already
sent the fix to Guido, but obviously forgotten that other people on
the Matrix SIG might need it. 

You have to add one line in the function get_docstring() in Python/compile.c;
I'll include the full function:

static object *
get_docstring(n)
	node *n;
{
	int i;

	switch (TYPE(n)) {

	case suite:
		if (NCH(n) == 1)
			return get_docstring(CHILD(n, 0));
		else {
			for (i = 0; i < NCH(n); i++) {
				node *ch = CHILD(n, i);
				if (TYPE(ch) == stmt)
					return get_docstring(ch);
			}
		}
		break;

	case file_input:
		for (i = 0; i < NCH(n); i++) {
			node *ch = CHILD(n, i);
			if (TYPE(ch) == stmt)
				return get_docstring(ch);
		}
		break;

	case stmt:
	case simple_stmt:
	case small_stmt:
		return get_docstring(CHILD(n, 0));

	case expr_stmt:
	case testlist:
	case test:
	case and_test:
	case not_test:
	case comparison:
	case expr:
	case xor_expr:
	case and_expr:
	case shift_expr:
	case arith_expr:
	case term:
	case factor:
	case power:
		if (NCH(n) == 1)
			return get_docstring(CHILD(n, 0));
		break;

	case atom:
		if (TYPE(CHILD(n, 0)) == STRING)
			return parsestrplus(n);
		break;

	}
	return NULL;
}

The new line is "case power:". Briefly, I had to introduce a new node
type to give the power operator a higher priority than multiplication,
and get_docstring() needs a complete list of node types in its case
statements in order to work correctly.

-- 
-------------------------------------------------------------------------------
Konrad Hinsen                     | E-Mail: hinsenk@ere.umontreal.ca
Departement de Chimie             | Tel.: +1-514-343-6111 ext. 3953
Universite de Montreal            | Fax:  +1-514-343-7586
C.P. 6128, succ. A                | Deutsch/Esperanto/English/Nederlands/
Montreal (QC) H3C 3J7             | Francais (phase experimentale)
-------------------------------------------------------------------------------

=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================