typing: add stub functions for `cext/charencoding`
authorMatt Harbison <matt_harbison@yahoo.com>
Sat, 05 Oct 2024 17:32:26 -0400
changeset 51941 e58f02e2f6a9
parent 51940 54d9f496f07a
child 51942 73a43fe3e6fd
typing: add stub functions for `cext/charencoding` I'm not sure if it's better to have a separate file, and currently pytype doesn't really know how to handle these, so it's no help in figuring that out. Technically, these methods are part of the `mercurial.cext.parsers` module, so put them into the existing stub until there's a reason to split it out.
mercurial/cext/parsers.pyi
--- a/mercurial/cext/parsers.pyi	Sat Oct 05 15:00:37 2024 -0400
+++ b/mercurial/cext/parsers.pyi	Sat Oct 05 17:32:26 2024 -0400
@@ -12,6 +12,21 @@
 version: int
 versionerrortext: str
 
+# From charencode.c
+
+# Note: the first 'bytes' arg of isasciistr() can be typed as 'Buffer' from the
+# typing_extensions backport, once the related bug is fixed in pytype, or pytype
+# is run under py3.12.  The arg for asciilower(), asciiupper() and
+# jsonescapeu8fast() is checked specifically for the 'bytes' type.  The 'bytes'
+# return is an instance of 'bytes', not an alias for 'Buffer'.
+#
+# https://github.com/google/pytype/issues/1772
+def isasciistr(s: bytes) -> bool: ...
+def asciilower(s: bytes) -> bytes: ...
+def asciiupper(s: bytes) -> bytes: ...
+def jsonescapeu8fast(u8chars: bytes, paranoid: bool) -> bytes: ...
+
+
 class DirstateItem:
     __doc__: str