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.
- Cython/Build/BuildExecutable.py +1 -14
- Cython/Build/Dependencies.py +6 -44
- Cython/Build/Inline.py +7 -3
- Cython/Build/IpythonMagic.py +0 -1
- Cython/Build/SharedModule.py +1 -2
- Cython/Build/Tests/TestCythonizeArgsParser.py +6 -6
- Cython/Build/Tests/TestDependencies.py +3 -3
- Cython/Build/Tests/TestInline.py +3 -3
- Cython/Build/Tests/TestIpythonMagic.py +35 -19
- Cython/Build/Tests/TestStripLiterals.py +2 -2
- Cython/Compiler/Buffer.py +5 -5
- Cython/Compiler/Builtin.py +57 -46
- Cython/Compiler/Code.pxd +12 -9
- Cython/Compiler/Code.py +220 -94
- Cython/Compiler/Dataclass.py +78 -52
- Cython/Compiler/Errors.py +21 -8
- Cython/Compiler/ExprNodes.py +871 -459
- Cython/Compiler/FlowControl.pxd +8 -6
- Cython/Compiler/FlowControl.py +111 -8
- Cython/Compiler/FusedNode.py +17 -12
- Cython/Compiler/Lexicon.py +123 -122
- Cython/Compiler/Main.py +3 -4
- Cython/Compiler/MatchCaseNodes.py +1948 -10
- Cython/Compiler/MemoryView.py +62 -33
- Cython/Compiler/ModuleNode.py +559 -283
- Cython/Compiler/Naming.py +4 -0
- Cython/Compiler/Nodes.py +333 -197
- Cython/Compiler/Optimize.py +268 -112
- Cython/Compiler/Options.py +0 -5
- Cython/Compiler/ParseTreeTransforms.pxd +2 -1
- Cython/Compiler/ParseTreeTransforms.py +180 -76
- Cython/Compiler/Parsing.py +55 -38
- Cython/Compiler/PyrexTypes.py +364 -128
- Cython/Compiler/Scanning.pxd +27 -5
- Cython/Compiler/Scanning.py +24 -14
- Cython/Compiler/StringEncoding.py +1 -2
- Cython/Compiler/Symtab.py +27 -19
- Cython/Compiler/Tests/TestBuiltin.py +41 -6
- Cython/Compiler/Tests/TestCmdLine.py +3 -2
- Cython/Compiler/Tests/TestCode.py +4 -3
- Cython/Compiler/Tests/TestFlowControl.py +2 -2
- Cython/Compiler/Tests/TestParseTreeTransforms.py +2 -2
- Cython/Compiler/Tests/TestScanning.py +2 -4
- Cython/Compiler/Tests/TestSignatureMatching.py +3 -3
- Cython/Compiler/Tests/TestStringEncoding.py +2 -3
- Cython/Compiler/Tests/TestTypes.py +46 -3
- Cython/Compiler/Tests/TestUtilityLoad.py +4 -4
- Cython/Compiler/TypeInference.py +20 -0
- Cython/Compiler/TypeSlots.py +171 -16
- Cython/Compiler/UtilNodes.py +24 -0
- Cython/Compiler/UtilityCode.py +1 -0
- Cython/Compiler/Visitor.pxd +1 -1
- Cython/Compiler/Visitor.py +3 -2
- Cython/Debugger/Tests/TestLibCython.py +7 -2
- Cython/Debugger/Tests/test_libcython_in_gdb.py +4 -2
- Cython/Debugger/Tests/test_libpython_in_gdb.py +1 -1
- Cython/Includes/cpython/array.pxd +5 -5
- Cython/Includes/cpython/dict.pxd +1 -6
- Cython/Includes/cpython/float.pxd +19 -10
- Cython/Includes/cpython/frozendict.pxd +37 -0
- Cython/Includes/cpython/long.pxd +31 -0
- Cython/Includes/cpython/object.pxd +9 -12
- Cython/Includes/cpython/sentinel.pxd +17 -0
- Cython/Includes/cpython/type.pxd +93 -0
- Cython/Includes/libcpp/exception.pxd +90 -0
- Cython/LZSS.py +170 -0
- Cython/Shadow.py +550 -73
- Cython/StringIOTree.py +1 -2
- Cython/Tempita/_tempita.py +45 -46
- Cython/TestUtils.py +50 -8
- Cython/Tests/TestCythonUtils.py +2 -2
- Cython/Tests/TestJediTyper.py +1 -1
- Cython/Tests/TestShadow.py +7 -5
- Cython/Tests/TestStringIOTree.py +4 -3
- Cython/Tests/TestTestUtils.py +2 -3
- Cython/Utility/AsyncGen.c +59 -19
- Cython/Utility/Buffer.c +4 -3
- Cython/Utility/Builtins.c +139 -17
- Cython/Utility/CConvert.pyx +27 -12
- Cython/Utility/CommonStructures.c +55 -37
- Cython/Utility/Coroutine.c +112 -68
- Cython/Utility/CythonFunction.c +607 -330
- Cython/Utility/Embed.c +8 -0
- Cython/Utility/Exceptions.c +20 -3
- Cython/Utility/ExtensionTypes.c +414 -224
- Cython/Utility/FunctionArguments.c +83 -81
- Cython/Utility/ImportExport.c +72 -61
- Cython/Utility/MatchCase.c +979 -0
- Cython/Utility/MatchCase_Cy.pyx +12 -0
- Cython/Utility/MemoryView.pxd +9 -88
- Cython/Utility/MemoryView.pyx +173 -61
- Cython/Utility/MemoryView_C.c +3 -3
- Cython/Utility/ModuleSetupCode.c +306 -157
- Cython/Utility/ObjectHandling.c +483 -404
- Cython/Utility/Optimize.c +1117 -164
- Cython/Utility/Overflow.c +3 -9
- Cython/Utility/Profile.c +4 -0
- Cython/Utility/StringTools.c +187 -149
- Cython/Utility/Synchronization.c +39 -0
- Cython/Utility/TString.c +24 -13
- Cython/Utility/TypeConversion.c +405 -250
- Cython/Utility/arrayarray.h +24 -22
- Cython/Utils.py +11 -23
- Cython/__init__.py +3 -1
- {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/METADATA +14 -33
- {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/RECORD +109 -107
- {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/WHEEL +1 -1
- Cython/Shadow.pyi +0 -521
- Cython/Utility/Printing.c +0 -86
- Cython/__init__.pyi +0 -7
- {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/entry_points.txt +0 -0
- {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/top_level.txt +0 -0
Cython/StringIOTree.py
CHANGED
Cython/Tempita/_tempita.py
CHANGED
|
@@ -29,6 +29,7 @@ can use ``__name='tmpl.html'`` to set the name of the template.
|
|
|
29
29
|
If there are syntax errors ``TemplateError`` will be raised.
|
|
30
30
|
"""
|
|
31
31
|
|
|
32
|
+
import cython
|
|
32
33
|
|
|
33
34
|
import re
|
|
34
35
|
import sys
|
|
@@ -150,6 +151,7 @@ class Template:
|
|
|
150
151
|
if default_inherit is not None:
|
|
151
152
|
self.default_inherit = default_inherit
|
|
152
153
|
|
|
154
|
+
@classmethod
|
|
153
155
|
def from_filename(cls, filename, namespace=None, encoding=None,
|
|
154
156
|
default_inherit=None, get_template=get_file_template):
|
|
155
157
|
with open(filename, 'rb') as f:
|
|
@@ -159,8 +161,6 @@ class Template:
|
|
|
159
161
|
return cls(content=c, name=filename, namespace=namespace,
|
|
160
162
|
default_inherit=default_inherit, get_template=get_template)
|
|
161
163
|
|
|
162
|
-
from_filename = classmethod(from_filename)
|
|
163
|
-
|
|
164
164
|
def __repr__(self):
|
|
165
165
|
return '<%s %s name=%r>' % (
|
|
166
166
|
self.__class__.__name__,
|
|
@@ -190,7 +190,7 @@ class Template:
|
|
|
190
190
|
result = self._interpret_inherit(result, defs, inherit, ns)
|
|
191
191
|
return result
|
|
192
192
|
|
|
193
|
-
def _interpret(self, ns):
|
|
193
|
+
def _interpret(self, ns) -> tuple:
|
|
194
194
|
__traceback_hide__ = True
|
|
195
195
|
parts = []
|
|
196
196
|
defs = {}
|
|
@@ -546,7 +546,7 @@ del _Empty
|
|
|
546
546
|
############################################################
|
|
547
547
|
|
|
548
548
|
|
|
549
|
-
def lex(s, name=None, trim_whitespace=True, line_offset=0, delimiters=None):
|
|
549
|
+
def lex(s, name=None, trim_whitespace=True, line_offset=0, delimiters=None) -> list:
|
|
550
550
|
"""
|
|
551
551
|
Lex a string into chunks:
|
|
552
552
|
|
|
@@ -568,45 +568,41 @@ def lex(s, name=None, trim_whitespace=True, line_offset=0, delimiters=None):
|
|
|
568
568
|
TemplateError: {{ inside expression at line 1 column 10
|
|
569
569
|
|
|
570
570
|
"""
|
|
571
|
-
if delimiters is None
|
|
572
|
-
|
|
573
|
-
|
|
571
|
+
start_braces: str = delimiters[0] if delimiters is not None else Template.default_namespace['start_braces']
|
|
572
|
+
end_braces: str = delimiters[1] if delimiters is not None else Template.default_namespace['end_braces']
|
|
573
|
+
|
|
574
574
|
in_expr = False
|
|
575
575
|
chunks = []
|
|
576
576
|
last = 0
|
|
577
577
|
last_pos = (line_offset + 1, 1)
|
|
578
578
|
|
|
579
|
-
token_re = re.compile(r'%s|%s' % (re.escape(
|
|
580
|
-
re.escape(
|
|
579
|
+
token_re = re.compile(r'%s|%s' % (re.escape(start_braces),
|
|
580
|
+
re.escape(end_braces)))
|
|
581
581
|
for match in token_re.finditer(s):
|
|
582
|
-
expr = match.group(0)
|
|
582
|
+
expr: str = match.group(0)
|
|
583
583
|
pos = find_position(s, match.end(), last, last_pos)
|
|
584
|
-
if expr ==
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
name=name)
|
|
588
|
-
elif expr == delimiters[1] and not in_expr:
|
|
589
|
-
raise TemplateError('%s outside expression' % delimiters[1],
|
|
590
|
-
position=pos,
|
|
591
|
-
name=name)
|
|
592
|
-
if expr == delimiters[0]:
|
|
584
|
+
if expr == start_braces:
|
|
585
|
+
if in_expr:
|
|
586
|
+
raise TemplateError(f'{start_braces} inside expression', position=pos, name=name)
|
|
593
587
|
part = s[last:match.start()]
|
|
594
588
|
if part:
|
|
595
589
|
chunks.append(part)
|
|
596
590
|
in_expr = True
|
|
597
591
|
else:
|
|
592
|
+
if not in_expr:
|
|
593
|
+
raise TemplateError(f'{end_braces} outside expression', position=pos, name=name)
|
|
598
594
|
chunks.append((s[last:match.start()], last_pos))
|
|
599
595
|
in_expr = False
|
|
600
596
|
last = match.end()
|
|
601
597
|
last_pos = pos
|
|
602
598
|
if in_expr:
|
|
603
|
-
raise TemplateError(
|
|
604
|
-
|
|
599
|
+
raise TemplateError(
|
|
600
|
+
f'No {end_braces} to finish last expression', name=name, position=last_pos)
|
|
605
601
|
part = s[last:]
|
|
606
602
|
if part:
|
|
607
603
|
chunks.append(part)
|
|
608
604
|
if trim_whitespace:
|
|
609
|
-
|
|
605
|
+
trim_lex(chunks)
|
|
610
606
|
return chunks
|
|
611
607
|
|
|
612
608
|
statement_re = re.compile(r'^(?:if |elif |for |def |inherit |default |py:)')
|
|
@@ -615,7 +611,7 @@ trail_whitespace_re = re.compile(r'\n\r?[\t ]*$')
|
|
|
615
611
|
lead_whitespace_re = re.compile(r'^[\t ]*\n')
|
|
616
612
|
|
|
617
613
|
|
|
618
|
-
def trim_lex(tokens):
|
|
614
|
+
def trim_lex(tokens: list):
|
|
619
615
|
r"""
|
|
620
616
|
Takes a lexed set of tokens, and removes whitespace when there is
|
|
621
617
|
a directive on a line by itself:
|
|
@@ -624,8 +620,10 @@ def trim_lex(tokens):
|
|
|
624
620
|
>>> tokens
|
|
625
621
|
[('if x', (1, 3)), '\nx\n', ('endif', (3, 3)), '\ny']
|
|
626
622
|
>>> trim_lex(tokens)
|
|
623
|
+
>>> tokens
|
|
627
624
|
[('if x', (1, 3)), 'x\n', ('endif', (3, 3)), 'y']
|
|
628
625
|
"""
|
|
626
|
+
i: cython.Py_ssize_t
|
|
629
627
|
last_trim = None
|
|
630
628
|
for i, current in enumerate(tokens):
|
|
631
629
|
if isinstance(current, str):
|
|
@@ -670,10 +668,9 @@ def trim_lex(tokens):
|
|
|
670
668
|
m = lead_whitespace_re.search(next_chunk)
|
|
671
669
|
next_chunk = next_chunk[m.end():]
|
|
672
670
|
tokens[i + 1] = next_chunk
|
|
673
|
-
return tokens
|
|
674
671
|
|
|
675
672
|
|
|
676
|
-
def find_position(string, index, last_index, last_pos):
|
|
673
|
+
def find_position(string: str, index, last_index, last_pos) -> tuple:
|
|
677
674
|
"""Given a string and index, return (line, column)"""
|
|
678
675
|
lines = string.count('\n', last_index, index)
|
|
679
676
|
if lines > 0:
|
|
@@ -733,9 +730,6 @@ def parse(s, name=None, line_offset=0, delimiters=None):
|
|
|
733
730
|
...
|
|
734
731
|
TemplateError: Multi-line py blocks must start with a newline at line 1 column 3
|
|
735
732
|
"""
|
|
736
|
-
if delimiters is None:
|
|
737
|
-
delimiters = ( Template.default_namespace['start_braces'],
|
|
738
|
-
Template.default_namespace['end_braces'] )
|
|
739
733
|
tokens = lex(s, name=name, line_offset=line_offset, delimiters=delimiters)
|
|
740
734
|
result = []
|
|
741
735
|
while tokens:
|
|
@@ -744,9 +738,10 @@ def parse(s, name=None, line_offset=0, delimiters=None):
|
|
|
744
738
|
return result
|
|
745
739
|
|
|
746
740
|
|
|
747
|
-
def parse_expr(tokens, name, context=()):
|
|
741
|
+
def parse_expr(tokens: list, name, context=()) -> tuple:
|
|
748
742
|
if isinstance(tokens[0], str):
|
|
749
743
|
return tokens[0], tokens[1:]
|
|
744
|
+
expr: str
|
|
750
745
|
expr, pos = tokens[0]
|
|
751
746
|
expr = expr.strip()
|
|
752
747
|
if expr.startswith('py:'):
|
|
@@ -797,7 +792,7 @@ def parse_expr(tokens, name, context=()):
|
|
|
797
792
|
return ('expr', pos, tokens[0][0]), tokens[1:]
|
|
798
793
|
|
|
799
794
|
|
|
800
|
-
def parse_cond(tokens, name, context):
|
|
795
|
+
def parse_cond(tokens: list, name, context) -> tuple:
|
|
801
796
|
start = tokens[0][1]
|
|
802
797
|
pieces = []
|
|
803
798
|
context = context + ('if',)
|
|
@@ -813,7 +808,8 @@ def parse_cond(tokens, name, context):
|
|
|
813
808
|
pieces.append(next_chunk)
|
|
814
809
|
|
|
815
810
|
|
|
816
|
-
def parse_one_cond(tokens, name, context):
|
|
811
|
+
def parse_one_cond(tokens: list, name, context) -> tuple:
|
|
812
|
+
first: str
|
|
817
813
|
(first, pos), tokens = tokens[0], tokens[1:]
|
|
818
814
|
content = []
|
|
819
815
|
if first.endswith(':'):
|
|
@@ -840,7 +836,8 @@ def parse_one_cond(tokens, name, context):
|
|
|
840
836
|
content.append(next_chunk)
|
|
841
837
|
|
|
842
838
|
|
|
843
|
-
def parse_for(tokens, name, context):
|
|
839
|
+
def parse_for(tokens: list, name, context) -> tuple:
|
|
840
|
+
first: str
|
|
844
841
|
first, pos = tokens[0]
|
|
845
842
|
tokens = tokens[1:]
|
|
846
843
|
context = ('for',) + context
|
|
@@ -854,14 +851,11 @@ def parse_for(tokens, name, context):
|
|
|
854
851
|
raise TemplateError(
|
|
855
852
|
'Bad for (no "in") in %r' % first,
|
|
856
853
|
position=pos, name=name)
|
|
857
|
-
|
|
858
|
-
if '(' in
|
|
854
|
+
vars_part: str = first[:match.start()]
|
|
855
|
+
if '(' in vars_part:
|
|
859
856
|
raise TemplateError(
|
|
860
|
-
'You cannot have () in the variable section of a for loop (
|
|
861
|
-
|
|
862
|
-
vars = tuple([
|
|
863
|
-
v.strip() for v in first[:match.start()].split(',')
|
|
864
|
-
if v.strip()])
|
|
857
|
+
f'You cannot have () in the variable section of a for loop ({vars_part!r})', position=pos, name=name)
|
|
858
|
+
vars = tuple([v.strip() for v in vars_part.split(',') if v.strip()])
|
|
865
859
|
expr = first[match.end():]
|
|
866
860
|
while 1:
|
|
867
861
|
if not tokens:
|
|
@@ -875,7 +869,8 @@ def parse_for(tokens, name, context):
|
|
|
875
869
|
content.append(next_chunk)
|
|
876
870
|
|
|
877
871
|
|
|
878
|
-
def parse_default(tokens, name, context):
|
|
872
|
+
def parse_default(tokens: list, name, context) -> tuple:
|
|
873
|
+
first: str
|
|
879
874
|
first, pos = tokens[0]
|
|
880
875
|
assert first.startswith('default ')
|
|
881
876
|
first = first.split(None, 1)[1]
|
|
@@ -884,7 +879,7 @@ def parse_default(tokens, name, context):
|
|
|
884
879
|
raise TemplateError(
|
|
885
880
|
"Expression must be {{default var=value}}; no = found in %r" % first,
|
|
886
881
|
position=pos, name=name)
|
|
887
|
-
var = parts[0].strip()
|
|
882
|
+
var: str = parts[0].strip()
|
|
888
883
|
if ',' in var:
|
|
889
884
|
raise TemplateError(
|
|
890
885
|
"{{default x, y = ...}} is not supported",
|
|
@@ -897,14 +892,16 @@ def parse_default(tokens, name, context):
|
|
|
897
892
|
return ('default', pos, var, expr), tokens[1:]
|
|
898
893
|
|
|
899
894
|
|
|
900
|
-
def parse_inherit(tokens, name, context):
|
|
895
|
+
def parse_inherit(tokens: list, name, context) -> tuple:
|
|
896
|
+
first: str
|
|
901
897
|
first, pos = tokens[0]
|
|
902
898
|
assert first.startswith('inherit ')
|
|
903
899
|
expr = first.split(None, 1)[1]
|
|
904
900
|
return ('inherit', pos, expr), tokens[1:]
|
|
905
901
|
|
|
906
902
|
|
|
907
|
-
def parse_def(tokens, name, context):
|
|
903
|
+
def parse_def(tokens: list, name, context) -> tuple:
|
|
904
|
+
first: str
|
|
908
905
|
first, start = tokens[0]
|
|
909
906
|
tokens = tokens[1:]
|
|
910
907
|
assert first.startswith('def ')
|
|
@@ -935,14 +932,14 @@ def parse_def(tokens, name, context):
|
|
|
935
932
|
content.append(next_chunk)
|
|
936
933
|
|
|
937
934
|
|
|
938
|
-
def parse_signature(sig_text, name, pos):
|
|
935
|
+
def parse_signature(sig_text: str, name, pos) -> tuple:
|
|
939
936
|
tokens = tokenize.generate_tokens(StringIO(sig_text).readline)
|
|
940
937
|
sig_args = []
|
|
941
938
|
var_arg = None
|
|
942
939
|
var_kw = None
|
|
943
940
|
defaults = {}
|
|
944
941
|
|
|
945
|
-
def get_token(pos=False):
|
|
942
|
+
def get_token(pos=False) -> tuple:
|
|
946
943
|
try:
|
|
947
944
|
tok_type, tok_string, (srow, scol), (erow, ecol), line = next(tokens)
|
|
948
945
|
except StopIteration:
|
|
@@ -953,6 +950,8 @@ def parse_signature(sig_text, name, pos):
|
|
|
953
950
|
return tok_type, tok_string
|
|
954
951
|
while 1:
|
|
955
952
|
var_arg_type = None
|
|
953
|
+
tok_type: int
|
|
954
|
+
tok_string: str
|
|
956
955
|
tok_type, tok_string = get_token()
|
|
957
956
|
if tok_type == tokenize.ENDMARKER:
|
|
958
957
|
break
|
|
@@ -1011,7 +1010,7 @@ def parse_signature(sig_text, name, pos):
|
|
|
1011
1010
|
return sig_args, var_arg, var_kw, defaults
|
|
1012
1011
|
|
|
1013
1012
|
|
|
1014
|
-
def isolate_expression(string, start_pos, end_pos):
|
|
1013
|
+
def isolate_expression(string: str, start_pos, end_pos) -> str:
|
|
1015
1014
|
srow, scol = start_pos
|
|
1016
1015
|
srow -= 1
|
|
1017
1016
|
erow, ecol = end_pos
|
Cython/TestUtils.py
CHANGED
|
@@ -5,13 +5,14 @@ import shlex
|
|
|
5
5
|
import sys
|
|
6
6
|
import tempfile
|
|
7
7
|
import textwrap
|
|
8
|
+
import time
|
|
8
9
|
from functools import partial
|
|
9
10
|
|
|
10
11
|
from .Compiler import Errors
|
|
11
12
|
from .CodeWriter import CodeWriter
|
|
12
13
|
from .Compiler.TreeFragment import TreeFragment, strip_common_indent, StringParseContext
|
|
13
14
|
from .Compiler.Visitor import TreeVisitor, VisitorTransform
|
|
14
|
-
from .Compiler import TreePath
|
|
15
|
+
from .Compiler import Nodes, TreePath
|
|
15
16
|
from .Compiler.ParseTreeTransforms import PostParse
|
|
16
17
|
|
|
17
18
|
|
|
@@ -48,13 +49,27 @@ def treetypes(root):
|
|
|
48
49
|
return "\n".join([""] + w.result + [""])
|
|
49
50
|
|
|
50
51
|
|
|
51
|
-
class
|
|
52
|
+
class TimedTest(unittest.TestCase):
|
|
53
|
+
# See copy in runtests.py
|
|
54
|
+
def setUp(self):
|
|
55
|
+
super().setUp()
|
|
56
|
+
self._start_time = time.time()
|
|
57
|
+
|
|
58
|
+
def tearDown(self):
|
|
59
|
+
t = time.time() - self._start_time
|
|
60
|
+
super().tearDown()
|
|
61
|
+
sys.stderr.write(f"[{self.id()}:{'' if t < .5 else ' SLOWTEST'} {t:.2f} sec] ")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class CythonTest(TimedTest):
|
|
52
65
|
|
|
53
66
|
def setUp(self):
|
|
54
|
-
Errors.
|
|
67
|
+
Errors.reset()
|
|
68
|
+
super().setUp()
|
|
55
69
|
|
|
56
70
|
def tearDown(self):
|
|
57
|
-
|
|
71
|
+
super().tearDown()
|
|
72
|
+
Errors.reset()
|
|
58
73
|
|
|
59
74
|
def assertLines(self, expected, result):
|
|
60
75
|
"Checks that the given strings or lists of strings are equal line by line"
|
|
@@ -101,7 +116,13 @@ class CythonTest(unittest.TestCase):
|
|
|
101
116
|
if name.startswith("__main__."):
|
|
102
117
|
name = name[len("__main__."):]
|
|
103
118
|
name = name.replace(".", "_")
|
|
104
|
-
|
|
119
|
+
|
|
120
|
+
with Errors.local_errors() as errors:
|
|
121
|
+
fragment = TreeFragment(code, name, pxds, pipeline=pipeline)
|
|
122
|
+
|
|
123
|
+
if errors:
|
|
124
|
+
raise errors[0]
|
|
125
|
+
return fragment
|
|
105
126
|
|
|
106
127
|
def treetypes(self, root):
|
|
107
128
|
return treetypes(root)
|
|
@@ -304,7 +325,7 @@ class TreeAssertVisitor(VisitorTransform):
|
|
|
304
325
|
self.visitchildren(node)
|
|
305
326
|
return node
|
|
306
327
|
|
|
307
|
-
def
|
|
328
|
+
def visit_CompilerDirectivesMixin(self, node):
|
|
308
329
|
self._check_directives(node)
|
|
309
330
|
self.visitchildren(node)
|
|
310
331
|
return node
|
|
@@ -401,12 +422,33 @@ def write_newer_file(file_path, newer_than, content, dedent=False, encoding=None
|
|
|
401
422
|
write_file(file_path, content, dedent=dedent, encoding=encoding)
|
|
402
423
|
|
|
403
424
|
|
|
425
|
+
class DictEvalScope:
|
|
426
|
+
def __init__(self, namespace):
|
|
427
|
+
self.lookup = namespace.get
|
|
428
|
+
|
|
429
|
+
empty_eval_scope = DictEvalScope({})
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def compiled_eval(code, namespace=None):
|
|
433
|
+
"""
|
|
434
|
+
Parse code and evaluate it in a compile time env.
|
|
435
|
+
"""
|
|
436
|
+
node = py_parse_code(code)
|
|
437
|
+
|
|
438
|
+
if isinstance(node, Nodes.StatListNode):
|
|
439
|
+
assert len(node.stats) == 1, node.stats
|
|
440
|
+
node = node.stats[0]
|
|
441
|
+
if isinstance(node, Nodes.ExprStatNode):
|
|
442
|
+
node = node.expr
|
|
443
|
+
|
|
444
|
+
return node.compile_time_value(DictEvalScope(namespace) if namespace else empty_eval_scope)
|
|
445
|
+
|
|
446
|
+
|
|
404
447
|
def py_parse_code(code):
|
|
405
448
|
"""
|
|
406
449
|
Compiles code far enough to get errors from the parser and post-parse stage.
|
|
407
450
|
|
|
408
|
-
Is useful for checking for syntax errors, however it doesn't generate runable
|
|
409
|
-
code.
|
|
451
|
+
Is useful for checking for syntax errors, however it doesn't generate runable code.
|
|
410
452
|
"""
|
|
411
453
|
context = StringParseContext("test")
|
|
412
454
|
# all the errors we care about are in the parsing or postparse stage
|
Cython/Tests/TestCythonUtils.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import sys
|
|
2
|
-
import unittest
|
|
3
2
|
from io import StringIO
|
|
4
3
|
|
|
5
4
|
from Cython.Utils import (
|
|
@@ -7,6 +6,7 @@ from Cython.Utils import (
|
|
|
7
6
|
build_hex_version, cached_method, clear_method_caches, try_finally_contextmanager,
|
|
8
7
|
print_version, normalise_float_repr,
|
|
9
8
|
)
|
|
9
|
+
from Cython.TestUtils import TimedTest
|
|
10
10
|
|
|
11
11
|
METHOD_NAME = "cached_next"
|
|
12
12
|
CACHE_NAME = _build_cache_name(METHOD_NAME)
|
|
@@ -18,7 +18,7 @@ class Cached:
|
|
|
18
18
|
return next(x)
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
class TestCythonUtils(
|
|
21
|
+
class TestCythonUtils(TimedTest):
|
|
22
22
|
def test_build_hex_version(self):
|
|
23
23
|
self.assertEqual('0x001D00A1', build_hex_version('0.29a1'))
|
|
24
24
|
self.assertEqual('0x001D03C4', build_hex_version('0.29.3rc4'))
|
Cython/Tests/TestJediTyper.py
CHANGED
|
@@ -46,7 +46,7 @@ class DeclarationsFinder(Visitor.VisitorTransform):
|
|
|
46
46
|
|
|
47
47
|
visit_Node = Visitor.VisitorTransform.recurse_to_children
|
|
48
48
|
|
|
49
|
-
def
|
|
49
|
+
def visit_CompilerDirectivesMixin(self, node):
|
|
50
50
|
if not self.directives:
|
|
51
51
|
self.directives = []
|
|
52
52
|
self.directives.append(node)
|
Cython/Tests/TestShadow.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
|
|
3
1
|
from Cython import Shadow
|
|
4
2
|
from Cython.Compiler import Options, CythonScope, PyrexTypes, Errors
|
|
3
|
+
from Cython.TestUtils import TimedTest
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TestShadow(TimedTest):
|
|
7
|
+
def tearDown(self):
|
|
8
|
+
Errors.reset() # help out any future tests
|
|
5
9
|
|
|
6
|
-
class TestShadow(unittest.TestCase):
|
|
7
10
|
def test_all_directives_in_shadow(self):
|
|
8
11
|
missing_directives = []
|
|
9
12
|
extra_directives = []
|
|
@@ -81,13 +84,12 @@ class TestShadow(unittest.TestCase):
|
|
|
81
84
|
# present (because they're obtained by on-the-fly string parsing in `cython_scope.lookup_type`)
|
|
82
85
|
|
|
83
86
|
cython_scope = CythonScope.create_cython_scope(None)
|
|
84
|
-
# Set up just enough of "Context"
|
|
87
|
+
# Set up just enough of "Context" that CythonScope.lookup_type can fail
|
|
85
88
|
class Context:
|
|
86
89
|
cpp = False
|
|
87
90
|
language_level = 3
|
|
88
91
|
future_directives = []
|
|
89
92
|
cython_scope._context = Context
|
|
90
|
-
Errors.init_thread()
|
|
91
93
|
|
|
92
94
|
missing_types = []
|
|
93
95
|
missing_lookups = []
|
Cython/Tests/TestStringIOTree.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
|
|
3
1
|
from Cython import StringIOTree as stringtree
|
|
2
|
+
from Cython.TestUtils import TimedTest
|
|
4
3
|
|
|
5
4
|
code = """
|
|
6
5
|
cdef int spam # line 1
|
|
@@ -23,10 +22,12 @@ cpdef bacon():
|
|
|
23
22
|
|
|
24
23
|
linemap = dict(enumerate(code.splitlines()))
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
|
|
26
|
+
class TestStringIOTree(TimedTest):
|
|
27
27
|
|
|
28
28
|
def setUp(self):
|
|
29
29
|
self.tree = stringtree.StringIOTree()
|
|
30
|
+
super().setUp()
|
|
30
31
|
|
|
31
32
|
def test_markers(self):
|
|
32
33
|
assert not self.tree.allmarkers()
|
Cython/Tests/TestTestUtils.py
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import os.path
|
|
2
|
-
import unittest
|
|
3
2
|
import tempfile
|
|
4
3
|
import textwrap
|
|
5
4
|
import shutil
|
|
6
5
|
|
|
7
|
-
from ..TestUtils import write_file, write_newer_file, _parse_pattern
|
|
6
|
+
from ..TestUtils import TimedTest, write_file, write_newer_file, _parse_pattern
|
|
8
7
|
|
|
9
8
|
|
|
10
|
-
class TestTestUtils(
|
|
9
|
+
class TestTestUtils(TimedTest):
|
|
11
10
|
def setUp(self):
|
|
12
11
|
super().setUp()
|
|
13
12
|
self.temp_dir = tempfile.mkdtemp()
|
Cython/Utility/AsyncGen.c
CHANGED
|
@@ -45,19 +45,20 @@ if (likely(__pyx_AsyncGen_init($module_cname) == 0)); else
|
|
|
45
45
|
//@requires: Coroutine.c::Coroutine
|
|
46
46
|
|
|
47
47
|
#define __Pyx_AsyncGen_USED
|
|
48
|
+
|
|
48
49
|
typedef struct {
|
|
49
50
|
__pyx_CoroutineObject coro;
|
|
50
51
|
PyObject *ag_finalizer;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
char ag_hooks_inited;
|
|
53
|
+
char ag_closed;
|
|
54
|
+
char ag_running_async;
|
|
54
55
|
} __pyx_PyAsyncGenObject;
|
|
55
56
|
|
|
56
|
-
#define __Pyx_AsyncGen_CheckExact(obj)
|
|
57
|
+
#define __Pyx_AsyncGen_CheckExact(obj) Py_IS_TYPE(obj, CGLOBAL(__pyx_AsyncGenType))
|
|
57
58
|
#define __pyx_PyAsyncGenASend_CheckExact(o) \
|
|
58
|
-
|
|
59
|
+
Py_IS_TYPE(o, CGLOBAL(__pyx__PyAsyncGenASendType))
|
|
59
60
|
#define __pyx_PyAsyncGenAThrow_CheckExact(o) \
|
|
60
|
-
|
|
61
|
+
Py_IS_TYPE(o, CGLOBAL(__pyx__PyAsyncGenAThrowType))
|
|
61
62
|
|
|
62
63
|
static PyObject *__Pyx_async_gen_anext(PyObject *o);
|
|
63
64
|
static CYTHON_INLINE PyObject *__Pyx_async_gen_asend_iternext(PyObject *o);
|
|
@@ -164,7 +165,7 @@ typedef struct __pyx__PyAsyncGenWrappedValue {
|
|
|
164
165
|
} __pyx__PyAsyncGenWrappedValue;
|
|
165
166
|
|
|
166
167
|
#define __pyx__PyAsyncGenWrappedValue_CheckExact(o) \
|
|
167
|
-
|
|
168
|
+
Py_IS_TYPE(o, CGLOBAL(__pyx__PyAsyncGenWrappedValueType))
|
|
168
169
|
|
|
169
170
|
|
|
170
171
|
static int
|
|
@@ -329,6 +330,7 @@ __Pyx_async_gen_aclose(__pyx_PyAsyncGenObject *o, PyObject *arg)
|
|
|
329
330
|
}
|
|
330
331
|
|
|
331
332
|
|
|
333
|
+
// Not FASTCALL because the args end up being converted back to a tuple anyway.
|
|
332
334
|
static PyObject *
|
|
333
335
|
__Pyx_async_gen_athrow(__pyx_PyAsyncGenObject *o, PyObject *args)
|
|
334
336
|
{
|
|
@@ -351,8 +353,6 @@ static PyGetSetDef __Pyx_async_gen_getsetlist[] = {
|
|
|
351
353
|
PyDoc_STR("name of the async generator"), 0},
|
|
352
354
|
{"__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname,
|
|
353
355
|
PyDoc_STR("qualified name of the async generator"), 0},
|
|
354
|
-
//REMOVED: {(char*) "ag_await", (getter)coro_get_cr_await, NULL,
|
|
355
|
-
//REMOVED: (char*) PyDoc_STR("object being awaited on, or None")},
|
|
356
356
|
{0, 0, 0, 0, 0} /* Sentinel */
|
|
357
357
|
};
|
|
358
358
|
|
|
@@ -360,7 +360,6 @@ static PyMemberDef __Pyx_async_gen_memberlist[] = {
|
|
|
360
360
|
//REMOVED: {(char*) "ag_frame", T_OBJECT, offsetof(__pyx_PyAsyncGenObject, ag_frame), READONLY},
|
|
361
361
|
{"ag_running", T_BOOL, offsetof(__pyx_PyAsyncGenObject, ag_running_async), READONLY, NULL},
|
|
362
362
|
//REMOVED: {(char*) "ag_code", T_OBJECT, offsetof(__pyx_PyAsyncGenObject, ag_code), READONLY},
|
|
363
|
-
//ADDED: "ag_await"
|
|
364
363
|
{"ag_await", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY,
|
|
365
364
|
PyDoc_STR("object being awaited on, or None")},
|
|
366
365
|
{"__module__", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_modulename), 0, 0},
|
|
@@ -433,7 +432,7 @@ __Pyx_PyAsyncGen_ClearFreeLists(void)
|
|
|
433
432
|
|
|
434
433
|
while (CGLOBAL(__Pyx_ag_value_freelist_free)) {
|
|
435
434
|
__pyx__PyAsyncGenWrappedValue *o;
|
|
436
|
-
o = CGLOBAL(__Pyx_ag_value_freelist)[--CGLOBAL(__Pyx_ag_value_freelist_free]
|
|
435
|
+
o = CGLOBAL(__Pyx_ag_value_freelist)[--CGLOBAL(__Pyx_ag_value_freelist_free)];
|
|
437
436
|
assert(__pyx__PyAsyncGenWrappedValue_CheckExact((PyObject*)o));
|
|
438
437
|
__Pyx_PyHeapTypeObject_GC_Del(o);
|
|
439
438
|
}
|
|
@@ -441,7 +440,7 @@ __Pyx_PyAsyncGen_ClearFreeLists(void)
|
|
|
441
440
|
while (CGLOBAL(__Pyx_ag_asend_freelist_free)) {
|
|
442
441
|
__pyx_PyAsyncGenASend *o;
|
|
443
442
|
o = CGLOBAL(__Pyx_ag_asend_freelist)[--CGLOBAL(__Pyx_ag_asend_freelist_free)];
|
|
444
|
-
assert(
|
|
443
|
+
assert(Py_IS_TYPE((PyObject*)o, CGLOBAL(__pyx__PyAsyncGenASendType)));
|
|
445
444
|
__Pyx_PyHeapTypeObject_GC_Del(o);
|
|
446
445
|
}
|
|
447
446
|
|
|
@@ -569,7 +568,13 @@ __Pyx_async_gen_asend_iternext(PyObject *o)
|
|
|
569
568
|
|
|
570
569
|
|
|
571
570
|
static PyObject *
|
|
572
|
-
__Pyx_async_gen_asend_throw(__pyx_PyAsyncGenASend *o,
|
|
571
|
+
__Pyx_async_gen_asend_throw(__pyx_PyAsyncGenASend *o,
|
|
572
|
+
#if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000
|
|
573
|
+
PyObject *args
|
|
574
|
+
#else
|
|
575
|
+
PyObject *const *args, Py_ssize_t nargs
|
|
576
|
+
#endif
|
|
577
|
+
)
|
|
573
578
|
{
|
|
574
579
|
PyObject *result;
|
|
575
580
|
|
|
@@ -578,7 +583,11 @@ __Pyx_async_gen_asend_throw(__pyx_PyAsyncGenASend *o, PyObject *args)
|
|
|
578
583
|
return NULL;
|
|
579
584
|
}
|
|
580
585
|
|
|
581
|
-
result = __Pyx_Coroutine_Throw((PyObject*)o->ags_gen, args
|
|
586
|
+
result = __Pyx_Coroutine_Throw((PyObject*)o->ags_gen, args
|
|
587
|
+
#if !(CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000)
|
|
588
|
+
, nargs
|
|
589
|
+
#endif
|
|
590
|
+
);
|
|
582
591
|
result = __Pyx_async_gen_unwrap_value(o->ags_gen, result, 0);
|
|
583
592
|
|
|
584
593
|
if (result == NULL) {
|
|
@@ -601,7 +610,13 @@ __Pyx_async_gen_asend_close(PyObject *g, PyObject *args)
|
|
|
601
610
|
|
|
602
611
|
static PyMethodDef __Pyx_async_gen_asend_methods[] = {
|
|
603
612
|
{"send", (PyCFunction)__Pyx_async_gen_asend_send, METH_O, __Pyx_async_gen_send_doc},
|
|
604
|
-
{"throw", (PyCFunction
|
|
613
|
+
{"throw", __PYX_REINTERPRET_FUNCION(PyCFunction, __Pyx_async_gen_asend_throw),
|
|
614
|
+
#if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000
|
|
615
|
+
METH_VARARGS,
|
|
616
|
+
#else
|
|
617
|
+
METH_FASTCALL,
|
|
618
|
+
#endif
|
|
619
|
+
__Pyx_async_gen_throw_doc},
|
|
605
620
|
{"close", (PyCFunction)__Pyx_async_gen_asend_close, METH_NOARGS, __Pyx_async_gen_close_doc},
|
|
606
621
|
{"__await__", (PyCFunction)__Pyx_async_gen_self_method, METH_NOARGS, __Pyx_async_gen_await_doc},
|
|
607
622
|
{0, 0, 0, 0} /* Sentinel */
|
|
@@ -905,7 +920,13 @@ __Pyx_async_gen_athrow_send(__pyx_PyAsyncGenAThrow *o, PyObject *arg)
|
|
|
905
920
|
|
|
906
921
|
|
|
907
922
|
static PyObject *
|
|
908
|
-
__Pyx_async_gen_athrow_throw(__pyx_PyAsyncGenAThrow *o,
|
|
923
|
+
__Pyx_async_gen_athrow_throw(__pyx_PyAsyncGenAThrow *o,
|
|
924
|
+
#if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000
|
|
925
|
+
PyObject *args
|
|
926
|
+
#else
|
|
927
|
+
PyObject *const *args, Py_ssize_t nargs
|
|
928
|
+
#endif
|
|
929
|
+
)
|
|
909
930
|
{
|
|
910
931
|
PyObject *retval;
|
|
911
932
|
|
|
@@ -914,9 +935,18 @@ __Pyx_async_gen_athrow_throw(__pyx_PyAsyncGenAThrow *o, PyObject *args)
|
|
|
914
935
|
return NULL;
|
|
915
936
|
}
|
|
916
937
|
|
|
917
|
-
retval = __Pyx_Coroutine_Throw((PyObject*)o->agt_gen, args
|
|
938
|
+
retval = __Pyx_Coroutine_Throw((PyObject*)o->agt_gen, args
|
|
939
|
+
#if !(CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000)
|
|
940
|
+
, nargs
|
|
941
|
+
#endif
|
|
942
|
+
);
|
|
918
943
|
if (o->agt_args) {
|
|
919
|
-
|
|
944
|
+
retval = __Pyx_async_gen_unwrap_value(o->agt_gen, retval, 0);
|
|
945
|
+
if (retval == NULL) {
|
|
946
|
+
o->agt_gen->ag_running_async = 0;
|
|
947
|
+
o->agt_state = __PYX_AWAITABLE_STATE_CLOSED;
|
|
948
|
+
}
|
|
949
|
+
return retval;
|
|
920
950
|
} else {
|
|
921
951
|
// aclose() mode
|
|
922
952
|
PyObject *exc_type;
|
|
@@ -927,6 +957,10 @@ __Pyx_async_gen_athrow_throw(__pyx_PyAsyncGenAThrow *o, PyObject *args)
|
|
|
927
957
|
PyErr_SetString(PyExc_RuntimeError, __Pyx_ASYNC_GEN_IGNORED_EXIT_MSG);
|
|
928
958
|
return NULL;
|
|
929
959
|
}
|
|
960
|
+
if (retval == NULL) {
|
|
961
|
+
o->agt_gen->ag_running_async = 0;
|
|
962
|
+
o->agt_state = __PYX_AWAITABLE_STATE_CLOSED;
|
|
963
|
+
}
|
|
930
964
|
exc_type = PyErr_Occurred();
|
|
931
965
|
if (__Pyx_PyErr_GivenExceptionMatches2(exc_type, PyExc_StopAsyncIteration, PyExc_GeneratorExit)) {
|
|
932
966
|
// when aclose() is called we don't want to propagate
|
|
@@ -960,7 +994,13 @@ __Pyx_async_gen_athrow_close(PyObject *g, PyObject *args)
|
|
|
960
994
|
|
|
961
995
|
static PyMethodDef __Pyx_async_gen_athrow_methods[] = {
|
|
962
996
|
{"send", (PyCFunction)__Pyx_async_gen_athrow_send, METH_O, __Pyx_async_gen_send_doc},
|
|
963
|
-
{"throw", (PyCFunction
|
|
997
|
+
{"throw", __PYX_REINTERPRET_FUNCION(PyCFunction, __Pyx_async_gen_athrow_throw),
|
|
998
|
+
#if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000
|
|
999
|
+
METH_VARARGS,
|
|
1000
|
+
#else
|
|
1001
|
+
METH_FASTCALL,
|
|
1002
|
+
#endif
|
|
1003
|
+
__Pyx_async_gen_throw_doc},
|
|
964
1004
|
{"close", (PyCFunction)__Pyx_async_gen_athrow_close, METH_NOARGS, __Pyx_async_gen_close_doc},
|
|
965
1005
|
{"__await__", (PyCFunction)__Pyx_async_gen_self_method, METH_NOARGS, __Pyx_async_gen_await_doc},
|
|
966
1006
|
{0, 0, 0, 0} /* Sentinel */
|