1
- from typing import Any , assert_type
1
+ from typing import Any , TypeAlias , assert_type
2
2
3
3
import numpy as np
4
4
import numpy .typing as npt
5
5
6
- AR_U : np .char .chararray [tuple [int , ...], np .dtype [np .str_ ]]
7
- AR_S : np .char .chararray [tuple [int , ...], np .dtype [np .bytes_ ]]
6
+ _BytesCharArray : TypeAlias = np .char .chararray [tuple [Any , ...], np .dtype [np .bytes_ ]]
7
+ _StrCharArray : TypeAlias = np .char .chararray [tuple [Any , ...], np .dtype [np .str_ ]]
8
+
9
+ AR_U : _StrCharArray
10
+ AR_S : _BytesCharArray
8
11
9
12
assert_type (AR_U == AR_U , npt .NDArray [np .bool ])
10
13
assert_type (AR_S == AR_S , npt .NDArray [np .bool ])
@@ -24,46 +27,46 @@ assert_type(AR_S > AR_S, npt.NDArray[np.bool])
24
27
assert_type (AR_U < AR_U , npt .NDArray [np .bool ])
25
28
assert_type (AR_S < AR_S , npt .NDArray [np .bool ])
26
29
27
- assert_type (AR_U * 5 , np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
28
- assert_type (AR_S * [5 ], np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
30
+ assert_type (AR_U * 5 , _StrCharArray )
31
+ assert_type (AR_S * [5 ], _BytesCharArray )
29
32
30
- assert_type (AR_U % "test" , np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
31
- assert_type (AR_S % b"test" , np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
33
+ assert_type (AR_U % "test" , _StrCharArray )
34
+ assert_type (AR_S % b"test" , _BytesCharArray )
32
35
33
- assert_type (AR_U .capitalize (), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
34
- assert_type (AR_S .capitalize (), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
36
+ assert_type (AR_U .capitalize (), _StrCharArray )
37
+ assert_type (AR_S .capitalize (), _BytesCharArray )
35
38
36
- assert_type (AR_U .center (5 ), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
37
- assert_type (AR_S .center ([2 , 3 , 4 ], b"a" ), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
39
+ assert_type (AR_U .center (5 ), _StrCharArray )
40
+ assert_type (AR_S .center ([2 , 3 , 4 ], b"a" ), _BytesCharArray )
38
41
39
- assert_type (AR_U .encode (), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
40
- assert_type (AR_S .decode (), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
42
+ assert_type (AR_U .encode (), _BytesCharArray )
43
+ assert_type (AR_S .decode (), _StrCharArray )
41
44
42
- assert_type (AR_U .expandtabs (), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
43
- assert_type (AR_S .expandtabs (tabsize = 4 ), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
45
+ assert_type (AR_U .expandtabs (), _StrCharArray )
46
+ assert_type (AR_S .expandtabs (tabsize = 4 ), _BytesCharArray )
44
47
45
- assert_type (AR_U .join ("_" ), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
46
- assert_type (AR_S .join ([b"_" , b"" ]), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
48
+ assert_type (AR_U .join ("_" ), _StrCharArray )
49
+ assert_type (AR_S .join ([b"_" , b"" ]), _BytesCharArray )
47
50
48
- assert_type (AR_U .ljust (5 ), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
49
- assert_type (AR_S .ljust ([4 , 3 , 1 ], fillchar = [b"a" , b"b" , b"c" ]), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
50
- assert_type (AR_U .rjust (5 ), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
51
- assert_type (AR_S .rjust ([4 , 3 , 1 ], fillchar = [b"a" , b"b" , b"c" ]), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
51
+ assert_type (AR_U .ljust (5 ), _StrCharArray )
52
+ assert_type (AR_S .ljust ([4 , 3 , 1 ], fillchar = [b"a" , b"b" , b"c" ]), _BytesCharArray )
53
+ assert_type (AR_U .rjust (5 ), _StrCharArray )
54
+ assert_type (AR_S .rjust ([4 , 3 , 1 ], fillchar = [b"a" , b"b" , b"c" ]), _BytesCharArray )
52
55
53
- assert_type (AR_U .lstrip (), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
54
- assert_type (AR_S .lstrip (chars = b"_" ), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
55
- assert_type (AR_U .rstrip (), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
56
- assert_type (AR_S .rstrip (chars = b"_" ), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
57
- assert_type (AR_U .strip (), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
58
- assert_type (AR_S .strip (chars = b"_" ), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
56
+ assert_type (AR_U .lstrip (), _StrCharArray )
57
+ assert_type (AR_S .lstrip (chars = b"_" ), _BytesCharArray )
58
+ assert_type (AR_U .rstrip (), _StrCharArray )
59
+ assert_type (AR_S .rstrip (chars = b"_" ), _BytesCharArray )
60
+ assert_type (AR_U .strip (), _StrCharArray )
61
+ assert_type (AR_S .strip (chars = b"_" ), _BytesCharArray )
59
62
60
- assert_type (AR_U .partition ("\n " ), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
61
- assert_type (AR_S .partition ([b"a" , b"b" , b"c" ]), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
62
- assert_type (AR_U .rpartition ("\n " ), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
63
- assert_type (AR_S .rpartition ([b"a" , b"b" , b"c" ]), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
63
+ assert_type (AR_U .partition ("\n " ), _StrCharArray )
64
+ assert_type (AR_S .partition ([b"a" , b"b" , b"c" ]), _BytesCharArray )
65
+ assert_type (AR_U .rpartition ("\n " ), _StrCharArray )
66
+ assert_type (AR_S .rpartition ([b"a" , b"b" , b"c" ]), _BytesCharArray )
64
67
65
- assert_type (AR_U .replace ("_" , "-" ), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
66
- assert_type (AR_S .replace ([b"_" , b"" ], [b"a" , b"b" ]), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
68
+ assert_type (AR_U .replace ("_" , "-" ), _StrCharArray )
69
+ assert_type (AR_S .replace ([b"_" , b"" ], [b"a" , b"b" ]), _BytesCharArray )
67
70
68
71
assert_type (AR_U .split ("_" ), npt .NDArray [np .object_ ])
69
72
assert_type (AR_S .split (maxsplit = [1 , 2 , 3 ]), npt .NDArray [np .object_ ])
@@ -73,17 +76,17 @@ assert_type(AR_S.rsplit(maxsplit=[1, 2, 3]), npt.NDArray[np.object_])
73
76
assert_type (AR_U .splitlines (), npt .NDArray [np .object_ ])
74
77
assert_type (AR_S .splitlines (keepends = [True , True , False ]), npt .NDArray [np .object_ ])
75
78
76
- assert_type (AR_U .swapcase (), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
77
- assert_type (AR_S .swapcase (), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
79
+ assert_type (AR_U .swapcase (), _StrCharArray )
80
+ assert_type (AR_S .swapcase (), _BytesCharArray )
78
81
<
10000
code class="diff-text syntax-highlighted-line">
79
- assert_type (AR_U .title (), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
80
- assert_type (AR_S .title (), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
82
+ assert_type (AR_U .title (), _StrCharArray )
83
+ assert_type (AR_S .title (), _BytesCharArray )
81
84
82
- assert_type (AR_U .upper (), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
83
- assert_type (AR_S .upper (), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
85
+ assert_type (AR_U .upper (), _StrCharArray )
86
+ assert_type (AR_S .upper (), _BytesCharArray )
84
87
85
- assert_type (AR_U .zfill (5 ), np . char . chararray [ tuple [ int , ...], np . dtype [ np . str_ ]] )
86
- assert_type (AR_S .zfill ([2 , 3 , 4 ]), np . char . chararray [ tuple [ int , ...], np . dtype [ np . bytes_ ]] )
88
+ assert_type (AR_U .zfill (5 ), _StrCharArray )
89
+ assert_type (AR_S .zfill ([2 , 3 , 4 ]), _BytesCharArray )
87
90
88
91
assert_type (AR_U .count ("a" , start = [1 , 2 , 3 ]), npt .NDArray [np .int_ ])
89
92
assert_type (AR_S .count ([b"a" , b"b" , b"c" ], end = 9 ), npt .NDArray [np .int_ ])
0 commit comments