Cython 3.2.6__py3-none-any.whl → 3.3.0a2.dev0__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.

Potentially problematic release.


This version of Cython might be problematic. Click here for more details.

Files changed (112) hide show
  1. Cython/Build/BuildExecutable.py +1 -14
  2. Cython/Build/Dependencies.py +6 -44
  3. Cython/Build/Inline.py +7 -3
  4. Cython/Build/IpythonMagic.py +0 -1
  5. Cython/Build/SharedModule.py +1 -2
  6. Cython/Build/Tests/TestCythonizeArgsParser.py +6 -6
  7. Cython/Build/Tests/TestDependencies.py +3 -3
  8. Cython/Build/Tests/TestInline.py +3 -3
  9. Cython/Build/Tests/TestIpythonMagic.py +35 -19
  10. Cython/Build/Tests/TestStripLiterals.py +2 -2
  11. Cython/Compiler/Buffer.py +5 -5
  12. Cython/Compiler/Builtin.py +57 -46
  13. Cython/Compiler/Code.pxd +12 -9
  14. Cython/Compiler/Code.py +220 -94
  15. Cython/Compiler/Dataclass.py +78 -52
  16. Cython/Compiler/Errors.py +21 -8
  17. Cython/Compiler/ExprNodes.py +871 -459
  18. Cython/Compiler/FlowControl.pxd +8 -6
  19. Cython/Compiler/FlowControl.py +111 -8
  20. Cython/Compiler/FusedNode.py +17 -12
  21. Cython/Compiler/Lexicon.py +123 -122
  22. Cython/Compiler/Main.py +3 -4
  23. Cython/Compiler/MatchCaseNodes.py +1948 -10
  24. Cython/Compiler/MemoryView.py +62 -33
  25. Cython/Compiler/ModuleNode.py +559 -283
  26. Cython/Compiler/Naming.py +4 -0
  27. Cython/Compiler/Nodes.py +333 -197
  28. Cython/Compiler/Optimize.py +268 -112
  29. Cython/Compiler/Options.py +0 -5
  30. Cython/Compiler/ParseTreeTransforms.pxd +2 -1
  31. Cython/Compiler/ParseTreeTransforms.py +180 -76
  32. Cython/Compiler/Parsing.py +55 -38
  33. Cython/Compiler/PyrexTypes.py +364 -128
  34. Cython/Compiler/Scanning.pxd +27 -5
  35. Cython/Compiler/Scanning.py +24 -14
  36. Cython/Compiler/StringEncoding.py +1 -2
  37. Cython/Compiler/Symtab.py +27 -19
  38. Cython/Compiler/Tests/TestBuiltin.py +41 -6
  39. Cython/Compiler/Tests/TestCmdLine.py +3 -2
  40. Cython/Compiler/Tests/TestCode.py +4 -3
  41. Cython/Compiler/Tests/TestFlowControl.py +2 -2
  42. Cython/Compiler/Tests/TestParseTreeTransforms.py +2 -2
  43. Cython/Compiler/Tests/TestScanning.py +2 -4
  44. Cython/Compiler/Tests/TestSignatureMatching.py +3 -3
  45. Cython/Compiler/Tests/TestStringEncoding.py +2 -3
  46. Cython/Compiler/Tests/TestTypes.py +46 -3
  47. Cython/Compiler/Tests/TestUtilityLoad.py +4 -4
  48. Cython/Compiler/TypeInference.py +20 -0
  49. Cython/Compiler/TypeSlots.py +171 -16
  50. Cython/Compiler/UtilNodes.py +24 -0
  51. Cython/Compiler/UtilityCode.py +1 -0
  52. Cython/Compiler/Visitor.pxd +1 -1
  53. Cython/Compiler/Visitor.py +3 -2
  54. Cython/Debugger/Tests/TestLibCython.py +7 -2
  55. Cython/Debugger/Tests/test_libcython_in_gdb.py +4 -2
  56. Cython/Debugger/Tests/test_libpython_in_gdb.py +1 -1
  57. Cython/Includes/cpython/array.pxd +5 -5
  58. Cython/Includes/cpython/dict.pxd +1 -6
  59. Cython/Includes/cpython/float.pxd +19 -10
  60. Cython/Includes/cpython/frozendict.pxd +37 -0
  61. Cython/Includes/cpython/long.pxd +31 -0
  62. Cython/Includes/cpython/object.pxd +9 -12
  63. Cython/Includes/cpython/sentinel.pxd +17 -0
  64. Cython/Includes/cpython/type.pxd +93 -0
  65. Cython/Includes/libcpp/exception.pxd +90 -0
  66. Cython/LZSS.py +170 -0
  67. Cython/Shadow.py +550 -73
  68. Cython/StringIOTree.py +1 -2
  69. Cython/Tempita/_tempita.py +45 -46
  70. Cython/TestUtils.py +50 -8
  71. Cython/Tests/TestCythonUtils.py +2 -2
  72. Cython/Tests/TestJediTyper.py +1 -1
  73. Cython/Tests/TestShadow.py +7 -5
  74. Cython/Tests/TestStringIOTree.py +4 -3
  75. Cython/Tests/TestTestUtils.py +2 -3
  76. Cython/Utility/AsyncGen.c +59 -19
  77. Cython/Utility/Buffer.c +4 -3
  78. Cython/Utility/Builtins.c +139 -17
  79. Cython/Utility/CConvert.pyx +27 -12
  80. Cython/Utility/CommonStructures.c +55 -37
  81. Cython/Utility/Coroutine.c +112 -68
  82. Cython/Utility/CythonFunction.c +607 -330
  83. Cython/Utility/Embed.c +8 -0
  84. Cython/Utility/Exceptions.c +20 -3
  85. Cython/Utility/ExtensionTypes.c +414 -224
  86. Cython/Utility/FunctionArguments.c +83 -81
  87. Cython/Utility/ImportExport.c +72 -61
  88. Cython/Utility/MatchCase.c +979 -0
  89. Cython/Utility/MatchCase_Cy.pyx +12 -0
  90. Cython/Utility/MemoryView.pxd +9 -88
  91. Cython/Utility/MemoryView.pyx +173 -61
  92. Cython/Utility/MemoryView_C.c +3 -3
  93. Cython/Utility/ModuleSetupCode.c +306 -157
  94. Cython/Utility/ObjectHandling.c +483 -404
  95. Cython/Utility/Optimize.c +1117 -164
  96. Cython/Utility/Overflow.c +3 -9
  97. Cython/Utility/Profile.c +4 -0
  98. Cython/Utility/StringTools.c +187 -149
  99. Cython/Utility/Synchronization.c +39 -0
  100. Cython/Utility/TString.c +24 -13
  101. Cython/Utility/TypeConversion.c +405 -250
  102. Cython/Utility/arrayarray.h +24 -22
  103. Cython/Utils.py +11 -23
  104. Cython/__init__.py +3 -1
  105. {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/METADATA +14 -33
  106. {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/RECORD +109 -107
  107. {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/WHEEL +1 -1
  108. Cython/Shadow.pyi +0 -521
  109. Cython/Utility/Printing.c +0 -86
  110. Cython/__init__.pyi +0 -7
  111. {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/entry_points.txt +0 -0
  112. {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/top_level.txt +0 -0
@@ -10,7 +10,7 @@ cython.declare(Nodes=object, ExprNodes=object, EncodedString=object,
10
10
  bytes_literal=object, StringEncoding=object,
11
11
  FileSourceDescriptor=object, lookup_unicodechar=object,
12
12
  Future=object, Options=object, error=object, warning=object,
13
- Builtin=object, ModuleNode=object, Utils=object, _unicode=object, _bytes=object,
13
+ Builtin=object, ModuleNode=object, _unicode=object, _bytes=object,
14
14
  re=object, _parse_escape_sequences=object, _parse_escape_sequences_raw=object,
15
15
  partial=object, reduce=object,
16
16
  _CDEF_MODIFIERS=tuple, COMMON_BINOP_MISTAKES=dict)
@@ -28,8 +28,7 @@ from . import Builtin
28
28
  from . import StringEncoding
29
29
  from .StringEncoding import EncodedString, bytes_literal
30
30
  from .ModuleNode import ModuleNode
31
- from .Errors import error, warning, CompileError
32
- from .. import Utils
31
+ from .Errors import error, warning
33
32
  from . import Future
34
33
  from . import Options
35
34
 
@@ -73,7 +72,7 @@ def p_ident(s: PyrexScanner, message="Expected an identifier"):
73
72
 
74
73
 
75
74
  @cython.cfunc
76
- def p_ident_list(s: PyrexScanner):
75
+ def p_ident_list(s: PyrexScanner) -> list:
77
76
  names = []
78
77
  while s.sy == 'IDENT':
79
78
  names.append(s.context.intern_ustring(s.systring))
@@ -397,7 +396,7 @@ def p_typecast(s: PyrexScanner):
397
396
  is_memslice = isinstance(base_type, Nodes.MemoryViewSliceTypeNode)
398
397
  is_other_unnamed_type = isinstance(base_type, (
399
398
  Nodes.TemplatedTypeNode,
400
- Nodes.CConstOrVolatileTypeNode,
399
+ Nodes.CQualifierTypeNode,
401
400
  Nodes.CTupleBaseTypeNode,
402
401
  ))
403
402
  if not (is_memslice or is_other_unnamed_type) and base_type.name is None:
@@ -560,7 +559,7 @@ def p_call_parse_args(s: PyrexScanner, allow_genexp: cython.bint = True) -> tupl
560
559
  while s.sy != ')':
561
560
  if s.sy == '*':
562
561
  if starstar_seen:
563
- s.error("Non-keyword arg following keyword arg", pos=s.position())
562
+ s.error("Non-keyword arg following keyword arg")
564
563
  s.next()
565
564
  positional_args.append(p_test(s))
566
565
  last_was_tuple_unpack = True
@@ -601,7 +600,7 @@ def p_call_parse_args(s: PyrexScanner, allow_genexp: cython.bint = True) -> tupl
601
600
 
602
601
 
603
602
  @cython.cfunc
604
- def p_call_build_packed_args(pos, positional_args, keyword_args) -> tuple:
603
+ def p_call_build_packed_args(pos, positional_args: list, keyword_args: list) -> tuple:
605
604
  keyword_dict = None
606
605
 
607
606
  subtuples = [
@@ -837,6 +836,7 @@ def p_atom_ident_constants(s: PyrexScanner):
837
836
  # s.sy == 'IDENT'
838
837
  pos = s.position()
839
838
  name = s.systring
839
+ result = None
840
840
  if name == "None":
841
841
  result = ExprNodes.NoneNode(pos)
842
842
  elif name == "True":
@@ -1198,7 +1198,7 @@ def p_ft_string_replacement_field(s: PyrexScanner,
1198
1198
  # validate the conversion char
1199
1199
  if conversion_char in ['}', ':', '']:
1200
1200
  error(s.position(), "missing conversion character")
1201
- elif not ExprNodes.FormattedValueNode.find_conversion_func(conversion_char):
1201
+ elif ExprNodes.FormattedValueNode.find_conversion_func(conversion_char) is None:
1202
1202
  error(s.position(), "invalid conversion character '%s'" % conversion_char)
1203
1203
  s.next()
1204
1204
  elif s.position()[2] != (previous_pos[2] + 1):
@@ -2317,7 +2317,7 @@ def p_with_items(s: PyrexScanner, is_async: cython.bint = False):
2317
2317
 
2318
2318
 
2319
2319
  @cython.cfunc
2320
- def p_with_items_list(s: PyrexScanner, is_async: cython.bint) -> list:
2320
+ def p_with_items_list(s: PyrexScanner, is_async: cython.bint) -> list[tuple]:
2321
2321
  items = []
2322
2322
  while True:
2323
2323
  items.append(p_with_item(s, is_async))
@@ -2818,10 +2818,10 @@ def p_c_simple_base_type(s: PyrexScanner, nonempty: cython.bint, templates=None)
2818
2818
  base_type = p_c_base_type(s, nonempty=nonempty, templates=templates)
2819
2819
  if isinstance(base_type, Nodes.MemoryViewSliceTypeNode):
2820
2820
  # reverse order to avoid having to write "(const int)[:]"
2821
- base_type.base_type_node = Nodes.CConstOrVolatileTypeNode(pos,
2821
+ base_type.base_type_node = Nodes.CQualifierTypeNode(pos,
2822
2822
  base_type=base_type.base_type_node, is_const=is_const, is_volatile=is_volatile)
2823
2823
  return base_type
2824
- return Nodes.CConstOrVolatileTypeNode(pos,
2824
+ return Nodes.CQualifierTypeNode(pos,
2825
2825
  base_type=base_type, is_const=is_const, is_volatile=is_volatile)
2826
2826
 
2827
2827
  if s.sy != 'IDENT':
@@ -3180,15 +3180,23 @@ def p_c_simple_declarator(s: PyrexScanner, ctx,
3180
3180
  s.next()
3181
3181
 
3182
3182
  const_pos = s.position()
3183
- is_const = s.systring == 'const' and s.sy == 'IDENT'
3184
- if is_const:
3183
+ is_restrict = is_const = False
3184
+ while s.sy == 'IDENT':
3185
+ if s.systring == 'const':
3186
+ if is_const: error(pos, "Duplicate 'const'")
3187
+ is_const = True
3188
+ elif s.systring == 'restrict':
3189
+ if is_restrict: error(pos, "Duplicate 'restrict'")
3190
+ is_restrict = True
3191
+ else:
3192
+ break
3185
3193
  s.next()
3186
3194
 
3187
3195
  base = p_c_declarator(s, ctx, empty=empty, is_type=is_type,
3188
3196
  cmethod_flag=cmethod_flag,
3189
3197
  assignable=assignable, nonempty=nonempty)
3190
- if is_const:
3191
- base = Nodes.CConstDeclaratorNode(const_pos, base=base)
3198
+ if is_const or is_restrict:
3199
+ base = Nodes.CQualifierDeclaratorNode(const_pos, base=base, is_const=is_const, is_restrict=is_restrict)
3192
3200
  if is_ptrptr:
3193
3201
  base = Nodes.CPtrDeclaratorNode(pos, base=base)
3194
3202
  result = Nodes.CPtrDeclaratorNode(pos, base=base)
@@ -4017,7 +4025,7 @@ def p_c_class_definition(s: PyrexScanner, pos, ctx):
4017
4025
  visibility = ctx.visibility,
4018
4026
  typedef_flag = ctx.typedef_flag,
4019
4027
  api = ctx.api,
4020
- module_name = ".".join(module_path),
4028
+ module_name = EncodedString(".".join(module_path)),
4021
4029
  class_name = class_name,
4022
4030
  as_name = as_name,
4023
4031
  bases = bases,
@@ -4454,8 +4462,8 @@ def p_closed_pattern(s: PyrexScanner):
4454
4462
  | class_pattern
4455
4463
 
4456
4464
  For the sake avoiding too much backtracking, we know:
4457
- * starts with "{" is a sequence_pattern
4458
- * starts with "[" is a mapping_pattern
4465
+ * starts with "{" is a mapping_pattern
4466
+ * starts with "[" is a sequence_pattern
4459
4467
  * starts with "(" is a group_pattern or sequence_pattern
4460
4468
  * wildcard pattern is just identifier=='_'
4461
4469
  The rest are then tried in order with backtracking
@@ -4500,6 +4508,9 @@ def p_literal_pattern(s: PyrexScanner):
4500
4508
  sign_pos = s.position()
4501
4509
  s.next()
4502
4510
  next_must_be_a_number = True
4511
+ elif s.sy == '+':
4512
+ s.next()
4513
+ next_must_be_a_number = True
4503
4514
 
4504
4515
  sy = s.sy
4505
4516
  pos = s.position()
@@ -4518,6 +4529,8 @@ def p_literal_pattern(s: PyrexScanner):
4518
4529
  if res is not None and s.sy in ['+', '-']:
4519
4530
  sign = s.sy
4520
4531
  s.next()
4532
+ if s.sy == '+':
4533
+ s.next()
4521
4534
  if s.sy != 'IMAG':
4522
4535
  s.error("Expected imaginary number")
4523
4536
  else:
@@ -4535,8 +4548,6 @@ def p_literal_pattern(s: PyrexScanner):
4535
4548
  value = s.systring[:-1]
4536
4549
  s.next()
4537
4550
  res = ExprNodes.ImagNode(pos, value=sign+value)
4538
- if sign == "-":
4539
- res = ExprNodes.UnaryMinusNode(sign_pos, operand=res)
4540
4551
 
4541
4552
  if res is not None:
4542
4553
  return MatchCaseNodes.MatchValuePatternNode(pos, value=res)
@@ -4594,25 +4605,21 @@ def p_group_pattern(s: PyrexScanner):
4594
4605
 
4595
4606
  @cython.cfunc
4596
4607
  def p_sequence_pattern(s: PyrexScanner):
4597
- opener = s.sy
4598
4608
  pos = s.position()
4599
- if opener in ['[', '(']:
4600
- closer = ']' if opener == '[' else ')'
4601
- s.next()
4602
- # maybe_sequence_pattern and open_sequence_pattern
4603
- patterns = []
4604
- while s.sy != closer:
4605
- patterns.append(p_maybe_star_pattern(s))
4606
- if s.sy == ",":
4607
- s.next()
4608
- else:
4609
- if opener == '(' and len(patterns) == 1:
4610
- s.error("tuple-like pattern of length 1 must finish with ','")
4611
- break
4612
- s.expect(closer)
4613
- return MatchCaseNodes.MatchSequencePatternNode(pos, patterns=patterns)
4614
- else:
4615
- s.error("Expected '[' or '('")
4609
+ assert s.sy in ('(', '[')
4610
+ closer = ')' if s.sy == '(' else ']'
4611
+ s.next()
4612
+ # maybe_sequence_pattern and open_sequence_pattern
4613
+ patterns = []
4614
+ while s.sy != closer:
4615
+ patterns.append(p_maybe_star_pattern(s))
4616
+ if s.sy != ",":
4617
+ if closer == ')' and len(patterns) == 1:
4618
+ s.error("tuple-like pattern of length 1 must finish with ','")
4619
+ break
4620
+ s.next()
4621
+ s.expect(closer)
4622
+ return MatchCaseNodes.MatchSequencePatternNode(pos, patterns=patterns)
4616
4623
 
4617
4624
 
4618
4625
  @cython.cfunc
@@ -4626,12 +4633,16 @@ def p_mapping_pattern(s: PyrexScanner):
4626
4633
 
4627
4634
  double_star_capture_target = None
4628
4635
  items_patterns = []
4636
+ double_star_set_twice_pos = None
4637
+ pattern_after_double_star_pos = None
4629
4638
  star_star_arg_pos = None
4630
4639
  while s.sy != '}':
4631
4640
  if double_star_capture_target and not star_star_arg_pos:
4632
4641
  star_star_arg_pos = s.position()
4633
4642
  if s.sy == '**':
4634
4643
  s.next()
4644
+ if double_star_capture_target:
4645
+ double_star_set_twice_pos = s.position()
4635
4646
  double_star_capture_target = p_pattern_capture_target(s)
4636
4647
  else:
4637
4648
  # key=(literal_expr | attr)
@@ -4644,10 +4655,16 @@ def p_mapping_pattern(s: PyrexScanner):
4644
4655
  s.expect(':')
4645
4656
  value = p_pattern(s)
4646
4657
  items_patterns.append((key, value))
4658
+ if double_star_capture_target:
4659
+ pattern_after_double_star_pos = value.pos
4647
4660
  if s.sy != ',':
4648
4661
  break
4649
4662
  s.next()
4650
4663
  s.expect('}')
4664
+ if double_star_set_twice_pos is not None:
4665
+ return Nodes.ErrorNode(double_star_set_twice_pos, what = "Double star capture set twice")
4666
+ if pattern_after_double_star_pos is not None:
4667
+ return Nodes.ErrorNode(pattern_after_double_star_pos, what = "pattern follows ** capture")
4651
4668
 
4652
4669
  if star_star_arg_pos is not None:
4653
4670
  return Nodes.ErrorNode(