Skip to content

Commit

Permalink
Permit return annotations in __text_signature__
Browse files Browse the repository at this point in the history
I.e., extract everything till the "\n--\n\n" marker.
  • Loading branch information
skirpichev committed Feb 13, 2023
1 parent af8609c commit 57df8d4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ find_signature(const char *name, const char *doc)
return doc;
}

#define SIGNATURE_END_MARKER ")\n--\n\n"
#define SIGNATURE_END_MARKER_LENGTH 6
#define SIGNATURE_END_MARKER "\n--\n\n"
#define SIGNATURE_END_MARKER_LENGTH 5
/*
* skips past the end of the docstring's introspection signature.
* (assumes doc starts with a valid signature prefix.)
Expand Down Expand Up @@ -277,11 +277,12 @@ _PyType_GetTextSignatureFromInternalDoc(const char *name, const char *internal_d
Py_RETURN_NONE;
}

/* back "end" up until it points just past the final ')' */
end -= SIGNATURE_END_MARKER_LENGTH - 1;
/* back "end" up until it points just past the end marker */
end -= SIGNATURE_END_MARKER_LENGTH;
assert((end - start) >= 2); /* should be "()" at least */
assert(end[-1] == ')');
assert(end[0] == '\n');
assert(end[1] == '-');
assert(end[2] == '-');
return PyUnicode_FromStringAndSize(start, end - start);
}

Expand Down

0 comments on commit 57df8d4

Please sign in to comment.