]>
crepu.dev Git - config.git/blob - djavu-asus/emacs/elpy/rpc-venv/lib/python3.11/site-packages/pyflakes/reporter.py
65ed4d8e75019e929bf4012bb13e1a0c7285c0ae
2 Provide the Reporter class.
11 Formats the results of pyflakes checks to users.
14 def __init__(self
, warningStream
, errorStream
):
16 Construct a L{Reporter}.
18 @param warningStream: A file-like object where warnings will be
19 written to. The stream's C{write} method must accept unicode.
20 C{sys.stdout} is a good value.
21 @param errorStream: A file-like object where error output will be
22 written to. The stream's C{write} method must accept unicode.
23 C{sys.stderr} is a good value.
25 self
._stdout
= warningStream
26 self
._stderr
= errorStream
28 def unexpectedError(self
, filename
, msg
):
30 An unexpected error occurred trying to process C{filename}.
32 @param filename: The path to a file that we could not process.
33 @ptype filename: C{unicode}
34 @param msg: A message explaining the problem.
35 @ptype msg: C{unicode}
37 self
._stderr
.write(f
"{filename}: {msg}\n")
39 def syntaxError(self
, filename
, msg
, lineno
, offset
, text
):
41 There was a syntax error in C{filename}.
43 @param filename: The path to the file with the syntax error.
44 @ptype filename: C{unicode}
45 @param msg: An explanation of the syntax error.
46 @ptype msg: C{unicode}
47 @param lineno: The line number where the syntax error occurred.
49 @param offset: The column on which the syntax error occurred, or None.
51 @param text: The source code containing the syntax error.
52 @ptype text: C{unicode}
57 line
= text
.splitlines()[-1]
59 # lineno might be None if the error was during tokenization
60 # lineno might be 0 if the error came from stdin
61 lineno
= max(lineno
or 0, 1)
63 if offset
is not None:
64 # some versions of python emit an offset of -1 for certain encoding errors
65 offset
= max(offset
, 1)
66 self
._stderr
.write('%s:%d:%d: %s\n' %
67 (filename
, lineno
, offset
, msg
))
69 self
._stderr
.write('%s:%d: %s\n' % (filename
, lineno
, msg
))
72 self
._stderr
.write(line
)
73 self
._stderr
.write('\n')
74 if offset
is not None:
75 self
._stderr
.write(re
.sub(r
'\S', ' ', line
[:offset
- 1]) +
78 def flake(self
, message
):
80 pyflakes found something wrong with the code.
82 @param: A L{pyflakes.messages.Message}.
84 self
._stdout
.write(str(message
))
85 self
._stdout
.write('\n')
88 def _makeDefaultReporter():
90 Make a reporter that can be used when no reporter is specified.
92 return Reporter(sys
.stdout
, sys
.stderr
)