Closed JacobSwanson closed 2 years ago
Good catch.
I think it would be more correct to represent NULL
as None
, so in this case the repr looks like:
pygit2.Signature('Foo Ibáñez', 'foo@bar.com', 1322174594, 60, None)
Then for this to work Signature_init
has to be changed to use z
instead of s
:
if (!PyArg_ParseTupleAndKeywords(
args, kwds, "Os|Liz", keywords,
&py_name, &email, &time, &offset, &encoding))
Agreed that representation has better semantics. Updated to reflect!
Fixed up! Let me know if there is anything else I can do. Thanks
One more thing, pygit2/_pygit2.pyi
needs to be updated. I think only _encoding
and __init__
are concerned:
class Signature:
_encoding: str | None
...
def __init__(self, name: str, email: str, time: int, offset: int, encoding: str | None) -> None: ...
Merged, thanks!
FYI, after a second thought I've done follow up commit. The main change is that Signature._encoding
will return utf-8
when internally it's NULL
. This is to keep backwards compatibility, so users don't need to worry about handling None
.
to_unicode()
expects a non-NULLx
argument (due tostrlen(x)
); howeverself->encoding
may be NULL, especially if built withbuild_signature()
(i.e. if called from thecommit.author
property).As a result, any
repr()
on aSignature
with a NULLencoding
will cause a segfault.Other functions manually map NULL to "utf-8" (see
Signature__encoding__get__()
), so we'll do the same thing here.