Cython 3.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (316) hide show
  1. Cython/Build/BuildExecutable.py +169 -0
  2. Cython/Build/Cache.py +199 -0
  3. Cython/Build/Cythonize.py +323 -0
  4. Cython/Build/Dependencies.py +1306 -0
  5. Cython/Build/Distutils.py +1 -0
  6. Cython/Build/Inline.py +463 -0
  7. Cython/Build/IpythonMagic.py +560 -0
  8. Cython/Build/SharedModule.py +76 -0
  9. Cython/Build/Tests/TestCyCache.py +194 -0
  10. Cython/Build/Tests/TestCythonizeArgsParser.py +481 -0
  11. Cython/Build/Tests/TestDependencies.py +133 -0
  12. Cython/Build/Tests/TestInline.py +177 -0
  13. Cython/Build/Tests/TestIpythonMagic.py +287 -0
  14. Cython/Build/Tests/TestRecythonize.py +212 -0
  15. Cython/Build/Tests/TestStripLiterals.py +155 -0
  16. Cython/Build/Tests/__init__.py +1 -0
  17. Cython/Build/__init__.py +8 -0
  18. Cython/CodeWriter.py +811 -0
  19. Cython/Compiler/AnalysedTreeTransforms.py +97 -0
  20. Cython/Compiler/Annotate.py +326 -0
  21. Cython/Compiler/AutoDocTransforms.py +320 -0
  22. Cython/Compiler/Buffer.py +680 -0
  23. Cython/Compiler/Builtin.py +934 -0
  24. Cython/Compiler/CmdLine.py +259 -0
  25. Cython/Compiler/Code.pxd +148 -0
  26. Cython/Compiler/Code.py +3375 -0
  27. Cython/Compiler/CodeGeneration.py +33 -0
  28. Cython/Compiler/CythonScope.py +187 -0
  29. Cython/Compiler/Dataclass.py +868 -0
  30. Cython/Compiler/DebugFlags.py +24 -0
  31. Cython/Compiler/Errors.py +295 -0
  32. Cython/Compiler/ExprNodes.py +15267 -0
  33. Cython/Compiler/FlowControl.pxd +97 -0
  34. Cython/Compiler/FlowControl.py +1455 -0
  35. Cython/Compiler/FusedNode.py +1002 -0
  36. Cython/Compiler/Future.py +16 -0
  37. Cython/Compiler/Interpreter.py +57 -0
  38. Cython/Compiler/Lexicon.py +340 -0
  39. Cython/Compiler/LineTable.py +114 -0
  40. Cython/Compiler/Main.py +853 -0
  41. Cython/Compiler/MatchCaseNodes.py +259 -0
  42. Cython/Compiler/MemoryView.py +922 -0
  43. Cython/Compiler/ModuleNode.py +4024 -0
  44. Cython/Compiler/Naming.py +374 -0
  45. Cython/Compiler/Nodes.py +10826 -0
  46. Cython/Compiler/Optimize.py +5256 -0
  47. Cython/Compiler/Options.py +835 -0
  48. Cython/Compiler/ParseTreeTransforms.pxd +77 -0
  49. Cython/Compiler/ParseTreeTransforms.py +4509 -0
  50. Cython/Compiler/Parsing.pxd +9 -0
  51. Cython/Compiler/Parsing.py +4789 -0
  52. Cython/Compiler/Pipeline.py +439 -0
  53. Cython/Compiler/PyrexTypes.py +5762 -0
  54. Cython/Compiler/Pythran.py +232 -0
  55. Cython/Compiler/Scanning.pxd +40 -0
  56. Cython/Compiler/Scanning.py +577 -0
  57. Cython/Compiler/StringEncoding.py +347 -0
  58. Cython/Compiler/Symtab.py +3080 -0
  59. Cython/Compiler/Tests/TestBuffer.py +105 -0
  60. Cython/Compiler/Tests/TestBuiltin.py +72 -0
  61. Cython/Compiler/Tests/TestCmdLine.py +586 -0
  62. Cython/Compiler/Tests/TestCode.py +86 -0
  63. Cython/Compiler/Tests/TestFlowControl.py +65 -0
  64. Cython/Compiler/Tests/TestGrammar.py +202 -0
  65. Cython/Compiler/Tests/TestMemView.py +71 -0
  66. Cython/Compiler/Tests/TestParseTreeTransforms.py +285 -0
  67. Cython/Compiler/Tests/TestScanning.py +134 -0
  68. Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
  69. Cython/Compiler/Tests/TestStringEncoding.py +33 -0
  70. Cython/Compiler/Tests/TestTreeFragment.py +63 -0
  71. Cython/Compiler/Tests/TestTreePath.py +103 -0
  72. Cython/Compiler/Tests/TestTypes.py +75 -0
  73. Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
  74. Cython/Compiler/Tests/TestVisitor.py +61 -0
  75. Cython/Compiler/Tests/Utils.py +36 -0
  76. Cython/Compiler/Tests/__init__.py +1 -0
  77. Cython/Compiler/TreeFragment.py +278 -0
  78. Cython/Compiler/TreePath.py +303 -0
  79. Cython/Compiler/TypeInference.py +584 -0
  80. Cython/Compiler/TypeSlots.py +1181 -0
  81. Cython/Compiler/UFuncs.py +311 -0
  82. Cython/Compiler/UtilNodes.py +389 -0
  83. Cython/Compiler/UtilityCode.py +344 -0
  84. Cython/Compiler/Version.py +8 -0
  85. Cython/Compiler/Visitor.pxd +53 -0
  86. Cython/Compiler/Visitor.py +861 -0
  87. Cython/Compiler/__init__.py +1 -0
  88. Cython/Coverage.py +448 -0
  89. Cython/Debugger/Cygdb.py +175 -0
  90. Cython/Debugger/DebugWriter.py +82 -0
  91. Cython/Debugger/Tests/TestLibCython.py +275 -0
  92. Cython/Debugger/Tests/__init__.py +1 -0
  93. Cython/Debugger/Tests/cfuncs.c +8 -0
  94. Cython/Debugger/Tests/codefile +49 -0
  95. Cython/Debugger/Tests/test_libcython_in_gdb.py +578 -0
  96. Cython/Debugger/Tests/test_libpython_in_gdb.py +90 -0
  97. Cython/Debugger/__init__.py +1 -0
  98. Cython/Debugger/libcython.py +1548 -0
  99. Cython/Debugger/libpython.py +2821 -0
  100. Cython/Debugging.py +20 -0
  101. Cython/Distutils/__init__.py +2 -0
  102. Cython/Distutils/build_ext.py +139 -0
  103. Cython/Distutils/extension.py +96 -0
  104. Cython/Distutils/old_build_ext.py +351 -0
  105. Cython/Includes/cpython/__init__.pxd +173 -0
  106. Cython/Includes/cpython/array.pxd +174 -0
  107. Cython/Includes/cpython/bool.pxd +37 -0
  108. Cython/Includes/cpython/buffer.pxd +112 -0
  109. Cython/Includes/cpython/bytearray.pxd +33 -0
  110. Cython/Includes/cpython/bytes.pxd +200 -0
  111. Cython/Includes/cpython/cellobject.pxd +35 -0
  112. Cython/Includes/cpython/ceval.pxd +8 -0
  113. Cython/Includes/cpython/codecs.pxd +121 -0
  114. Cython/Includes/cpython/complex.pxd +60 -0
  115. Cython/Includes/cpython/contextvars.pxd +145 -0
  116. Cython/Includes/cpython/conversion.pxd +36 -0
  117. Cython/Includes/cpython/datetime.pxd +395 -0
  118. Cython/Includes/cpython/descr.pxd +26 -0
  119. Cython/Includes/cpython/dict.pxd +187 -0
  120. Cython/Includes/cpython/exc.pxd +263 -0
  121. Cython/Includes/cpython/fileobject.pxd +57 -0
  122. Cython/Includes/cpython/float.pxd +47 -0
  123. Cython/Includes/cpython/function.pxd +65 -0
  124. Cython/Includes/cpython/genobject.pxd +25 -0
  125. Cython/Includes/cpython/getargs.pxd +12 -0
  126. Cython/Includes/cpython/instance.pxd +25 -0
  127. Cython/Includes/cpython/iterator.pxd +36 -0
  128. Cython/Includes/cpython/iterobject.pxd +24 -0
  129. Cython/Includes/cpython/list.pxd +92 -0
  130. Cython/Includes/cpython/long.pxd +149 -0
  131. Cython/Includes/cpython/longintrepr.pxd +14 -0
  132. Cython/Includes/cpython/mapping.pxd +63 -0
  133. Cython/Includes/cpython/marshal.pxd +66 -0
  134. Cython/Includes/cpython/mem.pxd +120 -0
  135. Cython/Includes/cpython/memoryview.pxd +50 -0
  136. Cython/Includes/cpython/method.pxd +49 -0
  137. Cython/Includes/cpython/module.pxd +208 -0
  138. Cython/Includes/cpython/number.pxd +258 -0
  139. Cython/Includes/cpython/object.pxd +433 -0
  140. Cython/Includes/cpython/pycapsule.pxd +143 -0
  141. Cython/Includes/cpython/pylifecycle.pxd +68 -0
  142. Cython/Includes/cpython/pyport.pxd +8 -0
  143. Cython/Includes/cpython/pystate.pxd +95 -0
  144. Cython/Includes/cpython/pythread.pxd +53 -0
  145. Cython/Includes/cpython/ref.pxd +67 -0
  146. Cython/Includes/cpython/sequence.pxd +134 -0
  147. Cython/Includes/cpython/set.pxd +119 -0
  148. Cython/Includes/cpython/slice.pxd +70 -0
  149. Cython/Includes/cpython/time.pxd +129 -0
  150. Cython/Includes/cpython/tuple.pxd +72 -0
  151. Cython/Includes/cpython/type.pxd +53 -0
  152. Cython/Includes/cpython/unicode.pxd +639 -0
  153. Cython/Includes/cpython/version.pxd +32 -0
  154. Cython/Includes/cpython/weakref.pxd +78 -0
  155. Cython/Includes/libc/__init__.pxd +1 -0
  156. Cython/Includes/libc/complex.pxd +35 -0
  157. Cython/Includes/libc/errno.pxd +127 -0
  158. Cython/Includes/libc/float.pxd +43 -0
  159. Cython/Includes/libc/limits.pxd +28 -0
  160. Cython/Includes/libc/locale.pxd +46 -0
  161. Cython/Includes/libc/math.pxd +209 -0
  162. Cython/Includes/libc/setjmp.pxd +10 -0
  163. Cython/Includes/libc/signal.pxd +64 -0
  164. Cython/Includes/libc/stddef.pxd +9 -0
  165. Cython/Includes/libc/stdint.pxd +105 -0
  166. Cython/Includes/libc/stdio.pxd +80 -0
  167. Cython/Includes/libc/stdlib.pxd +72 -0
  168. Cython/Includes/libc/string.pxd +50 -0
  169. Cython/Includes/libc/threads.pxd +84 -0
  170. Cython/Includes/libc/time.pxd +51 -0
  171. Cython/Includes/libcpp/__init__.pxd +4 -0
  172. Cython/Includes/libcpp/algorithm.pxd +320 -0
  173. Cython/Includes/libcpp/any.pxd +16 -0
  174. Cython/Includes/libcpp/atomic.pxd +59 -0
  175. Cython/Includes/libcpp/barrier.pxd +22 -0
  176. Cython/Includes/libcpp/bit.pxd +29 -0
  177. Cython/Includes/libcpp/cast.pxd +12 -0
  178. Cython/Includes/libcpp/cmath.pxd +518 -0
  179. Cython/Includes/libcpp/complex.pxd +106 -0
  180. Cython/Includes/libcpp/deque.pxd +165 -0
  181. Cython/Includes/libcpp/exception.pxd +86 -0
  182. Cython/Includes/libcpp/execution.pxd +15 -0
  183. Cython/Includes/libcpp/forward_list.pxd +63 -0
  184. Cython/Includes/libcpp/functional.pxd +26 -0
  185. Cython/Includes/libcpp/future.pxd +103 -0
  186. Cython/Includes/libcpp/iterator.pxd +34 -0
  187. Cython/Includes/libcpp/latch.pxd +17 -0
  188. Cython/Includes/libcpp/limits.pxd +61 -0
  189. Cython/Includes/libcpp/list.pxd +117 -0
  190. Cython/Includes/libcpp/map.pxd +252 -0
  191. Cython/Includes/libcpp/memory.pxd +115 -0
  192. Cython/Includes/libcpp/mutex.pxd +130 -0
  193. Cython/Includes/libcpp/numbers.pxd +15 -0
  194. Cython/Includes/libcpp/numeric.pxd +131 -0
  195. Cython/Includes/libcpp/optional.pxd +34 -0
  196. Cython/Includes/libcpp/pair.pxd +1 -0
  197. Cython/Includes/libcpp/queue.pxd +25 -0
  198. Cython/Includes/libcpp/random.pxd +166 -0
  199. Cython/Includes/libcpp/semaphore.pxd +44 -0
  200. Cython/Includes/libcpp/set.pxd +228 -0
  201. Cython/Includes/libcpp/shared_mutex.pxd +72 -0
  202. Cython/Includes/libcpp/span.pxd +87 -0
  203. Cython/Includes/libcpp/stack.pxd +11 -0
  204. Cython/Includes/libcpp/stop_token.pxd +105 -0
  205. Cython/Includes/libcpp/string.pxd +355 -0
  206. Cython/Includes/libcpp/string_view.pxd +181 -0
  207. Cython/Includes/libcpp/typeindex.pxd +15 -0
  208. Cython/Includes/libcpp/typeinfo.pxd +10 -0
  209. Cython/Includes/libcpp/unordered_map.pxd +193 -0
  210. Cython/Includes/libcpp/unordered_set.pxd +152 -0
  211. Cython/Includes/libcpp/utility.pxd +30 -0
  212. Cython/Includes/libcpp/vector.pxd +186 -0
  213. Cython/Includes/openmp.pxd +50 -0
  214. Cython/Includes/posix/__init__.pxd +1 -0
  215. Cython/Includes/posix/dlfcn.pxd +14 -0
  216. Cython/Includes/posix/fcntl.pxd +86 -0
  217. Cython/Includes/posix/ioctl.pxd +4 -0
  218. Cython/Includes/posix/mman.pxd +101 -0
  219. Cython/Includes/posix/resource.pxd +57 -0
  220. Cython/Includes/posix/select.pxd +21 -0
  221. Cython/Includes/posix/signal.pxd +73 -0
  222. Cython/Includes/posix/stat.pxd +98 -0
  223. Cython/Includes/posix/stdio.pxd +37 -0
  224. Cython/Includes/posix/stdlib.pxd +29 -0
  225. Cython/Includes/posix/strings.pxd +9 -0
  226. Cython/Includes/posix/time.pxd +71 -0
  227. Cython/Includes/posix/types.pxd +30 -0
  228. Cython/Includes/posix/uio.pxd +26 -0
  229. Cython/Includes/posix/unistd.pxd +271 -0
  230. Cython/Includes/posix/wait.pxd +38 -0
  231. Cython/Plex/Actions.pxd +24 -0
  232. Cython/Plex/Actions.py +119 -0
  233. Cython/Plex/DFA.pxd +14 -0
  234. Cython/Plex/DFA.py +164 -0
  235. Cython/Plex/Errors.py +48 -0
  236. Cython/Plex/Lexicons.py +178 -0
  237. Cython/Plex/Machines.pxd +36 -0
  238. Cython/Plex/Machines.py +238 -0
  239. Cython/Plex/Regexps.py +539 -0
  240. Cython/Plex/Scanners.pxd +47 -0
  241. Cython/Plex/Scanners.py +360 -0
  242. Cython/Plex/Transitions.pxd +14 -0
  243. Cython/Plex/Transitions.py +239 -0
  244. Cython/Plex/__init__.py +34 -0
  245. Cython/Runtime/__init__.py +1 -0
  246. Cython/Runtime/refnanny.pyx +237 -0
  247. Cython/Shadow.py +690 -0
  248. Cython/Shadow.pyi +521 -0
  249. Cython/StringIOTree.py +170 -0
  250. Cython/Tempita/__init__.py +4 -0
  251. Cython/Tempita/_looper.py +154 -0
  252. Cython/Tempita/_tempita.py +1091 -0
  253. Cython/TestUtils.py +410 -0
  254. Cython/Tests/TestCodeWriter.py +128 -0
  255. Cython/Tests/TestCythonUtils.py +202 -0
  256. Cython/Tests/TestJediTyper.py +223 -0
  257. Cython/Tests/TestShadow.py +114 -0
  258. Cython/Tests/TestStringIOTree.py +67 -0
  259. Cython/Tests/TestTestUtils.py +90 -0
  260. Cython/Tests/__init__.py +1 -0
  261. Cython/Tests/xmlrunner.py +390 -0
  262. Cython/Utility/AsyncGen.c +1002 -0
  263. Cython/Utility/Buffer.c +875 -0
  264. Cython/Utility/BufferFormatFromTypeInfo.pxd +2 -0
  265. Cython/Utility/Builtins.c +776 -0
  266. Cython/Utility/CConvert.pyx +134 -0
  267. Cython/Utility/CMath.c +104 -0
  268. Cython/Utility/CommonStructures.c +118 -0
  269. Cython/Utility/Complex.c +378 -0
  270. Cython/Utility/Coroutine.c +2206 -0
  271. Cython/Utility/CpdefEnums.pyx +103 -0
  272. Cython/Utility/CppConvert.pyx +279 -0
  273. Cython/Utility/CppSupport.cpp +143 -0
  274. Cython/Utility/CythonFunction.c +1794 -0
  275. Cython/Utility/Dataclasses.c +185 -0
  276. Cython/Utility/Dataclasses.py +112 -0
  277. Cython/Utility/Embed.c +125 -0
  278. Cython/Utility/Exceptions.c +1012 -0
  279. Cython/Utility/ExtensionTypes.c +809 -0
  280. Cython/Utility/FunctionArguments.c +965 -0
  281. Cython/Utility/ImportExport.c +987 -0
  282. Cython/Utility/Lock.c +136 -0
  283. Cython/Utility/MemoryView.pxd +187 -0
  284. Cython/Utility/MemoryView.pyx +1481 -0
  285. Cython/Utility/MemoryView_C.c +1046 -0
  286. Cython/Utility/ModuleSetupCode.c +3059 -0
  287. Cython/Utility/NumpyImportArray.c +46 -0
  288. Cython/Utility/ObjectHandling.c +3342 -0
  289. Cython/Utility/Optimize.c +1589 -0
  290. Cython/Utility/Overflow.c +404 -0
  291. Cython/Utility/Printing.c +86 -0
  292. Cython/Utility/Profile.c +709 -0
  293. Cython/Utility/StringTools.c +1259 -0
  294. Cython/Utility/TestCyUtilityLoader.pyx +8 -0
  295. Cython/Utility/TestCythonScope.pyx +75 -0
  296. Cython/Utility/TestUtilityLoader.c +12 -0
  297. Cython/Utility/TypeConversion.c +1284 -0
  298. Cython/Utility/UFuncs.pyx +50 -0
  299. Cython/Utility/UFuncs_C.c +89 -0
  300. Cython/Utility/__init__.py +28 -0
  301. Cython/Utility/arrayarray.h +148 -0
  302. Cython/Utils.py +687 -0
  303. Cython/__init__.py +10 -0
  304. Cython/__init__.pyi +7 -0
  305. Cython/py.typed +0 -0
  306. cython-3.1.0.dist-info/COPYING.txt +19 -0
  307. cython-3.1.0.dist-info/LICENSE.txt +176 -0
  308. cython-3.1.0.dist-info/METADATA +636 -0
  309. cython-3.1.0.dist-info/RECORD +316 -0
  310. cython-3.1.0.dist-info/WHEEL +5 -0
  311. cython-3.1.0.dist-info/entry_points.txt +4 -0
  312. cython-3.1.0.dist-info/top_level.txt +3 -0
  313. cython.py +29 -0
  314. pyximport/__init__.py +4 -0
  315. pyximport/pyxbuild.py +160 -0
  316. pyximport/pyximport.py +482 -0
