[PyQt] Possible small bug in docstring generation
Shaheed Haque
srhaque at theiet.org
Sat Jun 17 13:22:06 BST 2017
We are not quite there...for the char case, as ooposed to the string
case, soemthing like this is needed:
=========
$ diff -u gencode.c.original gencode.c
--- gencode.c.original 2017-06-17 12:14:22.434916795 +0200
+++ gencode.c 2017-06-17 14:15:55.476982401 +0200
@@ -469,7 +469,10 @@
switch (vd->vtype)
{
case qchar_value:
- prcode(fp,"'%c'",vd->u.vqchar);
+ if ((vd->u.vqchar == '"') && in_str)
+ prcode(fp,"'\\\"'");
+ else
+ prcode(fp,"'%c'",vd->u.vqchar);
break;
case string_value:
==========
else stuff like this goes wrong in the docstring case:
==========
PyDoc_STRVAR(doc_KMime_HeaderParsing_parseGenericQuotedString,
"parseGenericQuotedString(str, str, bool, str = '\"', str = '\"') ->
Tuple[bool, str, str]");
extern "C" {static PyObject
*meth_KMime_HeaderParsing_parseGenericQuotedString(PyObject *,
PyObject *);}
static PyObject
*meth_KMime_HeaderParsing_parseGenericQuotedString(PyObject *,
PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
const char* a0;
const char* a1;
::QString* a2;
bool a3;
char a4 = '"';
char a5 = '"';
============
Sorry for not realising this earlier.
Thanks, Shaheed
On 17 June 2017 at 11:51, Shaheed Haque <srhaque at theiet.org> wrote:
> On 16 June 2017 at 13:06, Phil Thompson <phil at riverbankcomputing.com> wrote:
>> On 15 Jun 2017, at 7:58 pm, Shaheed Haque <srhaque at theiet.org> wrote:
>>>
>>> Attached is a patch that converts this SIP:
>>>
>>> ===========
>>> virtual void
>>> openDialogIncidenceCreated(Akonadi::ITIPHandlerDialogDelegate::Recipient
>>> recipient, const QString &question,
>>> Akonadi::ITIPHandlerDialogDelegate::Action action =
>>> Akonadi::ITIPHandlerDialogDelegate::ActionAsk, const KGuiItem
>>> &buttonYes = KGuiItem(i18nc("@action:button dialog positive
>>> answer","Send Email")), const KGuiItem &buttonNo =
>>> KGuiItem(i18nc("@action:button dialog negative answer","Do Not
>>> Send")));
>>> ============
>>>
>>> into this C++ code:
>>>
>>> ============
>>> PyDoc_STRVAR(doc_Akonadi_ITIPHandlerDialogDelegate_openDialogIncidenceCreated,
>>> "openDialogIncidenceCreated(self,
>>> Akonadi.ITIPHandlerDialogDelegate.Recipient, str,
>>> Akonadi.ITIPHandlerDialogDelegate.Action =
>>> Akonadi.ITIPHandlerDialogDelegate.ActionAsk, KGuiItem =
>>> KGuiItem(i18nc(\"@action:button dialog positive answer\",\"Send
>>> Email\")), KGuiItem = KGuiItem(i18nc(\"@action:button dialog negative
>>> answer\",\"Do Not Send\")))");
>>> .
>>> .
>>> .
>>> {
>>> ::Akonadi::ITIPHandlerDialogDelegate::Recipient a0;
>>> const ::QString* a1;
>>> int a1State = 0;
>>> ::Akonadi::ITIPHandlerDialogDelegate::Action a2 =
>>> Akonadi::ITIPHandlerDialogDelegate::ActionAsk;
>>> const ::KGuiItem& a3def = KGuiItem(i18nc("@action:button
>>> dialog positive answer","Send Email"));
>>> const ::KGuiItem* a3 = &a3def;
>>> const ::KGuiItem& a4def = KGuiItem(i18nc("@action:button
>>> dialog negative answer","Do Not Send"));
>>> ============
>>>
>>> As you can see, the PyDoc_STRVAR has the quotes escaped, but a3def and
>>> a4def do not. Now, the patch as-is is slightly overkill in the sense
>>> that it introduces a %q format code for prcode, which I expected would
>>> be needed for cases like:
>>>
>>> ..., QString bar = "worst \"stri\\ng ever", ...
>>>
>>> to generate:
>>>
>>> ..., QString bar = \"worst \\\"stri\\\\ng ever\", ...
>>>
>>> However, it seems that SIP's lexer does not like the escapes. I did
>>> not feel comfortable patching that here and now, so as I say, that
>>> make the %q arguably overkill.
>>>
>>> Please consider the patch, which is against sip-4.19.3.dev1706101519,
>>> with or without the %q stuff.
>>
>> Can you try tonight's snapshot? Hopefully the lexer now supports escape characters properly.
>
> I just tried sip-4.19.3.dev1706161918 and that seems to work nicely
> for both the simple case of a quoted string, and also the
> quoted-string-contains-escapes case.
>
> Thanks! Shaheed
>
>
>> Phil
More information about the PyQt
mailing list