@@ -181,22 +181,34 @@ function Base.showerror(io::IO, e::PyException)
181
181
import traceback
182
182
$(fs :: Vector{Tuple{String, String, Int}} ) = [(x.name, x.filename, x.lineno) for x in traceback.extract_tb($(e. bref) )]
183
183
```
184
- for (i, (name, fname, lineno)) in enumerate ( reverse (fs))
185
- if VERSION < v " 1.6.0-rc1 "
184
+ if VERSION < v " 1.6.0-rc1 "
185
+ for (i, (name, fname, lineno)) in enumerate ( reverse (fs))
186
186
println (io)
187
187
printstyled (io, " [" , i, " ] " )
188
188
printstyled (io, name, bold = true )
189
189
printstyled (io, " at " )
190
190
printstyled (io, fname, " :" , lineno, bold = true )
191
- else
191
+ end
192
+ else
193
+ mcdict = Dict {String, Symbol} ()
194
+ mccyclyer = Iterators. Stateful (Iterators. cycle (Base. STACKTRACE_MODULECOLORS))
195
+ for (i, (name, fname, lineno)) in enumerate (reverse (fs))
192
196
println (io)
193
197
printstyled (io, " [" , i, " ] " )
194
198
printstyled (io, name, bold = true )
195
199
println (io)
196
200
printstyled (io, " @ " , color = :light_black )
197
201
mod = file_to_pymodule (fname)
198
202
if mod != = nothing
199
- printstyled (io, mod, " " , color = :magenta )
203
+ # print the module, with colour determined by the top level name
204
+ tmod = first (split (mod, " ." , limit= 2 ))
205
+ color = get! (mcdict, tmod) do
206
+ popfirst! (mccyclyer)
207
+ end
208
+ printstyled (io, mod, " " , color = color)
209
+ end
210
+ if isfile (fname) && Base. stacktrace_contract_userdir ()
211
+ fname = Base. replaceuserpath (fname)
200
212
end
201
213
printstyled (io, fname, " :" , lineno, color = :light_black )
202
214
end
0 commit comments