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/Compiler/Scanning.pxd
CHANGED
|
@@ -28,21 +28,43 @@ cdef class PyrexScanner(Scanner):
|
|
|
28
28
|
cdef public bint in_python_file
|
|
29
29
|
cdef public source_encoding
|
|
30
30
|
cdef dict keywords
|
|
31
|
-
cdef public list indentation_stack
|
|
31
|
+
cdef public list[Py_ssize_t] indentation_stack
|
|
32
32
|
cdef public Py_UCS4 indentation_char
|
|
33
|
-
cdef public
|
|
33
|
+
cdef public Py_ssize_t bracket_nesting_level
|
|
34
34
|
cdef readonly bint async_enabled
|
|
35
35
|
cdef public unicode sy
|
|
36
36
|
cdef public systring # EncodedString
|
|
37
37
|
cdef public list put_back_on_failure
|
|
38
38
|
# fstrings/tstrings
|
|
39
|
-
cdef list ft_string_state_stack
|
|
39
|
+
cdef list[FTStringState] ft_string_state_stack
|
|
40
40
|
cdef int in_ft_string_expr_prescan
|
|
41
41
|
|
|
42
42
|
cdef Py_ssize_t current_level(self)
|
|
43
|
-
|
|
43
|
+
|
|
44
|
+
cpdef int next(self) except -1
|
|
45
|
+
cpdef tuple peek(self)
|
|
46
|
+
cpdef int error_at_scanpos(self, message) except -1
|
|
47
|
+
cpdef int expect(self, what: str, message=*) except -1
|
|
48
|
+
cpdef int expect_keyword(self, what: str, message=*) except -1
|
|
49
|
+
cpdef int expected(self, what: str, message=*) except -1
|
|
50
|
+
cpdef int expect_indent(self) except -1
|
|
51
|
+
cpdef int expect_dedent(self) except -1
|
|
52
|
+
cpdef int expect_newline(self, message=*, ignore_semicolon: bint=*) except -1
|
|
53
|
+
cpdef int enter_async(self) except -1
|
|
54
|
+
cpdef int exit_async(self) except -1
|
|
44
55
|
|
|
45
56
|
|
|
46
57
|
cdef class FTStringState:
|
|
47
|
-
cdef list bracket_states
|
|
58
|
+
cdef list[FTStringBracketState] bracket_states
|
|
48
59
|
cdef readonly str scanner_state
|
|
60
|
+
|
|
61
|
+
cdef bracket_nesting_level(self)
|
|
62
|
+
cdef bint in_format_specifier(self)
|
|
63
|
+
cdef set_in_format_specifier(self)
|
|
64
|
+
cdef push_bracket_state(self, Py_ssize_t bracket_nesting_level)
|
|
65
|
+
cdef pop_bracket_state(self)
|
|
66
|
+
|
|
67
|
+
@cython.final
|
|
68
|
+
cdef class FTStringBracketState:
|
|
69
|
+
cdef Py_ssize_t bracket_nesting_level
|
|
70
|
+
cdef bint in_format_specifier
|
Cython/Compiler/Scanning.py
CHANGED
|
@@ -5,21 +5,24 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
import cython
|
|
8
|
+
|
|
8
9
|
cython.declare(make_lexicon=object, lexicon=object,
|
|
9
10
|
print_function=object, error=object, warning=object,
|
|
10
|
-
os=object, platform=object)
|
|
11
|
+
os=object, platform=object, Path=object)
|
|
11
12
|
|
|
12
13
|
import os
|
|
13
14
|
import platform
|
|
14
|
-
from unicodedata import normalize
|
|
15
15
|
from contextlib import contextmanager
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from unicodedata import normalize
|
|
16
18
|
|
|
17
19
|
from .. import Utils
|
|
18
|
-
from ..Plex.Scanners import Scanner
|
|
19
20
|
from ..Plex.Errors import UnrecognizedInput
|
|
21
|
+
from ..Plex.Scanners import Scanner
|
|
20
22
|
from .Errors import error, warning, hold_errors, release_errors, CompileError
|
|
21
23
|
from .Lexicon import any_string_prefix, ft_string_prefixes, make_lexicon, IDENT
|
|
22
24
|
from .Future import print_function
|
|
25
|
+
from .Lexicon import IDENT, any_string_prefix, make_lexicon
|
|
23
26
|
|
|
24
27
|
debug_scanner = 0
|
|
25
28
|
trace_scanner = 0
|
|
@@ -222,6 +225,13 @@ class FileSourceDescriptor(SourceDescriptor):
|
|
|
222
225
|
def get_description(self):
|
|
223
226
|
return self._short_path_description
|
|
224
227
|
|
|
228
|
+
def get_relative_path(self) -> Path:
|
|
229
|
+
file_path = Path(self.file_path)
|
|
230
|
+
if file_path.is_absolute():
|
|
231
|
+
return Path(self.get_description())
|
|
232
|
+
else:
|
|
233
|
+
return file_path
|
|
234
|
+
|
|
225
235
|
def get_error_description(self):
|
|
226
236
|
path = self.filename
|
|
227
237
|
cwd = Utils.decode_filename(os.getcwd() + os.path.sep)
|
|
@@ -263,6 +273,9 @@ class StringSourceDescriptor(SourceDescriptor):
|
|
|
263
273
|
def get_description(self):
|
|
264
274
|
return self.name
|
|
265
275
|
|
|
276
|
+
def get_relative_path(self):
|
|
277
|
+
return Path(self.get_description())
|
|
278
|
+
|
|
266
279
|
get_error_description = get_description
|
|
267
280
|
|
|
268
281
|
def get_filenametable_entry(self):
|
|
@@ -369,6 +382,9 @@ class PyrexScanner(Scanner):
|
|
|
369
382
|
|
|
370
383
|
def close_bracket_action(self, text):
|
|
371
384
|
self.bracket_nesting_level -= 1
|
|
385
|
+
if (self.ft_string_state_stack and
|
|
386
|
+
self.ft_string_state_stack[-1].bracket_nesting_level() > self.bracket_nesting_level):
|
|
387
|
+
self.error_at_scanpos(f"Unmatched '{text}'")
|
|
372
388
|
return text
|
|
373
389
|
|
|
374
390
|
def open_brace_action(self, text):
|
|
@@ -540,7 +556,7 @@ class PyrexScanner(Scanner):
|
|
|
540
556
|
sy, systring = self.read()
|
|
541
557
|
except UnrecognizedInput:
|
|
542
558
|
self.error_at_scanpos("Unrecognized character")
|
|
543
|
-
return # just a marker, error() always raises
|
|
559
|
+
return -1 # just a marker, error() always raises
|
|
544
560
|
if sy == IDENT:
|
|
545
561
|
if systring in self.keywords:
|
|
546
562
|
if systring == 'print' and print_function in self.context.future_directives:
|
|
@@ -578,7 +594,6 @@ class PyrexScanner(Scanner):
|
|
|
578
594
|
self.systring = systring
|
|
579
595
|
self.last_token_position_tuple = pos
|
|
580
596
|
|
|
581
|
-
|
|
582
597
|
def error(self, message, pos=None, fatal=True):
|
|
583
598
|
if pos is None:
|
|
584
599
|
pos = self.position()
|
|
@@ -621,7 +636,7 @@ class PyrexScanner(Scanner):
|
|
|
621
636
|
def expect_dedent(self):
|
|
622
637
|
self.expect('DEDENT', "Expected a decrease in indentation level")
|
|
623
638
|
|
|
624
|
-
def expect_newline(self, message="Expected a newline", ignore_semicolon
|
|
639
|
+
def expect_newline(self, message="Expected a newline", ignore_semicolon=False):
|
|
625
640
|
# Expect either a newline or end of file
|
|
626
641
|
useless_trailing_semicolon = None
|
|
627
642
|
if ignore_semicolon and self.sy == ';':
|
|
@@ -656,7 +671,7 @@ def tentatively_scan(scanner: PyrexScanner):
|
|
|
656
671
|
initial_state = (scanner.sy, scanner.systring, scanner.position())
|
|
657
672
|
try:
|
|
658
673
|
yield errors
|
|
659
|
-
except CompileError
|
|
674
|
+
except CompileError:
|
|
660
675
|
pass
|
|
661
676
|
finally:
|
|
662
677
|
if errors:
|
|
@@ -692,7 +707,7 @@ class FTStringState:
|
|
|
692
707
|
def set_in_format_specifier(self):
|
|
693
708
|
self.bracket_states[-1].in_format_specifier = True
|
|
694
709
|
|
|
695
|
-
def push_bracket_state(self, bracket_nesting_level:
|
|
710
|
+
def push_bracket_state(self, bracket_nesting_level: cython.Py_ssize_t):
|
|
696
711
|
self.bracket_states.append(FTStringBracketState(bracket_nesting_level))
|
|
697
712
|
|
|
698
713
|
def pop_bracket_state(self):
|
|
@@ -700,11 +715,6 @@ class FTStringState:
|
|
|
700
715
|
|
|
701
716
|
|
|
702
717
|
class FTStringBracketState:
|
|
703
|
-
|
|
704
|
-
# so just use __slots__ to keep it compact.
|
|
705
|
-
__slots__ = ('bracket_nesting_level', 'in_format_specifier')
|
|
706
|
-
bracket_nesting_level: int
|
|
707
|
-
in_format_specifier: bool
|
|
708
|
-
def __init__(self, bracket_nesting_level: int):
|
|
718
|
+
def __init__(self, bracket_nesting_level: cython.Py_ssize_t):
|
|
709
719
|
self.bracket_nesting_level = bracket_nesting_level
|
|
710
720
|
self.in_format_specifier = False
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import re
|
|
7
|
-
import sys
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
class UnicodeLiteralBuilder:
|
|
@@ -98,7 +97,7 @@ class EncodedString(str):
|
|
|
98
97
|
return self.encode(self.encoding)
|
|
99
98
|
|
|
100
99
|
def utf8encode(self):
|
|
101
|
-
assert self.encoding is None
|
|
100
|
+
assert self.encoding is None, self.encoding
|
|
102
101
|
return self.encode("UTF-8")
|
|
103
102
|
|
|
104
103
|
@property
|
Cython/Compiler/Symtab.py
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
import re
|
|
7
7
|
import copy
|
|
8
8
|
import operator
|
|
9
|
-
import math
|
|
10
9
|
|
|
11
10
|
from ..Utils import try_finally_contextmanager
|
|
12
11
|
from .Errors import warning, error, InternalError, performance_hint
|
|
@@ -364,7 +363,6 @@ class Scope:
|
|
|
364
363
|
# is_c_class_scope boolean Is an extension type scope
|
|
365
364
|
# is_local_scope boolean Is a local (i.e. function/method/generator) scope
|
|
366
365
|
# is_closure_scope boolean Is a closure scope
|
|
367
|
-
# is_generator_scope boolean Is a closure scope of a generator
|
|
368
366
|
# is_generator_expression_scope boolean A subset of closure scope used for generator expressions
|
|
369
367
|
# is_passthrough boolean Outer scope is passed directly
|
|
370
368
|
# is_cpp_class_scope boolean Is a C++ class scope
|
|
@@ -387,7 +385,6 @@ class Scope:
|
|
|
387
385
|
is_c_class_scope = 0
|
|
388
386
|
is_closure_scope = 0
|
|
389
387
|
is_local_scope = False
|
|
390
|
-
is_generator_scope = False
|
|
391
388
|
is_generator_expression_scope = 0
|
|
392
389
|
is_comprehension_scope = 0
|
|
393
390
|
is_passthrough = 0
|
|
@@ -1411,8 +1408,7 @@ class ModuleScope(Scope):
|
|
|
1411
1408
|
outer_scope = Builtin.builtin_scope
|
|
1412
1409
|
Scope.__init__(self, name, outer_scope, parent_module)
|
|
1413
1410
|
self.is_package = is_package
|
|
1414
|
-
self.module_name = name
|
|
1415
|
-
self.module_name = EncodedString(self.module_name)
|
|
1411
|
+
self.module_name = EncodedString(name)
|
|
1416
1412
|
self._context = context
|
|
1417
1413
|
self.module_cname = Naming.module_cname
|
|
1418
1414
|
self.module_dict_cname = Naming.moddict_cname
|
|
@@ -1903,6 +1899,8 @@ class ModuleScope(Scope):
|
|
|
1903
1899
|
collection_type = self.directives.get('collection_type')
|
|
1904
1900
|
if collection_type == 'sequence':
|
|
1905
1901
|
entry.type.has_sequence_flag = True
|
|
1902
|
+
elif collection_type == 'mapping':
|
|
1903
|
+
entry.type.has_mapping_flag = True
|
|
1906
1904
|
|
|
1907
1905
|
# cdef classes are always exported, but we need to set it to
|
|
1908
1906
|
# distinguish between unused Cython utility code extension classes
|
|
@@ -2228,9 +2226,12 @@ class ComprehensionScope(Scope):
|
|
|
2228
2226
|
class ClosureScope(LocalScope):
|
|
2229
2227
|
|
|
2230
2228
|
is_closure_scope = True
|
|
2229
|
+
is_pure_generator_scope = False
|
|
2231
2230
|
|
|
2232
|
-
def __init__(self, name, scope_name, outer_scope, parent_scope=None
|
|
2231
|
+
def __init__(self, name, scope_name, outer_scope, parent_scope=None,
|
|
2232
|
+
is_pure_generator_scope=False):
|
|
2233
2233
|
LocalScope.__init__(self, name, outer_scope, parent_scope)
|
|
2234
|
+
self.is_pure_generator_scope = is_pure_generator_scope
|
|
2234
2235
|
self.closure_cname = "%s%s" % (Naming.closure_scope_prefix, scope_name)
|
|
2235
2236
|
|
|
2236
2237
|
# def mangle_closure_cnames(self, scope_var):
|
|
@@ -2250,7 +2251,6 @@ class ClosureScope(LocalScope):
|
|
|
2250
2251
|
|
|
2251
2252
|
|
|
2252
2253
|
class GeneratorExpressionScope(ClosureScope):
|
|
2253
|
-
is_generator_scope = True
|
|
2254
2254
|
is_generator_expression_scope = True
|
|
2255
2255
|
|
|
2256
2256
|
def declare_assignment_expression_target(self, name, type, pos):
|
|
@@ -2763,7 +2763,7 @@ class CClassScope(ClassScope):
|
|
|
2763
2763
|
"""
|
|
2764
2764
|
property_entry = self.declare_property(name, doc=doc, ctype=type, pos=pos)
|
|
2765
2765
|
cfunc_entry = property_entry.scope.declare_cfunction(
|
|
2766
|
-
name=
|
|
2766
|
+
name="__get__",
|
|
2767
2767
|
type=PyrexTypes.CFuncType(
|
|
2768
2768
|
type,
|
|
2769
2769
|
[PyrexTypes.CFuncTypeArg("self", self.parent_type, pos=None)],
|
|
@@ -3028,16 +3028,23 @@ class PropertyScope(Scope):
|
|
|
3028
3028
|
def declare_cfunction(self, name, type, pos, *args, **kwargs):
|
|
3029
3029
|
"""Declare a C property function.
|
|
3030
3030
|
"""
|
|
3031
|
-
if
|
|
3032
|
-
|
|
3033
|
-
|
|
3031
|
+
if name=="__get__":
|
|
3032
|
+
if type.return_type.is_void:
|
|
3033
|
+
error(pos, "C property getter cannot return 'void'")
|
|
3034
|
+
if len(type.args) != 1:
|
|
3035
|
+
error(pos, "C property getter must have a single (self) argument")
|
|
3036
|
+
|
|
3037
|
+
if name=="__set__":
|
|
3038
|
+
if not type.return_type.is_void:
|
|
3039
|
+
error(pos, "C property setter must return 'void'")
|
|
3040
|
+
if len(type.args) != 2:
|
|
3041
|
+
error(pos, "C property setter must have two arguments (self and value)")
|
|
3042
|
+
|
|
3043
|
+
if not (type.args[0].type.is_pyobject or type.args[0].type is self.parent_scope.parent_type):
|
|
3044
|
+
error(pos, "self argument of C property method must be an object")
|
|
3034
3045
|
if type.args and type.args[0].type is py_object_type:
|
|
3035
3046
|
# Set 'self' argument type to extension type.
|
|
3036
3047
|
type.args[0].type = self.parent_scope.parent_type
|
|
3037
|
-
elif len(type.args) != 1:
|
|
3038
|
-
error(pos, "C property method must have a single (self) argument")
|
|
3039
|
-
elif not (type.args[0].type.is_pyobject or type.args[0].type is self.parent_scope.parent_type):
|
|
3040
|
-
error(pos, "C property method must have a single (object) argument")
|
|
3041
3048
|
|
|
3042
3049
|
entry = Scope.declare_cfunction(self, name, type, pos, *args, **kwargs)
|
|
3043
3050
|
entry.is_cproperty = True
|
|
@@ -3057,9 +3064,9 @@ class PropertyScope(Scope):
|
|
|
3057
3064
|
return None
|
|
3058
3065
|
|
|
3059
3066
|
|
|
3060
|
-
class
|
|
3067
|
+
class CQualifierScope(Scope):
|
|
3061
3068
|
|
|
3062
|
-
def __init__(self, base_type_scope, is_const=
|
|
3069
|
+
def __init__(self, base_type_scope, is_const=False, is_volatile=False, is_restrict=False):
|
|
3063
3070
|
Scope.__init__(
|
|
3064
3071
|
self,
|
|
3065
3072
|
'cv_' + base_type_scope.name,
|
|
@@ -3068,13 +3075,14 @@ class CConstOrVolatileScope(Scope):
|
|
|
3068
3075
|
self.base_type_scope = base_type_scope
|
|
3069
3076
|
self.is_const = is_const
|
|
3070
3077
|
self.is_volatile = is_volatile
|
|
3078
|
+
self.is_restrict = is_restrict
|
|
3071
3079
|
|
|
3072
3080
|
def lookup_here(self, name):
|
|
3073
3081
|
entry = self.base_type_scope.lookup_here(name)
|
|
3074
3082
|
if entry is not None:
|
|
3075
3083
|
entry = copy.copy(entry)
|
|
3076
|
-
entry.type = PyrexTypes.
|
|
3077
|
-
entry.type, self.is_const, self.is_volatile)
|
|
3084
|
+
entry.type = PyrexTypes.c_qualifier_type(
|
|
3085
|
+
entry.type, self.is_const, self.is_volatile, is_restrict=False)
|
|
3078
3086
|
return entry
|
|
3079
3087
|
|
|
3080
3088
|
|
|
@@ -2,43 +2,76 @@ import builtins
|
|
|
2
2
|
import json
|
|
3
3
|
import subprocess
|
|
4
4
|
import sys
|
|
5
|
-
import unittest
|
|
6
5
|
|
|
7
6
|
from ..Builtin import (
|
|
8
7
|
inferred_method_return_types, find_return_type_of_builtin_method,
|
|
9
8
|
unsafe_compile_time_methods, is_safe_compile_time_method,
|
|
10
9
|
builtin_scope,
|
|
11
10
|
)
|
|
11
|
+
from ..Symtab import ModuleScope
|
|
12
|
+
from ..PyrexTypes import py_object_type
|
|
12
13
|
|
|
13
14
|
from ..Code import (
|
|
14
15
|
KNOWN_PYTHON_BUILTINS_VERSION, KNOWN_PYTHON_BUILTINS,
|
|
16
|
+
uncachable_builtins,
|
|
15
17
|
)
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
from ...TestUtils import TimedTest
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class TestBuiltinReturnTypes(TimedTest):
|
|
18
23
|
def test_find_return_type_of_builtin_method(self):
|
|
19
24
|
# It's enough to test the method existence in a recent Python that likely has them.
|
|
20
25
|
look_up_methods = sys.version_info >= (3,10)
|
|
26
|
+
min_versions = {
|
|
27
|
+
'frozendict': (3, 15, 0, 'alpha', 7),
|
|
28
|
+
'sentinel': (3, 15, 0, 'beta', 1),
|
|
29
|
+
}
|
|
30
|
+
test_module_scope = ModuleScope('test', None, None)
|
|
31
|
+
pos = None
|
|
21
32
|
|
|
22
33
|
for type_name, methods in inferred_method_return_types.items():
|
|
23
|
-
|
|
34
|
+
try:
|
|
35
|
+
py_type = getattr(builtins, type_name if type_name != 'unicode' else 'str')
|
|
36
|
+
except AttributeError:
|
|
37
|
+
if sys.version_info >= min_versions.get(type_name, ()):
|
|
38
|
+
raise
|
|
39
|
+
print(f"Skipping builtin type '{type_name}' as it is not in 'builtins'")
|
|
40
|
+
continue
|
|
24
41
|
|
|
25
42
|
for method_name, return_type_name in methods.items():
|
|
26
43
|
builtin_type = builtin_scope.lookup(type_name).type
|
|
27
|
-
return_type = find_return_type_of_builtin_method(
|
|
44
|
+
return_type = find_return_type_of_builtin_method(
|
|
45
|
+
pos, test_module_scope, builtin_type, method_name)
|
|
28
46
|
|
|
29
47
|
if return_type.is_builtin_type:
|
|
30
48
|
if '[' in return_type_name:
|
|
31
|
-
|
|
49
|
+
origin_type_name, _, subscripted_type_names = return_type_name[:-1].partition('[')
|
|
50
|
+
if origin_type_name == 'tuple':
|
|
51
|
+
# Currently, cython does not support tuple with subscript
|
|
52
|
+
return_type_name = origin_type_name
|
|
53
|
+
else:
|
|
54
|
+
subscripted_type_names = [type_name if t == 'T' else t for t in subscripted_type_names.split(',')]
|
|
55
|
+
subscripted_types = [
|
|
56
|
+
entry.type if entry else py_object_type
|
|
57
|
+
for entry in map(builtin_scope.lookup, subscripted_type_names)
|
|
58
|
+
]
|
|
59
|
+
origin_type = builtin_scope.lookup(origin_type_name).type
|
|
60
|
+
return_type_name = origin_type.specialize_here(
|
|
61
|
+
pos, test_module_scope, subscripted_types).name
|
|
32
62
|
if return_type_name == 'T':
|
|
33
63
|
return_type_name = type_name
|
|
64
|
+
|
|
34
65
|
self.assertEqual(return_type.name, return_type_name)
|
|
35
66
|
if look_up_methods:
|
|
36
67
|
self.assertTrue(hasattr(py_type, method_name), f"{type_name}.{method_name}")
|
|
37
68
|
else:
|
|
69
|
+
if return_type_name == 'I':
|
|
70
|
+
return_type_name = 'object'
|
|
38
71
|
self.assertEqual(return_type.empty_declaration_code(pyrex=True), return_type_name)
|
|
39
72
|
|
|
40
73
|
|
|
41
|
-
class TestBuiltinCompatibility(
|
|
74
|
+
class TestBuiltinCompatibility(TimedTest):
|
|
42
75
|
def test_python_builtin_compatibility(self):
|
|
43
76
|
expected_builtins = set(KNOWN_PYTHON_BUILTINS)
|
|
44
77
|
if sys.platform != 'win32':
|
|
@@ -57,6 +90,8 @@ class TestBuiltinCompatibility(unittest.TestCase):
|
|
|
57
90
|
if sys.version_info < KNOWN_PYTHON_BUILTINS_VERSION:
|
|
58
91
|
missing_builtins = expected_builtins - runtime_builtins
|
|
59
92
|
if missing_builtins:
|
|
93
|
+
missing_from_uncachable = missing_builtins - set(uncachable_builtins)
|
|
94
|
+
self.assertSetEqual(missing_from_uncachable, set())
|
|
60
95
|
self.skipTest(f'skipping test, older Python release found. Missing builtins: {", ".join(sorted(missing_builtins))}')
|
|
61
96
|
self.skipTest('skipping test, older Python release found.')
|
|
62
97
|
self.assertSetEqual(runtime_builtins, expected_builtins)
|
|
@@ -2,12 +2,12 @@ import os
|
|
|
2
2
|
import sys
|
|
3
3
|
import re
|
|
4
4
|
from io import StringIO
|
|
5
|
-
from unittest import TestCase
|
|
6
5
|
from unittest.mock import patch, Mock
|
|
7
6
|
|
|
8
7
|
from .. import Options
|
|
9
8
|
from ..CmdLine import parse_command_line
|
|
10
9
|
|
|
10
|
+
from ...TestUtils import TimedTest
|
|
11
11
|
from .Utils import backup_Options, restore_Options, check_global_options
|
|
12
12
|
|
|
13
13
|
unpatched_exists = os.path.exists
|
|
@@ -28,8 +28,9 @@ def patched_exists(path):
|
|
|
28
28
|
return True
|
|
29
29
|
return unpatched_exists(path)
|
|
30
30
|
|
|
31
|
+
|
|
31
32
|
@patch('os.path.exists', new=Mock(side_effect=patched_exists))
|
|
32
|
-
class CmdLineParserTest(
|
|
33
|
+
class CmdLineParserTest(TimedTest):
|
|
33
34
|
def setUp(self):
|
|
34
35
|
self._options_backup = backup_Options()
|
|
35
36
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import textwrap
|
|
2
|
-
from unittest import TestCase
|
|
3
2
|
|
|
4
3
|
from .. import Naming
|
|
5
4
|
from ..Code import _indent_chunk, UtilityCode, process_utility_ccode
|
|
5
|
+
from ...TestUtils import TimedTest
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
class TestIndent(TimedTest):
|
|
8
9
|
def _test_indentations(self, chunk, expected):
|
|
9
10
|
for indentation in range(16):
|
|
10
11
|
expected_indented = textwrap.indent(expected, ' ' * indentation)
|
|
@@ -87,7 +88,7 @@ else:
|
|
|
87
88
|
self._test_indentations(chunk, expected)
|
|
88
89
|
|
|
89
90
|
|
|
90
|
-
class TestUtilityCodeProcessing(
|
|
91
|
+
class TestUtilityCodeProcessing(TimedTest):
|
|
91
92
|
def _process(self, code):
|
|
92
93
|
utility_code = UtilityCode()
|
|
93
94
|
formatted_code, is_module_specific = process_utility_ccode(utility_code, None, code)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
from copy import deepcopy
|
|
2
|
-
from unittest import TestCase
|
|
3
2
|
|
|
4
3
|
from Cython.Compiler.FlowControl import (
|
|
5
4
|
NameAssignment, StaticAssignment, Argument, NameDeletion)
|
|
5
|
+
from Cython.TestUtils import TimedTest
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class FakeType:
|
|
@@ -22,7 +22,7 @@ class FakeEntry:
|
|
|
22
22
|
type = FakeType()
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
class TestGraph(
|
|
25
|
+
class TestGraph(TimedTest):
|
|
26
26
|
def test_deepcopy(self):
|
|
27
27
|
lhs, rhs = FakeNode(), FakeNode()
|
|
28
28
|
entry = FakeEntry()
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import os.path
|
|
2
2
|
import unittest
|
|
3
3
|
|
|
4
|
-
from Cython.TestUtils import TransformTest
|
|
4
|
+
from Cython.TestUtils import TimedTest, TransformTest
|
|
5
5
|
from Cython.Compiler.ParseTreeTransforms import *
|
|
6
6
|
from Cython.Compiler.ParseTreeTransforms import _calculate_pickle_checksums
|
|
7
7
|
from Cython.Compiler.Nodes import *
|
|
@@ -274,7 +274,7 @@ class TestDebugTransform(DebuggerTestCase):
|
|
|
274
274
|
raise
|
|
275
275
|
|
|
276
276
|
|
|
277
|
-
class TestAnalyseDeclarationsTransform(
|
|
277
|
+
class TestAnalyseDeclarationsTransform(TimedTest):
|
|
278
278
|
def test_calculate_pickle_checksums(self):
|
|
279
279
|
checksums = _calculate_pickle_checksums(['member1', 'member2', 'member3'])
|
|
280
280
|
assert 2 <= len(checksums) <= 3, checksums # expecting ['0xc0af380' (MD5), '0x0c75bd4', '0xa7a7b94']
|
|
@@ -4,8 +4,8 @@ import string
|
|
|
4
4
|
|
|
5
5
|
from .. import Scanning
|
|
6
6
|
from ..Symtab import ModuleScope
|
|
7
|
+
from ...TestUtils import TimedTest
|
|
7
8
|
from ..TreeFragment import StringParseContext
|
|
8
|
-
from ..Errors import init_thread
|
|
9
9
|
|
|
10
10
|
# generate some fake code - just a bunch of lines of the form "a0 a1 ..."
|
|
11
11
|
code = []
|
|
@@ -14,10 +14,8 @@ for ch in string.ascii_lowercase:
|
|
|
14
14
|
code.append(line)
|
|
15
15
|
code = "\n".join(code)
|
|
16
16
|
|
|
17
|
-
init_thread()
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
class TestScanning(unittest.TestCase):
|
|
18
|
+
class TestScanning(TimedTest):
|
|
21
19
|
def make_scanner(self):
|
|
22
20
|
source = Scanning.StringSourceDescriptor("fake code", code)
|
|
23
21
|
buf = StringIO(code)
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
|
|
3
1
|
from Cython.Compiler import PyrexTypes as pt
|
|
4
2
|
from Cython.Compiler.ExprNodes import NameNode
|
|
5
3
|
from Cython.Compiler.PyrexTypes import CFuncTypeArg
|
|
4
|
+
from ...TestUtils import TimedTest
|
|
6
5
|
|
|
7
6
|
def cfunctype(*arg_types):
|
|
8
7
|
return pt.CFuncType(pt.c_int_type,
|
|
@@ -11,7 +10,8 @@ def cfunctype(*arg_types):
|
|
|
11
10
|
def cppclasstype(name, base_classes):
|
|
12
11
|
return pt.CppClassType(name, None, 'CPP_'+name, base_classes)
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
|
|
14
|
+
class SignatureMatcherTest(TimedTest):
|
|
15
15
|
"""
|
|
16
16
|
Test the signature matching algorithm for overloaded signatures.
|
|
17
17
|
"""
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
from itertools import chain
|
|
2
2
|
|
|
3
3
|
import Cython.Compiler.PyrexTypes as PT
|
|
4
|
+
from ...TestUtils import TimedTest
|
|
4
5
|
|
|
5
6
|
|
|
6
|
-
class TestMethodDispatcherTransform(
|
|
7
|
+
class TestMethodDispatcherTransform(TimedTest):
|
|
7
8
|
|
|
8
9
|
def test_widest_numeric_type(self):
|
|
9
10
|
def assert_widest(type1, type2, widest):
|
|
@@ -17,7 +18,49 @@ class TestMethodDispatcherTransform(unittest.TestCase):
|
|
|
17
18
|
assert_widest(PT.c_int_type, cenum, PT.c_int_type)
|
|
18
19
|
|
|
19
20
|
|
|
20
|
-
class
|
|
21
|
+
class TestBuiltinTypes(TimedTest):
|
|
22
|
+
|
|
23
|
+
BUILTIN_FLAGS_MAPPING = {
|
|
24
|
+
'is_pyint_type': ['int'],
|
|
25
|
+
'is_pyfloat_type': ['float'],
|
|
26
|
+
'is_pybool_type': ['bool'],
|
|
27
|
+
'is_pycomplex_type': ['complex'],
|
|
28
|
+
'is_pylist_type': ['list'],
|
|
29
|
+
'is_pytuple_type': ['tuple'],
|
|
30
|
+
'is_pydict_type': ['dict'],
|
|
31
|
+
'is_pyfrozendict_type': ['frozendict'],
|
|
32
|
+
'is_pyanydict_type': ['dict', 'frozendict'],
|
|
33
|
+
'is_pyset_type': ['set'],
|
|
34
|
+
'is_pyfrozenset_type': ['frozenset'],
|
|
35
|
+
'is_pyanyset_type': ['set', 'frozenset'],
|
|
36
|
+
'is_pybytes_type': ['bytes'],
|
|
37
|
+
'is_pystr_type': ['str'],
|
|
38
|
+
'is_pybytearray_type': ['bytearray'],
|
|
39
|
+
'is_pymemoryview_type': ['memoryview'],
|
|
40
|
+
'is_builtin_sequence': ['list', 'tuple', 'bytes', 'str', 'bytearray'],
|
|
41
|
+
'is_bytes_or_str_or_bytearray': ['bytes', 'str', 'bytearray'],
|
|
42
|
+
'has_uniform_element_type': ['list', 'set', 'frozenset'],
|
|
43
|
+
'supports_container_type': ['list', 'dict', 'frozendict', 'set', 'frozenset'],
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
def test_set_builtin_type_flags(self):
|
|
47
|
+
builtin_flags = set(chain.from_iterable(PT.BuiltinObjectType._builtin_type_flag_mapping.values()))
|
|
48
|
+
builtin_types = set(chain.from_iterable(self.BUILTIN_FLAGS_MAPPING.values()))
|
|
49
|
+
|
|
50
|
+
self.assertSetEqual(builtin_flags, set(self.BUILTIN_FLAGS_MAPPING))
|
|
51
|
+
self.assertSetEqual(set(PT.BuiltinObjectType._builtin_type_flag_mapping), builtin_types)
|
|
52
|
+
|
|
53
|
+
for attr in builtin_flags:
|
|
54
|
+
self.assertIs(getattr(PT.PyrexType, attr), False)
|
|
55
|
+
for type_name in self.BUILTIN_FLAGS_MAPPING[attr]:
|
|
56
|
+
self.assertIs(
|
|
57
|
+
getattr(PT.BuiltinObjectType(type_name, f'c_{type_name}'), attr),
|
|
58
|
+
True,
|
|
59
|
+
f"{attr} should be set for {type_name}"
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class TestTypeIdentifiers(TimedTest):
|
|
21
64
|
|
|
22
65
|
TEST_DATA = [
|
|
23
66
|
("char*", "char__ptr"),
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
|
|
3
1
|
from Cython.Compiler import Code, UtilityCode
|
|
2
|
+
from ...TestUtils import TimedTest
|
|
4
3
|
|
|
5
4
|
|
|
6
5
|
def strip_2tup(tup):
|
|
7
6
|
return tup[0] and tup[0].strip(), tup[1] and tup[1].strip()
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
class TestUtilityLoader(TimedTest):
|
|
10
10
|
"""
|
|
11
11
|
Test loading UtilityCodes
|
|
12
12
|
"""
|
|
@@ -94,7 +94,7 @@ class TestCythonUtilityLoader(TestTempitaUtilityLoader):
|
|
|
94
94
|
test_load_tempita = TestTempitaUtilityLoader.test_load
|
|
95
95
|
|
|
96
96
|
|
|
97
|
-
class TestUtilityCode(
|
|
97
|
+
class TestUtilityCode(TimedTest):
|
|
98
98
|
def test_equality(self):
|
|
99
99
|
c1 = Code.UtilityCode.load("NumpyImportUFunc", "NumpyImportArray.c")
|
|
100
100
|
c2 = Code.UtilityCode.load("NumpyImportArray", "NumpyImportArray.c")
|
Cython/Compiler/TypeInference.py
CHANGED
|
@@ -584,6 +584,26 @@ def safe_spanning_type(types, might_overflow, scope):
|
|
|
584
584
|
elif (not result_type.can_coerce_to_pyobject(scope)
|
|
585
585
|
and not result_type.is_error):
|
|
586
586
|
return result_type
|
|
587
|
+
|
|
588
|
+
# We'll treat it as a Python object from this point on, but may be able to infer
|
|
589
|
+
# something more concrete than 'object'.
|
|
590
|
+
|
|
591
|
+
equivalent_type = result_type.equivalent_type
|
|
592
|
+
if equivalent_type and equivalent_type.is_pyobject:
|
|
593
|
+
# This is mostly covered by the cases above but still worth a first try
|
|
594
|
+
# to give the type a chance to speak up.
|
|
595
|
+
return equivalent_type
|
|
596
|
+
elif result_type.is_unicode_char:
|
|
597
|
+
# Unicode characters are ints but are not safe to infer for all operations,
|
|
598
|
+
# e.g. '+' should probably concatenate and not add the code unit numbers.
|
|
599
|
+
return Builtin.unicode_type
|
|
600
|
+
elif result_type.is_int:
|
|
601
|
+
return Builtin.int_type
|
|
602
|
+
elif result_type.is_float:
|
|
603
|
+
return Builtin.float_type
|
|
604
|
+
elif result_type.is_complex:
|
|
605
|
+
return Builtin.complex_type
|
|
606
|
+
|
|
587
607
|
return py_object_type
|
|
588
608
|
|
|
589
609
|
|