File: 0006-Now-tell-mypy-to-ignore-the-new-errors.patch

package info (click to toggle)
pydoctor 22.9.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,976 kB
  • sloc: python: 22,250; javascript: 2,533; ansic: 57; makefile: 21; sh: 18
file content (165 lines) | stat: -rw-r--r-- 9,053 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
From: tristanlatr <tristanlatr@users.noreply.github.com>
Date: Mon, 28 Nov 2022 17:35:23 -0500
Subject: Now tell mypy to ignore the new errors.

---
 pydoctor/epydoc/markup/_pyval_repr.py   | 62 ++++++++++++++++-----------------
 pydoctor/test/epydoc/test_pyval_repr.py |  2 ++
 2 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/pydoctor/epydoc/markup/_pyval_repr.py b/pydoctor/epydoc/markup/_pyval_repr.py
index bf6ab54..a9e9ad6 100644
--- a/pydoctor/epydoc/markup/_pyval_repr.py
+++ b/pydoctor/epydoc/markup/_pyval_repr.py
@@ -812,7 +812,7 @@ class PyvalColorizer:
             op = elt[0]
             args = elt[1]
 
-            if op == sre_constants.LITERAL:
+            if op == sre_constants.LITERAL: #type:ignore[attr-defined]
                 c = chr(cast(int, args))
                 # Add any appropriate escaping.
                 if c in '.^$\\*+?{}[]|()\'': 
@@ -834,10 +834,10 @@ class PyvalColorizer:
                     c = rb'\x%02x' % ord(c) # type:ignore[assignment]
                 self._output(c, self.RE_CHAR_TAG, state)
 
-            elif op == sre_constants.ANY:
+            elif op == sre_constants.ANY: #type:ignore[attr-defined]
                 self._output('.', self.RE_CHAR_TAG, state)
 
-            elif op == sre_constants.BRANCH:
+            elif op == sre_constants.BRANCH: #type:ignore[attr-defined]
                 if args[0] is not None:
                     raise ValueError('Branch expected None arg but got %s'
                                      % args[0])
@@ -846,35 +846,35 @@ class PyvalColorizer:
                         self._output('|', self.RE_OP_TAG, state)
                     self._colorize_re_tree(item, state, True, groups)
 
-            elif op == sre_constants.IN:
-                if (len(args) == 1 and args[0][0] == sre_constants.CATEGORY):
+            elif op == sre_constants.IN: #type:ignore[attr-defined]
+                if (len(args) == 1 and args[0][0] == sre_constants.CATEGORY): #type:ignore[attr-defined]
                     self._colorize_re_tree(args, state, False, groups)
                 else:
                     self._output('[', self.RE_GROUP_TAG, state)
                     self._colorize_re_tree(args, state, True, groups)
                     self._output(']', self.RE_GROUP_TAG, state)
 
-            elif op == sre_constants.CATEGORY:
-                if args == sre_constants.CATEGORY_DIGIT: val = r'\d'
-                elif args == sre_constants.CATEGORY_NOT_DIGIT: val = r'\D'
-                elif args == sre_constants.CATEGORY_SPACE: val = r'\s'
-                elif args == sre_constants.CATEGORY_NOT_SPACE: val = r'\S'
-                elif args == sre_constants.CATEGORY_WORD: val = r'\w'
-                elif args == sre_constants.CATEGORY_NOT_WORD: val = r'\W'
+            elif op == sre_constants.CATEGORY: #type:ignore[attr-defined]
+                if args == sre_constants.CATEGORY_DIGIT: val = r'\d' #type:ignore[attr-defined]
+                elif args == sre_constants.CATEGORY_NOT_DIGIT: val = r'\D' #type:ignore[attr-defined]
+                elif args == sre_constants.CATEGORY_SPACE: val = r'\s' #type:ignore[attr-defined]
+                elif args == sre_constants.CATEGORY_NOT_SPACE: val = r'\S' #type:ignore[attr-defined]
+                elif args == sre_constants.CATEGORY_WORD: val = r'\w' #type:ignore[attr-defined]
+                elif args == sre_constants.CATEGORY_NOT_WORD: val = r'\W' #type:ignore[attr-defined]
                 else: raise ValueError('Unknown category %s' % args)
                 self._output(val, self.RE_CHAR_TAG, state)
 
-            elif op == sre_constants.AT:
-                if args == sre_constants.AT_BEGINNING_STRING: val = r'\A'
-                elif args == sre_constants.AT_BEGINNING: val = '^'
-                elif args == sre_constants.AT_END: val = '$'
-                elif args == sre_constants.AT_BOUNDARY: val = r'\b'
-                elif args == sre_constants.AT_NON_BOUNDARY: val = r'\B'
-                elif args == sre_constants.AT_END_STRING: val = r'\Z'
+            elif op == sre_constants.AT: #type:ignore[attr-defined]
+                if args == sre_constants.AT_BEGINNING_STRING: val = r'\A' #type:ignore[attr-defined]
+                elif args == sre_constants.AT_BEGINNING: val = '^' #type:ignore[attr-defined]
+                elif args == sre_constants.AT_END: val = '$' #type:ignore[attr-defined]
+                elif args == sre_constants.AT_BOUNDARY: val = r'\b' #type:ignore[attr-defined]
+                elif args == sre_constants.AT_NON_BOUNDARY: val = r'\B' #type:ignore[attr-defined]
+                elif args == sre_constants.AT_END_STRING: val = r'\Z' #type:ignore[attr-defined]
                 else: raise ValueError('Unknown position %s' % args)
                 self._output(val, self.RE_CHAR_TAG, state)
 
