File tree Expand file tree Collapse file tree 6 files changed +102
-90
lines changed
Expand file tree Collapse file tree 6 files changed +102
-90
lines changed Original file line number Diff line number Diff line change 1+ # These are shared with test_tokenize and other test modules.
2+ #
3+ # Note: since several test cases filter out floats by looking for "e" and ".",
4+ # don't add hexadecimal literals that contain "e" or "E".
5+ VALID_UNDERSCORE_LITERALS = [
6+ '0_0_0' ,
7+ '4_2' ,
8+ '1_0000_0000' ,
9+ '0b1001_0100' ,
10+ '0xffff_ffff' ,
11+ '0o5_7_7' ,
12+ '1_00_00.5' ,
13+ '1_00_00.5e5' ,
14+ '1_00_00e5_1' ,
15+ '1e1_0' ,
16+ '.1_4' ,
17+ '.1_4e1' ,
18+ '0b_0' ,
19+ '0x_f' ,
20+ '0o_5' ,
21+ '1_00_00j' ,
22+ '1_00_00.5j' ,
23+ '1_00_00e5_1j' ,
24+ '.1_4j' ,
25+ '(1_2.5+3_3j)' ,
26+ '(.5_6j)' ,
27+ ]
28+ INVALID_UNDERSCORE_LITERALS = [
29+ # Trailing underscores:
30+ '0_' ,
31+ '42_' ,
32+ '1.4j_' ,
33+ '0x_' ,
34+ '0b1_' ,
35+ '0xf_' ,
36+ '0o5_' ,
37+ '0 if 1_Else 1' ,
38+ # Underscores in the base selector:
39+ '0_b0' ,
40+ '0_xf' ,
41+ '0_o5' ,
42+ # Old-style octal, still disallowed:
43+ '0_7' ,
44+ '09_99' ,
45+ # Multiple consecutive underscores:
46+ '4_______2' ,
47+ '0.1__4' ,
48+ '0.1__4j' ,
49+ '0b1001__0100' ,
50+ '0xffff__ffff' ,
51+ '0x___' ,
52+ '0o5__77' ,
53+ '1e1__0' ,
54+ '1e1__0j' ,
55+ # Underscore right before a dot:
56+ '1_.4' ,
57+ '1_.4j' ,
58+ # Underscore right after a dot:
59+ '1._4' ,
60+ '1._4j' ,
61+ '._5' ,
62+ '._5j' ,
63+ # Underscore right after a sign:
64+ '1.0e+_1' ,
65+ '1.0e+_1j' ,
66+ # Underscore right before j:
67+ '1.4_j' ,
68+ '1.4e5_j' ,
69+ # Underscore right before e:
70+ '1_e1' ,
71+ '1.4_e1' ,
72+ '1.4_e1j' ,
73+ # Underscore right after e:
74+ '1e_1' ,
75+ '1.4e_1' ,
76+ '1.4e_1j' ,
77+ # Complex cases with parens:
78+ '(1+1.5_j_)' ,
79+ '(1+1.5_j)' ,
80+ ]
81+
Original file line number Diff line number Diff line change 22import sys
33from test import support
44from test .support .testcase import ComplexesAreIdenticalMixin
5- from test .test_grammar import (VALID_UNDERSCORE_LITERALS ,
6- INVALID_UNDERSCORE_LITERALS )
5+ from test .support .numbers import (
6+ VALID_UNDERSCORE_LITERALS ,
7+ INVALID_UNDERSCORE_LITERALS ,
8+ )
79
810from random import random
911from math import isnan , copysign
Original file line number Diff line number Diff line change 99
1010from test import support
1111from test .support .testcase import FloatsAreIdenticalMixin
12- from test .test_grammar import (VALID_UNDERSCORE_LITERALS ,
13- INVALID_UNDERSCORE_LITERALS )
12+ from test .support .numbers import (
13+ VALID_UNDERSCORE_LITERALS ,
14+ INVALID_UNDERSCORE_LITERALS ,
15+ )
1416from math import isinf , isnan , copysign , ldexp
1517import math
1618
Original file line number Diff line number Diff line change 1717import typing
1818from test .typinganndata import ann_module2
1919import test
20-
21- # These are shared with test_tokenize and other test modules.
22- #
23- # Note: since several test cases filter out floats by looking for "e" and ".",
24- # don't add hexadecimal literals that contain "e" or "E".
25- VALID_UNDERSCORE_LITERALS = [
26- '0_0_0' ,
27- '4_2' ,
28- '1_0000_0000' ,
29- '0b1001_0100' ,
30- '0xffff_ffff' ,
31- '0o5_7_7' ,
32- '1_00_00.5' ,
33- '1_00_00.5e5' ,
34- '1_00_00e5_1' ,
35- '1e1_0' ,
36- '.1_4' ,
37- '.1_4e1' ,
38- '0b_0' ,
39- '0x_f' ,
40- '0o_5' ,
41- '1_00_00j' ,
42- '1_00_00.5j' ,
43- '1_00_00e5_1j' ,
44- '.1_4j' ,
45- '(1_2.5+3_3j)' ,
46- '(.5_6j)' ,
47- ]
48- INVALID_UNDERSCORE_LITERALS = [
49- # Trailing underscores:
50- '0_' ,
51- '42_' ,
52- '1.4j_' ,
53- '0x_' ,
54- '0b1_' ,
55- '0xf_' ,
56- '0o5_' ,
57- '0 if 1_Else 1' ,
58- # Underscores in the base selector:
59- '0_b0' ,
60- '0_xf' ,
61- '0_o5' ,
62- # Old-style octal, still disallowed:
63- '0_7' ,
64- '09_99' ,
65- # Multiple consecutive underscores:
66- '4_______2' ,
67- '0.1__4' ,
68- '0.1__4j' ,
69- '0b1001__0100' ,
70- '0xffff__ffff' ,
71- '0x___' ,
72- '0o5__77' ,
73- '1e1__0' ,
74- '1e1__0j' ,
75- # Underscore right before a dot:
76- '1_.4' ,
77- '1_.4j' ,
78- # Underscore right after a dot:
79- '1._4' ,
80- '1._4j' ,
81- '._5' ,
82- '._5j' ,
83- # Underscore right after a sign:
84- '1.0e+_1' ,
85- '1.0e+_1j' ,
86- # Underscore right before j:
87- '1.4_j' ,
88- '1.4e5_j' ,
89- # Underscore right before e:
90- '1_e1' ,
91- '1.4_e1' ,
92- '1.4_e1j' ,
93- # Underscore right after e:
94- '1e_1' ,
95- '1.4e_1' ,
96- '1.4e_1j' ,
97- # Complex cases with parens:
98- '(1+1.5_j_)' ,
99- '(1+1.5_j)' ,
100- ]
101-
20+ from test .support .numbers import (
21+ VALID_UNDERSCORE_LITERALS ,
22+ INVALID_UNDERSCORE_LITERALS ,
23+ )
10224
10325class TokenTests (unittest .TestCase ):
10426
Original file line number Diff line number Diff line change 33import unittest
44from unittest import mock
55from test import support
6- from test .test_grammar import (VALID_UNDERSCORE_LITERALS ,
7- INVALID_UNDERSCORE_LITERALS )
6+ from test .support .numbers import (
7+ VALID_UNDERSCORE_LITERALS ,
8+ INVALID_UNDERSCORE_LITERALS ,
9+ )
810
911try :
1012 import _pylong
Original file line number Diff line number Diff line change 77from textwrap import dedent
88from unittest import TestCase , mock
99from test import support
10- from test .test_grammar import (VALID_UNDERSCORE_LITERALS ,
11- INVALID_UNDERSCORE_LITERALS )
1210from test .support import os_helper
1311from test .support .script_helper import run_test_script , make_script , run_python_until_end
12+ from test .support .numbers import (
13+ VALID_UNDERSCORE_LITERALS ,
14+ INVALID_UNDERSCORE_LITERALS ,
15+ )
16+
1417
1518# Converts a source string into a list of textual representation
1619# of the tokens such as:
You can’t perform that action at this time.
0 commit comments