diff options
| author | Guido van Rossum <guido@python.org> | 2006-08-28 15:27:34 +0000 | 
|---|---|---|
| committer | Guido van Rossum <guido@python.org> | 2006-08-28 15:27:34 +0000 | 
| commit | 86e58e239e39845e706c4afa392423f0fedcdf39 (patch) | |
| tree | 1d0f4d942e644ee5c903636d87176b98a7203371 /Objects/setobject.c | |
| parent | ecfd0b2f3bfd622c3ba148e53d3feebb8c1ae721 (diff) | |
| download | cpython-git-86e58e239e39845e706c4afa392423f0fedcdf39.tar.gz | |
SF patch 1547796 by Georg Brandl -- set literals.
Diffstat (limited to 'Objects/setobject.c')
| -rw-r--r-- | Objects/setobject.c | 21 | 
1 files changed, 17 insertions, 4 deletions
| diff --git a/Objects/setobject.c b/Objects/setobject.c index d65145730c..b4b58b7afa 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -530,14 +530,20 @@ set_tp_print(PySetObject *so, FILE *fp, int flags)  	char *emit = "";	/* No separator emitted on first pass */  	char *separator = ", "; -	fprintf(fp, "%s([", so->ob_type->tp_name); +	if (so->ob_type == &PySet_Type) +		fprintf(fp, "{"); +	else +		fprintf(fp, "%s([", so->ob_type->tp_name);  	while (set_next(so, &pos, &entry)) {  		fputs(emit, fp);  		emit = separator;  		if (PyObject_Print(entry->key, fp, 0) != 0)  			return -1;  	} -	fputs("])", fp); +	if (so->ob_type == &PySet_Type) +		fputs("}", fp); +	else +		fputs("])", fp);  	return 0;  } @@ -554,8 +560,15 @@ set_repr(PySetObject *so)  	if (listrepr == NULL)  		return NULL; -	result = PyString_FromFormat("%s(%s)", so->ob_type->tp_name, -		PyString_AS_STRING(listrepr)); +	if (so->ob_type == &PySet_Type) { +		char *s = PyString_AS_STRING(listrepr); +		s += 1; +		s[strlen(s)-1] = 0; +		result = PyString_FromFormat("{%s}", s); +	} else { +		result = PyString_FromFormat("%s(%s)", so->ob_type->tp_name, +			 PyString_AS_STRING(listrepr)); +	}  	Py_DECREF(listrepr);  	return result;  } | 