-            elif op in (sre_constants.MAX_REPEAT, sre_constants.MIN_REPEAT):
+            elif op in (sre_constants.MAX_REPEAT, sre_constants.MIN_REPEAT): #type:ignore[attr-defined]
                 minrpt = args[0]
                 maxrpt = args[1]
                 if maxrpt == sre_constants.MAXREPEAT:
@@ -888,13 +888,13 @@ class PyvalColorizer:
                     val = '{%d}' % (maxrpt)
                 else:
                     val = '{%d,%d}' % (minrpt, maxrpt)
-                if op == sre_constants.MIN_REPEAT:
+                if op == sre_constants.MIN_REPEAT: #type:ignore[attr-defined]
                     val += '?'
 
                 self._colorize_re_tree(args[2], state, False, groups)
                 self._output(val, self.RE_OP_TAG, state)
 
-            elif op == sre_constants.SUBPATTERN:
+            elif op == sre_constants.SUBPATTERN: #type:ignore[attr-defined]
                 if args[0] is None:
                     self._output(r'(?:', self.RE_GROUP_TAG, state)
                 elif args[0] in groups:
@@ -911,20 +911,20 @@ class PyvalColorizer:
                 self._colorize_re_tree(args[3], state, True, groups)
                 self._output(')', self.RE_GROUP_TAG, state)
 
-            elif op == sre_constants.GROUPREF:
+            elif op == sre_constants.GROUPREF: #type:ignore[attr-defined]
                 self._output('\\%d' % args, self.RE_REF_TAG, state)
 
-            elif op == sre_constants.RANGE:
-                self._colorize_re_tree( ((sre_constants.LITERAL, args[0]),),
+            elif op == sre_constants.RANGE: #type:ignore[attr-defined]
+                self._colorize_re_tree( ((sre_constants.LITERAL, args[0]),), #type:ignore[attr-defined]
                                         state, False, groups )
                 self._output('-', self.RE_OP_TAG, state)
-                self._colorize_re_tree( ((sre_constants.LITERAL, args[1]),),
+                self._colorize_re_tree( ((sre_constants.LITERAL, args[1]),), #type:ignore[attr-defined]
                                         state, False, groups )
 
-            elif op == sre_constants.NEGATE:
+            elif op == sre_constants.NEGATE: #type:ignore[attr-defined]
                 self._output('^', self.RE_OP_TAG, state)
 
-            elif op == sre_constants.ASSERT:
+            elif op == sre_constants.ASSERT: #type:ignore[attr-defined]
                 if args[0] > 0:
                     self._output('(?=', self.RE_GROUP_TAG, state)
                 else:
@@ -932,7 +932,7 @@ class PyvalColorizer:
                 self._colorize_re_tree(args[1], state, True, groups)
                 self._output(')', self.RE_GROUP_TAG, state)
 
-            elif op == sre_constants.ASSERT_NOT:
+            elif op == sre_constants.ASSERT_NOT: #type:ignore[attr-defined]
                 if args[0] > 0:
                     self._output('(?!', self.RE_GROUP_TAG, state)
                 else:
@@ -940,9 +940,9 @@ class PyvalColorizer:
                 self._colorize_re_tree(args[1], state, True, groups)
                 self._output(')', self.RE_GROUP_TAG, state)
 
-            elif op == sre_constants.NOT_LITERAL:
+            elif op == sre_constants.NOT_LITERAL: #type:ignore[attr-defined]
                 self._output('[^', self.RE_GROUP_TAG, state)
-                self._colorize_re_tree( ((sre_constants.LITERAL, args),),
+                self._colorize_re_tree( ((sre_constants.LITERAL, args),), #type:ignore[attr-defined]
                                         state, False, groups )
                 self._output(']', self.RE_GROUP_TAG, state)
             else:
diff --git a/pydoctor/test/epydoc/test_pyval_repr.py b/pydoctor/test/epydoc/test_pyval_repr.py
index cdf4ea1..68b178e 100644
--- a/pydoctor/test/epydoc/test_pyval_repr.py
+++ b/pydoctor/test/epydoc/test_pyval_repr.py
@@ -1244,6 +1244,8 @@ def color_re(s: Union[bytes, str],
         
         expected = s
         if not raw_string:
+            assert isinstance(expected, str) 
+            # we only test invalid regexes with strings currently
             expected = expected.replace('\\', '\\\\')
         
         assert round_trip == expected, "%s != %s" % (repr(round_trip), repr(s))