@@ -0,0 +1,965 @@
1
+ //////////////////// ArgTypeTest.proto ////////////////////
2
+
3
+
4
+ // Exact is 0 (False), 1 (True) or 2 (True and from annotation)
5
+ // The latter gives a small amount of extra error diagnostics
6
+ #define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact) \
7
+ ((likely(__Pyx_IS_TYPE(obj, type) | (none_allowed && (obj == Py_None)))) ? 1 : \
8
+ __Pyx__ArgTypeTest(obj, type, name, exact))
9
+
10
+ static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact); /*proto*/
11
+
12
+ //////////////////// ArgTypeTest ////////////////////
13
+
14
+ static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact)
15
+ {
16
+ __Pyx_TypeName type_name;
17
+ __Pyx_TypeName obj_type_name;
18
+ PyObject *extra_info = EMPTY(unicode);
19
+ int from_annotation_subclass = 0;
20
+ if (unlikely(!type)) {
21
+ PyErr_SetString(PyExc_SystemError, "Missing type object");
22
+ return 0;
23
+ }
24
+ else if (!exact) {
25
+ if (likely(__Pyx_TypeCheck(obj, type))) return 1;
26
+ } else if (exact == 2) {
27
+ // type from annotation
28
+ if (__Pyx_TypeCheck(obj, type)) {
29
+ from_annotation_subclass = 1;
30
+ extra_info = PYUNICODE("Note that Cython is deliberately stricter than PEP-484 and rejects subclasses of builtin types. If you need to pass subclasses then set the 'annotation_typing' directive to False.");
31
+ }
32
+ }
33
+ type_name = __Pyx_PyType_GetFullyQualifiedName(type);
34
+ obj_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(obj));
35
+ PyErr_Format(PyExc_TypeError,
36
+ "Argument '%.200s' has incorrect type (expected " __Pyx_FMT_TYPENAME
37
+ ", got " __Pyx_FMT_TYPENAME ")"
38
+ #if __PYX_LIMITED_VERSION_HEX < 0x030C0000
39
+ "%s%U"
40
+ #endif
41
+ , name, type_name, obj_type_name
42
+ #if __PYX_LIMITED_VERSION_HEX < 0x030C0000
43
+ , (from_annotation_subclass ? ". " : ""), extra_info
44
+ #endif
45
+ );
46
+ #if __PYX_LIMITED_VERSION_HEX >= 0x030C0000
47
+ // Set the extra_info as a note instead. In principle it'd be possible to do this
48
+ // from Python 3.11 up, but PyErr_GetRaisedException makes it much easier so do it
49
+ // from Python 3.12 instead.
50
+ if (exact == 2 && from_annotation_subclass) {
51
+ PyObject *res;
52
+ PyObject *vargs[2];
53
+ vargs[0] = PyErr_GetRaisedException();
54
+ vargs[1] = extra_info;
55
+ res = PyObject_VectorcallMethod(PYUNICODE("add_note"), vargs, 2, NULL);
56
+ Py_XDECREF(res);
57
+ PyErr_SetRaisedException(vargs[0]);
58
+ }
59
+ #endif
60
+ __Pyx_DECREF_TypeName(type_name);
61
+ __Pyx_DECREF_TypeName(obj_type_name);
62
+ return 0;
63
+ }
64
+
65
+ //////////////////// RaiseArgTupleInvalid.proto ////////////////////
66
+
67
+ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
68
+ Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
69
+
70
+ //////////////////// RaiseArgTupleInvalid ////////////////////
71
+
72
+ // __Pyx_RaiseArgtupleInvalid raises the correct exception when too
73
+ // many or too few positional arguments were found. This handles
74
+ // Py_ssize_t formatting correctly.
75
+
76
+ static void __Pyx_RaiseArgtupleInvalid(
77
+ const char* func_name,
78
+ int exact,
79
+ Py_ssize_t num_min,
80
+ Py_ssize_t num_max,
81
+ Py_ssize_t num_found)
82
+ {
83
+ Py_ssize_t num_expected;
84
+ const char *more_or_less;
85
+
86
+ if (num_found < num_min) {
87
+ num_expected = num_min;
88
+ more_or_less = "at least";
89
+ } else {
90
+ num_expected = num_max;
91
+ more_or_less = "at most";
92
+ }
93
+ if (exact) {
94
+ more_or_less = "exactly";
95
+ }
96
+ PyErr_Format(PyExc_TypeError,
97
+ "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
98
+ func_name, more_or_less, num_expected,
99
+ (num_expected == 1) ? "" : "s", num_found);
100
+ }
101
+
102
+
103
+ //////////////////// RaiseKeywordRequired.proto ////////////////////
104
+
105
+ static void __Pyx_RaiseKeywordRequired(const char* func_name, PyObject* kw_name); /*proto*/
106
+
107
+ //////////////////// RaiseKeywordRequired ////////////////////
108
+
109
+ static void __Pyx_RaiseKeywordRequired(const char* func_name, PyObject* kw_name) {
110
+ PyErr_Format(PyExc_TypeError,
111
+ "%s() needs keyword-only argument %U", func_name, kw_name);
112
+ }
113
+
114
+
115
+ //////////////////// RaiseDoubleKeywords.proto ////////////////////
116
+
117
+ static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/
118
+
119
+ //////////////////// RaiseDoubleKeywords ////////////////////
120
+
121
+ static void __Pyx_RaiseDoubleKeywordsError(
122
+ const char* func_name,
123
+ PyObject* kw_name)
124
+ {
125
+ PyErr_Format(PyExc_TypeError,
126
+ "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
127
+ }
128
+
129
+
130
+ //////////////////// RaiseMappingExpected.proto ////////////////////
131
+
132
+ static void __Pyx_RaiseMappingExpectedError(PyObject* arg); /*proto*/
133
+
134
+ //////////////////// RaiseMappingExpected ////////////////////
135
+
136
+ static void __Pyx_RaiseMappingExpectedError(PyObject* arg) {
137
+ __Pyx_TypeName arg_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(arg));
138
+ PyErr_Format(PyExc_TypeError,
139
+ "'" __Pyx_FMT_TYPENAME "' object is not a mapping", arg_type_name);
140
+ __Pyx_DECREF_TypeName(arg_type_name);
141
+ }
142
+
143
+
144
+ //////////////////// KeywordStringCheck.proto ////////////////////
145
+
146
+ static CYTHON_INLINE int __Pyx_CheckKeywordStrings(const char* function_name, PyObject *kw); /*proto*/
147
+
148
+ //////////////////// KeywordStringCheck ////////////////////
149
+
150
+ // __Pyx_CheckKeywordStrings raises an error if non-string keywords
151
+ // were passed to a function.
152
+ //
153
+ // The "kw" argument is either a dict (for METH_VARARGS) or a tuple
154
+ // (for METH_FASTCALL), both non-empty.
155
+
156
+ static int __Pyx_CheckKeywordStrings(
157
+ const char* function_name,
158
+ PyObject *kw)
159
+ {
160
+ // PyPy appears to check keyword types at call time, not at unpacking time.
161
+ #if CYTHON_COMPILING_IN_PYPY
162
+ CYTHON_UNUSED_VAR(function_name);
163
+ CYTHON_UNUSED_VAR(kw);
164
+ return 0;
165
+ #else
166
+
167
+ // Validate keyword types.
168
+ if (CYTHON_METH_FASTCALL && likely(PyTuple_Check(kw))) {
169
+ // On CPython >= 3.9, the FASTCALL protocol guarantees that keyword
170
+ // names are strings (see https://github.com/python/cpython/issues/81721)
171
+ #if PY_VERSION_HEX >= 0x03090000
172
+ CYTHON_UNUSED_VAR(function_name);
173
+ #else
174
+
175
+ Py_ssize_t kwsize;
176
+ #if CYTHON_ASSUME_SAFE_SIZE
177
+ kwsize = PyTuple_GET_SIZE(kw);
178
+ #else
179
+ kwsize = PyTuple_Size(kw);
180
+ if (unlikely(kwsize < 0)) return -1;
181
+ #endif
182
+
183
+ for (Py_ssize_t pos = 0; pos < kwsize; pos++) {
184
+ PyObject* key = NULL;
185
+ #if CYTHON_ASSUME_SAFE_MACROS
186
+ key = PyTuple_GET_ITEM(kw, pos);
187
+ #else
188
+ key = PyTuple_GetItem(kw, pos);
189
+ if (unlikely(!key)) return -1;
190
+ #endif
191
+
192
+ if (unlikely(!PyUnicode_Check(key))) {
193
+ PyErr_Format(PyExc_TypeError,
194
+ "%.200s() keywords must be strings", function_name);
195
+ return -1;
196
+ }
197
+ }
198
+ #endif
199
+ } else {
200
+ // Otherwise, 'kw' is a dict: check if it's unicode-keys-only and let Python set the error otherwise.
201
+ if (unlikely(!PyArg_ValidateKeywordArguments(kw))) return -1;
202
+ }
203
+
204
+ return 0;
205
+ #endif
206
+ }
207
+
208
+
209
+ //////////////////// RejectKeywords.proto ////////////////////
210
+
211
+ static void __Pyx_RejectKeywords(const char* function_name, PyObject *kwds); /*proto*/
212
+
213
+ //////////////////// RejectKeywords ////////////////////
214
+
215
+ static void __Pyx_RejectKeywords(const char* function_name, PyObject *kwds) {
216
+ // Get the first keyword argument (there is at least one) and raise a TypeError for it.
217
+ PyObject *key = NULL;
218
+ if (CYTHON_METH_FASTCALL && likely(PyTuple_Check(kwds))) {
219
+ key = __Pyx_PySequence_ITEM(kwds, 0);
220
+ } else {
221
+ Py_ssize_t pos = 0;
222
+ // Check if dict is unicode-keys-only and let Python set the error otherwise.
223
+ if (unlikely(!PyArg_ValidateKeywordArguments(kwds))) return;
224
+ // Read first key.
225
+ PyDict_Next(kwds, &pos, &key, NULL);
226
+ Py_INCREF(key);
227
+ }
228
+
229
+ if (likely(key)) {
230
+ PyErr_Format(PyExc_TypeError,
231
+ "%s() got an unexpected keyword argument '%U'",
232
+ function_name, key);
233
+ Py_DECREF(key);
234
+ }
235
+ }
236
+
237
+
238
+ //////////////////// ParseKeywords.proto ////////////////////
239
+
240
+ static CYTHON_INLINE int __Pyx_ParseKeywords(
241
+ PyObject *kwds, PyObject *const *kwvalues, PyObject ** const argnames[],
242
+ PyObject *kwds2, PyObject *values[],
243
+ Py_ssize_t num_pos_args, Py_ssize_t num_kwargs,
244
+ const char* function_name,
245
+ int ignore_unknown_kwargs
246
+ ); /*proto*/
247
+
248
+ //////////////////// ParseKeywords ////////////////////
249
+ //@requires: RaiseDoubleKeywords
250
+
251
+ // __Pyx_ParseOptionalKeywords copies the optional/unknown keyword
252
+ // arguments from kwds into the dict kwds2. If kwds2 is NULL, unknown
253
+ // keywords will raise an invalid keyword error.
254
+ //
255
+ // When not using METH_FASTCALL, kwds is a dict and kwvalues is NULL.
256
+ // Otherwise, kwds is a tuple with keyword names and kwvalues is a C
257
+ // array with the corresponding values.
258
+ //
259
+ // Three kinds of errors are checked: 1) non-string keywords, 2)
260
+ // unexpected keywords and 3) overlap with positional arguments.
261
+ //
262
+ // If num_posargs is greater 0, it denotes the number of positional
263
+ // arguments that were passed and that must therefore not appear
264
+ // amongst the keywords as well.
265
+ //
266
+ // This method does not check for required keyword arguments.
267
+
268
+ static int __Pyx_ValidateDuplicatePosArgs(
269
+ PyObject *kwds,
270
+ PyObject ** const argnames[],
271
+ PyObject ** const *first_kw_arg,
272
+ const char* function_name)
273
+ {
274
+ PyObject ** const *name = argnames;
275
+ while (name != first_kw_arg) {
276
+ PyObject *key = **name;
277
+ int found = PyDict_Contains(kwds, key);
278
+ if (unlikely(found)) {
279
+ if (found == 1) __Pyx_RaiseDoubleKeywordsError(function_name, key);
280
+ goto bad;
281
+ }
282
+ name++;
283
+ }
284
+ return 0;
285
+
286
+ bad:
287
+ return -1;
288
+ }
289
+
290
+ #if CYTHON_USE_UNICODE_INTERNALS
291
+ static CYTHON_INLINE int __Pyx_UnicodeKeywordsEqual(PyObject *s1, PyObject *s2) {
292
+ int kind;
293
+ Py_ssize_t len = PyUnicode_GET_LENGTH(s1);
294
+ if (len != PyUnicode_GET_LENGTH(s2)) return 0;
295
+
296
+ kind = PyUnicode_KIND(s1);
297
+ if (kind != PyUnicode_KIND(s2)) return 0;
298
+
299
+ const void *data1 = PyUnicode_DATA(s1);
300
+ const void *data2 = PyUnicode_DATA(s2);
301
+ return (memcmp(data1, data2, (size_t) len * (size_t) kind) == 0);
302
+ }
303
+ #endif
304
+
305
+ static int __Pyx_MatchKeywordArg_str(
306
+ PyObject *key,
307
+ PyObject ** const argnames[],
308
+ PyObject ** const *first_kw_arg,
309
+ size_t *index_found,
310
+ const char *function_name)
311
+ {
312
+ PyObject ** const *name;
313
+ #if CYTHON_USE_UNICODE_INTERNALS
314
+ // The key hash is probably pre-calculated.
315
+ Py_hash_t key_hash = ((PyASCIIObject*)key)->hash;
316
+ if (unlikely(key_hash == -1)) {
317
+ key_hash = PyObject_Hash(key);
318
+ if (unlikely(key_hash == -1))
319
+ goto bad;
320
+ }
321
+ #endif
322
+
323
+ // Compare strings for non-interned matches.
324
+ name = first_kw_arg;
325
+ while (*name) {
326
+ PyObject *name_str = **name;
327
+
328
+ #if CYTHON_USE_UNICODE_INTERNALS
329
+ // The hash value of our interned argument name is definitely pre-calculated.
330
+ if (key_hash == ((PyASCIIObject*)name_str)->hash && __Pyx_UnicodeKeywordsEqual(name_str, key)) {
331
+ *index_found = (size_t) (name - argnames);
332
+ return 1;
333
+ }
334
+ #else
335
+
336
+ #if CYTHON_ASSUME_SAFE_SIZE
337
+ if (PyUnicode_GET_LENGTH(name_str) == PyUnicode_GET_LENGTH(key))
338
+ #endif
339
+ {
340
+ int cmp = PyUnicode_Compare(name_str, key);
341
+ if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
342
+ if (cmp == 0) {
343
+ *index_found = (size_t) (name - argnames);
344
+ return 1;
345
+ }
346
+ }
347
+ #endif
348
+ name++;
349
+ }
350
+
351
+ // Not found in keyword parameters, check for (unlikely) duplicate positional argument.
352
+ name = argnames;
353
+ while (name != first_kw_arg) {
354
+ PyObject *name_str = **name;
355
+
356
+ #if CYTHON_USE_UNICODE_INTERNALS
357
+ if (unlikely(key_hash == ((PyASCIIObject*)name_str)->hash)) {
358
+ if (__Pyx_UnicodeKeywordsEqual(name_str, key))
359
+ goto arg_passed_twice;
360
+ }
361
+
362
+ #else
363
+
364
+ #if CYTHON_ASSUME_SAFE_SIZE
365
+ if (PyUnicode_GET_LENGTH(name_str) == PyUnicode_GET_LENGTH(key))
366
+ #endif
367
+ {
368
+ if (unlikely(name_str == key)) goto arg_passed_twice;
369
+ int cmp = PyUnicode_Compare(name_str, key);
370
+ if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
371
+ if (cmp == 0) goto arg_passed_twice;
372
+ }
373
+
374
+ #endif
375
+ name++;
376
+ }
377
+
378
+ return 0;
379
+
380
+ arg_passed_twice:
381
+ __Pyx_RaiseDoubleKeywordsError(function_name, key);
382
+ goto bad;
383
+ bad:
384
+ return -1;
385
+ }
386
+
387
+ static int __Pyx_MatchKeywordArg_nostr(
388
+ PyObject *key,
389
+ PyObject ** const argnames[],
390
+ PyObject ** const *first_kw_arg,
391
+ size_t *index_found,
392
+ const char *function_name)
393
+ {
394
+ // Conservatively handle str subclasses.
395
+ PyObject ** const *name;
396
+
397
+ if (unlikely(!PyUnicode_Check(key))) goto invalid_keyword_type;
398
+
399
+ // Match keyword argument names.
400
+ name = first_kw_arg;
401
+ while (*name) {
402
+ int cmp = PyObject_RichCompareBool(**name, key, Py_EQ);
403
+ if (cmp == 1) {
404
+ *index_found = (size_t) (name - argnames);
405
+ return 1;
406
+ }
407
+ if (unlikely(cmp == -1)) goto bad;
408
+ name++;
409
+ }
410
+ // Reject collisions with positional arguments.
411
+ name = argnames;
412
+ while (name != first_kw_arg) {
413
+ int cmp = PyObject_RichCompareBool(**name, key, Py_EQ);
414
+ if (unlikely(cmp != 0)) {
415
+ if (cmp == 1) goto arg_passed_twice;
416
+ else goto bad;
417
+ }
418
+ name++;
419
+ }
420
+ return 0;
421
+
422
+ arg_passed_twice:
423
+ __Pyx_RaiseDoubleKeywordsError(function_name, key);
424
+ goto bad;
425
+ invalid_keyword_type:
426
+ PyErr_Format(PyExc_TypeError,
427
+ "%.200s() keywords must be strings", function_name);
428
+ goto bad;
429
+ bad:
430
+ return -1;
431
+ }
432
+
433
+ static CYTHON_INLINE int __Pyx_MatchKeywordArg(
434
+ PyObject *key,
435
+ PyObject ** const argnames[],
436
+ PyObject ** const *first_kw_arg,
437
+ size_t *index_found,
438
+ const char *function_name)
439
+ {
440
+ // Optimise for plain str behaviour.
441
+ return likely(PyUnicode_CheckExact(key)) ?
442
+ __Pyx_MatchKeywordArg_str(key, argnames, first_kw_arg, index_found, function_name) :
443
+ __Pyx_MatchKeywordArg_nostr(key, argnames, first_kw_arg, index_found, function_name);
444
+ }
445
+
446
+ static void __Pyx_RejectUnknownKeyword(
447
+ PyObject *kwds,
448
+ PyObject ** const argnames[],
449
+ PyObject ** const *first_kw_arg,
450
+ const char *function_name)
451
+ {
452
+ // Find the first unknown keyword and raise an error. There must be at least one.
453
+ Py_ssize_t pos = 0;
454
+ PyObject *key = NULL;
455
+
456
+ __Pyx_BEGIN_CRITICAL_SECTION(kwds);
457
+ while (PyDict_Next(kwds, &pos, &key, NULL)) {
458
+ // Quickly exclude the 'obviously' valid/known keyword arguments (exact pointer match).
459
+ PyObject** const *name = first_kw_arg;
460
+ while (*name && (**name != key)) name++;
461
+
462
+ if (!*name) {
463
+ // No exact match found:
464
+ // compare against positional (always reject) and keyword (reject unknown) names.
465
+ #if CYTHON_AVOID_BORROWED_REFS
466
+ Py_INCREF(key);
467
+ #endif
468
+
469
+ size_t index_found = 0;
470
+ int cmp = __Pyx_MatchKeywordArg(key, argnames, first_kw_arg, &index_found, function_name);
471
+ if (cmp != 1) {
472
+ if (cmp == 0) {
473
+ PyErr_Format(PyExc_TypeError,
474
+ "%s() got an unexpected keyword argument '%U'",
475
+ function_name, key);
476
+ }
477
+ #if CYTHON_AVOID_BORROWED_REFS
478
+ Py_DECREF(key);
479
+ #endif
480
+
481
+ break;
482
+ }
483
+ #if CYTHON_AVOID_BORROWED_REFS
484
+ Py_DECREF(key);
485
+ #endif
486
+ }
487
+ }
488
+ __Pyx_END_CRITICAL_SECTION();
489
+
490
+ assert(PyErr_Occurred());
491
+ }
492
+
493
+ static int __Pyx_ParseKeywordDict(
494
+ PyObject *kwds,
495
+ PyObject ** const argnames[],
496
+ PyObject *values[],
497
+ Py_ssize_t num_pos_args,
498
+ Py_ssize_t num_kwargs,
499
+ const char* function_name,
500
+ int ignore_unknown_kwargs)
501
+ {
502
+ PyObject** const *name;
503
+ PyObject** const *first_kw_arg = argnames + num_pos_args;
504
+ Py_ssize_t extracted = 0;
505
+
506
+ // Check if dict is unicode-keys-only and let Python set the error otherwise.
507
+ if (unlikely(!PyArg_ValidateKeywordArguments(kwds))) return -1;
508
+
509
+ // Extract declared keyword arguments.
510
+ name = first_kw_arg;
511
+ while (*name && num_kwargs > extracted) {
512
+ PyObject * key = **name;
513
+ PyObject *value;
514
+ int found = 0;
515
+
516
+ #if __PYX_LIMITED_VERSION_HEX >= 0x030d0000
517
+ found = PyDict_GetItemRef(kwds, key, &value);
518
+ #else
519
+ value = PyDict_GetItemWithError(kwds, key);
520
+ if (value) {
521
+ Py_INCREF(value);
522
+ found = 1;
523
+ } else {
524
+ if (unlikely(PyErr_Occurred())) goto bad;
525
+ }
526
+ #endif
527
+
528
+ if (found) {
529
+ if (unlikely(found < 0)) goto bad;
530
+ values[name-argnames] = value;
531
+ extracted++;
532
+ }
533
+
534
+ name++;
535
+ }
536
+
537
+ if (num_kwargs > extracted) {
538
+ if (ignore_unknown_kwargs) {
539
+ // Make sure the remaining kwargs are not duplicate posargs.
540
+ if (unlikely(__Pyx_ValidateDuplicatePosArgs(kwds, argnames, first_kw_arg, function_name) == -1))
541
+ goto bad;
542
+ } else {
543
+ // Any remaining kwarg is an error.
544
+ __Pyx_RejectUnknownKeyword(kwds, argnames, first_kw_arg, function_name);
545
+ goto bad;
546
+ }
547
+ }
548
+ return 0;
549
+
550
+ bad:
551
+ return -1;
552
+ }
553
+
554
+ static int __Pyx_ParseKeywordDictToDict(
555
+ PyObject *kwds,
556
+ PyObject ** const argnames[],
557
+ PyObject *kwds2,
558
+ PyObject *values[],
559
+ Py_ssize_t num_pos_args,
560
+ const char* function_name)
561
+ {
562
+ // Validate and parse keyword arguments from kwds dict.
563
+ PyObject** const *name;
564
+ PyObject** const *first_kw_arg = argnames + num_pos_args;
565
+ Py_ssize_t len;
566
+
567
+ // Check if dict is unicode-keys-only and let Python set the error otherwise.
568
+ if (unlikely(!PyArg_ValidateKeywordArguments(kwds))) return -1;
569
+
570
+ // Fast copy of all kwargs.
571
+ if (PyDict_Update(kwds2, kwds) < 0) goto bad;
572
+
573
+ // Extract declared keyword arguments (if any).
574
+ name = first_kw_arg;
575
+ while (*name) {
576
+ PyObject *key = **name;
577
+ PyObject *value;
578
+
579
+ #if !CYTHON_COMPILING_IN_LIMITED_API && (PY_VERSION_HEX >= 0x030d00A2 || defined(PyDict_Pop))
580
+ int found = PyDict_Pop(kwds2, key, &value);
581
+ if (found) {
582
+ if (unlikely(found < 0)) goto bad;
583
+ values[name-argnames] = value;
584
+ }
585
+ #elif __PYX_LIMITED_VERSION_HEX >= 0x030d0000
586
+ int found = PyDict_GetItemRef(kwds2, key, &value);
587
+ if (found) {
588
+ if (unlikely(found < 0)) goto bad;
589
+ values[name-argnames] = value;
590
+ if (unlikely(PyDict_DelItem(kwds2, key) < 0)) goto bad;
591
+ }
592
+ #else
593
+ // We use 'kwds2' as sentinel value to dict.pop() to avoid an exception on missing key.
594
+ #if CYTHON_COMPILING_IN_CPYTHON
595
+ value = _PyDict_Pop(kwds2, key, kwds2);
596
+ #else
597
+ value = CALL_UNBOUND_METHOD(PyDict_Type, "pop", kwds2, key, kwds2);
598
+ #endif
599
+ if (value == kwds2) {
600
+ // Not found.
601
+ Py_DECREF(value);
602
+ } else {
603
+ if (unlikely(!value)) goto bad;
604
+ values[name-argnames] = value;
605
+ }
606
+ #endif
607
+ name++;
608
+ }
609
+
610
+ // If unmatched keywords remain, check for duplicates of positional arguments.
611
+ len = PyDict_Size(kwds2);
612
+ if (len > 0) {
613
+ return __Pyx_ValidateDuplicatePosArgs(kwds, argnames, first_kw_arg, function_name);
614
+ } else if (unlikely(len == -1)) {
615
+ goto bad;
616
+ }
617
+
618
+ return 0;
619
+
620
+ bad:
621
+ return -1;
622
+ }
623
+
624
+ static int __Pyx_ParseKeywordsTuple(
625
+ PyObject *kwds,
626
+ PyObject * const *kwvalues,
627
+ PyObject ** const argnames[],
628
+ PyObject *kwds2,
629
+ PyObject *values[],
630
+ Py_ssize_t num_pos_args,
631
+ Py_ssize_t num_kwargs,
632
+ const char* function_name,
633
+ int ignore_unknown_kwargs)
634
+ {
635
+ PyObject *key = NULL;
636
+ PyObject** const * name;
637
+ PyObject** const *first_kw_arg = argnames + num_pos_args;
638
+
639
+ for (Py_ssize_t pos = 0; pos < num_kwargs; pos++) {
640
+ #if CYTHON_AVOID_BORROWED_REFS
641
+ key = __Pyx_PySequence_ITEM(kwds, pos);
642
+ #else
643
+ key = __Pyx_PyTuple_GET_ITEM(kwds, pos);
644
+ #endif
645
+ #if !CYTHON_ASSUME_SAFE_MACROS
646
+ if (unlikely(!key)) goto bad;
647
+ #endif
648
+
649
+ // Quick pointer search for interned parameter matches (will usually succeed).
650
+ name = first_kw_arg;
651
+ while (*name && (**name != key)) name++;
652
+ if (*name) {
653
+ // Declared keyword: **name == key
654
+ PyObject *value = kwvalues[pos];
655
+ values[name-argnames] = __Pyx_NewRef(value);
656
+ } else {
657
+ size_t index_found = 0;
658
+ int cmp = __Pyx_MatchKeywordArg(key, argnames, first_kw_arg, &index_found, function_name);
659
+
660
+ if (cmp == 1) {
661
+ // Found in declared keywords => assign value.
662
+ PyObject *value = kwvalues[pos];
663
+ values[index_found] = __Pyx_NewRef(value);
664
+ } else {
665
+ if (unlikely(cmp == -1)) goto bad;
666
+ if (kwds2) {
667
+ PyObject *value = kwvalues[pos];
668
+ if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
669
+ } else if (!ignore_unknown_kwargs) {
670
+ goto invalid_keyword;
671
+ }
672
+ }
673
+ }
674
+
675
+ #if CYTHON_AVOID_BORROWED_REFS
676
+ Py_DECREF(key);
677
+ key = NULL;
678
+ #endif
679
+ }
680
+ return 0;
681
+
682
+ invalid_keyword:
683
+ PyErr_Format(PyExc_TypeError,
684
+ "%s() got an unexpected keyword argument '%U'",
685
+ function_name, key);
686
+ goto bad;
687
+ bad:
688
+ #if CYTHON_AVOID_BORROWED_REFS
689
+ Py_XDECREF(key);
690
+ #endif
691
+ return -1;
692
+ }
693
+
694
+ static int __Pyx_ParseKeywords(
695
+ PyObject *kwds,
696
+ PyObject * const *kwvalues,
697
+ PyObject ** const argnames[],
698
+ PyObject *kwds2,
699
+ PyObject *values[],
700
+ Py_ssize_t num_pos_args,
701
+ Py_ssize_t num_kwargs,
702
+ const char* function_name,
703
+ int ignore_unknown_kwargs)
704
+ {
705
+ // Only called if kwds contains at least one optional keyword argument.
706
+ if (CYTHON_METH_FASTCALL && likely(PyTuple_Check(kwds)))
707
+ return __Pyx_ParseKeywordsTuple(kwds, kwvalues, argnames, kwds2, values, num_pos_args, num_kwargs, function_name, ignore_unknown_kwargs);
708
+ else if (kwds2)
709
+ return __Pyx_ParseKeywordDictToDict(kwds, argnames, kwds2, values, num_pos_args, function_name);
710
+ else
711
+ return __Pyx_ParseKeywordDict(kwds, argnames, values, num_pos_args, num_kwargs, function_name, ignore_unknown_kwargs);
712
+ }
713
+
714
+
715
+ //////////////////// MergeKeywords.proto ////////////////////
716
+
717
+ static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping); /*proto*/
718
+
719
+ //////////////////// MergeKeywords ////////////////////
720
+ //@requires: RaiseDoubleKeywords
721
+ //@requires: Optimize.c::dict_iter
722
+
723
+ static int __Pyx_MergeKeywords_dict(PyObject *kwdict, PyObject *source_dict) {
724
+ Py_ssize_t len1, len2;
725
+
726
+ len2 = PyDict_Size(source_dict);
727
+ if (unlikely(len2 == -1)) return -1;
728
+ if (len2 == 0) {
729
+ // There's nothing to copy from an empty dict.
730
+ return 0;
731
+ }
732
+
733
+ len1 = PyDict_Size(kwdict);
734
+ if (unlikely(len1 == -1)) return -1;
735
+
736
+ if (len1 > 0) {
737
+ PyObject *key, *smaller_dict, *larger_dict;
738
+ Py_ssize_t ppos = 0;
739
+ int duplicates_found = 0;
740
+
741
+ if (len1 <= len2) {
742
+ smaller_dict = kwdict;
743
+ larger_dict = source_dict;
744
+ } else {
745
+ smaller_dict = source_dict;
746
+ larger_dict = kwdict;
747
+ }
748
+
749
+ __Pyx_BEGIN_CRITICAL_SECTION(smaller_dict);
750
+ while (PyDict_Next(smaller_dict, &ppos, &key, NULL)) {
751
+ #if CYTHON_AVOID_BORROWED_REFS || CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS
752
+ Py_INCREF(key);
753
+ #endif
754
+ if (unlikely(PyDict_Contains(larger_dict, key))) {
755
+ __Pyx_RaiseDoubleKeywordsError("function", key);
756
+ #if CYTHON_AVOID_BORROWED_REFS || CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS
757
+ Py_DECREF(key);
758
+ #endif
759
+ duplicates_found = 1;
760
+ break;
761
+ };
762
+ #if CYTHON_AVOID_BORROWED_REFS || CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS
763
+ Py_DECREF(key);
764
+ #endif
765
+ }
766
+ __Pyx_END_CRITICAL_SECTION();
767
+
768
+ if (unlikely(duplicates_found))
769
+ return -1;
770
+ }
771
+
772
+ return PyDict_Update(kwdict, source_dict);
773
+ }
774
+
775
+ static int __Pyx_MergeKeywords_any(PyObject *kwdict, PyObject *source_mapping) {
776
+ PyObject *iter, *key = NULL, *value = NULL;
777
+ int source_is_dict, result;
778
+ Py_ssize_t orig_length, ppos = 0;
779
+
780
+ iter = __Pyx_dict_iterator(source_mapping, 0, PYIDENT("items"), &orig_length, &source_is_dict);
781
+ if (unlikely(!iter)) {
782
+ // slow fallback: try converting to dict, then iterate
783
+ PyObject *args;
784
+ if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError))) goto bad;
785
+ PyErr_Clear();
786
+ args = PyTuple_Pack(1, source_mapping);
787
+ if (likely(args)) {
788
+ PyObject *fallback = PyObject_Call((PyObject*)&PyDict_Type, args, NULL);
789
+ Py_DECREF(args);
790
+ if (likely(fallback)) {
791
+ result = __Pyx_MergeKeywords_dict(kwdict, fallback);
792
+ Py_DECREF(fallback);
793
+ return result;
794
+ }
795
+ }
796
+ if (unlikely(!iter)) goto bad;
797
+ }
798
+
799
+ while (1) {
800
+ result = __Pyx_dict_iter_next(iter, orig_length, &ppos, &key, &value, NULL, source_is_dict);
801
+ if (unlikely(result < 0)) goto bad;
802
+ if (!result) break;
803
+
804
+ #if PY_VERSION_HEX >= 0x030d0000 && !CYTHON_COMPILING_IN_LIMITED_API
805
+ {
806
+ int inserted = PyDict_SetDefaultRef(kwdict, key, value, NULL);
807
+ if (unlikely(inserted != 0)) {
808
+ if (inserted == 1) __Pyx_RaiseDoubleKeywordsError("function", key);
809
+ result = -1;
810
+ }
811
+ }
812
+ #else
813
+ if (unlikely(PyDict_Contains(kwdict, key))) {
814
+ __Pyx_RaiseDoubleKeywordsError("function", key);
815
+ result = -1;
816
+ } else {
817
+ result = PyDict_SetItem(kwdict, key, value);
818
+ }
819
+ #endif
820
+
821
+ Py_DECREF(key);
822
+ Py_DECREF(value);
823
+ if (unlikely(result < 0)) goto bad;
824
+ }
825
+ Py_XDECREF(iter);
826
+ return 0;
827
+
828
+ bad:
829
+ Py_XDECREF(iter);
830
+ return -1;
831
+ }
832
+
833
+ static CYTHON_INLINE int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping) {
834
+ assert(PyDict_Check(kwdict));
835
+ if (likely(PyDict_Check(source_mapping))) {
836
+ return __Pyx_MergeKeywords_dict(kwdict, source_mapping);
837
+ } else {
838
+ return __Pyx_MergeKeywords_any(kwdict, source_mapping);
839
+ }
840
+ }
841
+
842
+
843
+ /////////////// fastcall.proto ///////////////
844
+
845
+ // We define various functions and macros with two variants:
846
+ //..._FASTCALL and ..._VARARGS
847
+
848
+ // The first is used when METH_FASTCALL is enabled and the second is used
849
+ // otherwise. If the Python implementation does not support METH_FASTCALL
850
+ // (because it's an old version of CPython or it's not CPython at all),
851
+ // then the ..._FASTCALL macros simply alias ..._VARARGS
852
+
853
+ #if CYTHON_AVOID_BORROWED_REFS
854
+ #define __Pyx_ArgRef_VARARGS(args, i) __Pyx_PySequence_ITEM(args, i)
855
+ #elif CYTHON_ASSUME_SAFE_MACROS
856
+ #define __Pyx_ArgRef_VARARGS(args, i) __Pyx_NewRef(__Pyx_PyTuple_GET_ITEM(args, i))
857
+ #else
858
+ #define __Pyx_ArgRef_VARARGS(args, i) __Pyx_XNewRef(PyTuple_GetItem(args, i))
859
+ #endif
860
+
861
+ #define __Pyx_NumKwargs_VARARGS(kwds) PyDict_Size(kwds)
862
+ #define __Pyx_KwValues_VARARGS(args, nargs) NULL
863
+ #define __Pyx_GetKwValue_VARARGS(kw, kwvalues, s) __Pyx_PyDict_GetItemStrWithError(kw, s)
864
+ #define __Pyx_KwargsAsDict_VARARGS(kw, kwvalues) PyDict_Copy(kw)
865
+ #if CYTHON_METH_FASTCALL
866
+ #define __Pyx_ArgRef_FASTCALL(args, i) __Pyx_NewRef(args[i])
867
+ #define __Pyx_NumKwargs_FASTCALL(kwds) __Pyx_PyTuple_GET_SIZE(kwds)
868
+ #define __Pyx_KwValues_FASTCALL(args, nargs) ((args) + (nargs))
869
+ static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s);
870
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 || CYTHON_COMPILING_IN_LIMITED_API
871
+ CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues);/*proto*/
872
+ #else
873
+ #define __Pyx_KwargsAsDict_FASTCALL(kw, kwvalues) _PyStack_AsDict(kwvalues, kw)
874
+ #endif
875
+ #else
876
+ #define __Pyx_ArgRef_FASTCALL __Pyx_ArgRef_VARARGS
877
+ #define __Pyx_NumKwargs_FASTCALL __Pyx_NumKwargs_VARARGS
878
+ #define __Pyx_KwValues_FASTCALL __Pyx_KwValues_VARARGS
879
+ #define __Pyx_GetKwValue_FASTCALL __Pyx_GetKwValue_VARARGS
880
+ #define __Pyx_KwargsAsDict_FASTCALL __Pyx_KwargsAsDict_VARARGS
881
+ #endif
882
+
883
+ #define __Pyx_ArgsSlice_VARARGS(args, start, stop) PyTuple_GetSlice(args, start, stop)
884
+
885
+ #if CYTHON_METH_FASTCALL || (CYTHON_COMPILING_IN_CPYTHON && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS)
886
+ #define __Pyx_ArgsSlice_FASTCALL(args, start, stop) __Pyx_PyTuple_FromArray(args + start, stop - start)
887
+ #else
888
+ #define __Pyx_ArgsSlice_FASTCALL(args, start, stop) PyTuple_GetSlice(args, start, stop)
889
+ #endif
890
+
891
+ /////////////// fastcall ///////////////
892
+ //@requires: ObjectHandling.c::TupleAndListFromArray
893
+ //@requires: StringTools.c::UnicodeEquals
894
+
895
+ #if CYTHON_METH_FASTCALL
896
+ // kwnames: tuple with names of keyword arguments
897
+ // kwvalues: C array with values of keyword arguments
898
+ // s: str with the keyword name to look for
899
+ static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s)
900
+ {
901
+ // Search the kwnames array for s and return the corresponding value.
902
+ // We do two loops: a first one to compare pointers (which will find a
903
+ // match if the name in kwnames is interned, given that s is interned
904
+ // by Cython). A second loop compares the actual strings.
905
+ Py_ssize_t i, n = __Pyx_PyTuple_GET_SIZE(kwnames);
906
+ #if !CYTHON_ASSUME_SAFE_SIZE
907
+ if (unlikely(n == -1)) return NULL;
908
+ #endif
909
+ for (i = 0; i < n; i++)
910
+ {
911
+ PyObject *namei = __Pyx_PyTuple_GET_ITEM(kwnames, i);
912
+ #if !CYTHON_ASSUME_SAFE_MACROS
913
+ if (unlikely(!namei)) return NULL;
914
+ #endif
915
+ if (s == namei) return kwvalues[i];
916
+ }
917
+ for (i = 0; i < n; i++)
918
+ {
919
+ PyObject *namei = __Pyx_PyTuple_GET_ITEM(kwnames, i);
920
+ #if !CYTHON_ASSUME_SAFE_MACROS
921
+ if (unlikely(!namei)) return NULL;
922
+ #endif
923
+ int eq = __Pyx_PyUnicode_Equals(s, namei, Py_EQ);
924
+ if (unlikely(eq != 0)) {
925
+ if (unlikely(eq < 0)) return NULL; /* error */
926
+ return kwvalues[i];
927
+ }
928
+ }
929
+ return NULL; /* not found (no exception set) */
930
+ }
931
+
932
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 || CYTHON_COMPILING_IN_LIMITED_API
933
+ CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues) {
934
+ Py_ssize_t i, nkwargs;
935
+ PyObject *dict;
936
+ #if !CYTHON_ASSUME_SAFE_SIZE
937
+ nkwargs = PyTuple_Size(kwnames);
938
+ if (unlikely(nkwargs < 0)) return NULL;
939
+ #else
940
+ nkwargs = PyTuple_GET_SIZE(kwnames);
941
+ #endif
942
+
943
+ dict = PyDict_New();
944
+ if (unlikely(!dict))
945
+ return NULL;
946
+
947
+ for (i=0; i<nkwargs; i++) {
948
+ #if !CYTHON_ASSUME_SAFE_MACROS
949
+ PyObject *key = PyTuple_GetItem(kwnames, i);
950
+ if (!key) goto bad;
951
+ #else
952
+ PyObject *key = PyTuple_GET_ITEM(kwnames, i);
953
+ #endif
954
+ if (unlikely(PyDict_SetItem(dict, key, kwvalues[i]) < 0))
955
+ goto bad;
956
+ }
957
+ return dict;
958
+
959
+ bad:
960
+ Py_DECREF(dict);
961
+ return NULL;
962
+ }
963
+ #endif
964
+
965
+ #endif