mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-10 05:14:18 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -1,8 +1,6 @@
|
|||
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
|
||||
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
|
||||
|
||||
"""Raw data collector for coverage.py."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import atexit
|
||||
|
|
@ -10,29 +8,37 @@ import dis
|
|||
import itertools
|
||||
import sys
|
||||
import threading
|
||||
|
||||
from types import FrameType, ModuleType
|
||||
from typing import Any, Callable, Set, cast
|
||||
from types import FrameType
|
||||
from types import ModuleType
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import cast
|
||||
from typing import Set
|
||||
|
||||
from coverage import env
|
||||
from coverage.types import (
|
||||
TArc, TFileDisposition, TLineNo, TTraceData, TTraceFileData, TTraceFn,
|
||||
TracerCore, TWarnFn,
|
||||
)
|
||||
from coverage.types import TArc
|
||||
from coverage.types import TFileDisposition
|
||||
from coverage.types import TLineNo
|
||||
from coverage.types import TracerCore
|
||||
from coverage.types import TTraceData
|
||||
from coverage.types import TTraceFileData
|
||||
from coverage.types import TTraceFn
|
||||
from coverage.types import TWarnFn
|
||||
|
||||
# We need the YIELD_VALUE opcode below, in a comparison-friendly form.
|
||||
# PYVERSIONS: RESUME is new in Python3.11
|
||||
RESUME = dis.opmap.get("RESUME")
|
||||
RETURN_VALUE = dis.opmap["RETURN_VALUE"]
|
||||
RESUME = dis.opmap.get('RESUME')
|
||||
RETURN_VALUE = dis.opmap['RETURN_VALUE']
|
||||
if RESUME is None:
|
||||
YIELD_VALUE = dis.opmap["YIELD_VALUE"]
|
||||
YIELD_FROM = dis.opmap["YIELD_FROM"]
|
||||
YIELD_VALUE = dis.opmap['YIELD_VALUE']
|
||||
YIELD_FROM = dis.opmap['YIELD_FROM']
|
||||
YIELD_FROM_OFFSET = 0 if env.PYPY else 2
|
||||
|
||||
# When running meta-coverage, this file can try to trace itself, which confuses
|
||||
# everything. Don't trace ourselves.
|
||||
|
||||
THIS_FILE = __file__.rstrip("co")
|
||||
THIS_FILE = __file__.rstrip('co')
|
||||
|
||||
|
||||
class PyTracer(TracerCore):
|
||||
"""Python implementation of the raw data tracer."""
|
||||
|
|
@ -92,7 +98,7 @@ class PyTracer(TracerCore):
|
|||
|
||||
self.in_atexit = False
|
||||
# On exit, self.in_atexit = True
|
||||
atexit.register(setattr, self, "in_atexit", True)
|
||||
atexit.register(setattr, self, 'in_atexit', True)
|
||||
|
||||
# Cache a bound method on the instance, so that we don't have to
|
||||
# re-create a bound method object all the time.
|
||||
|
|
@ -101,26 +107,28 @@ class PyTracer(TracerCore):
|
|||
def __repr__(self) -> str:
|
||||
points = sum(len(v) for v in self.data.values())
|
||||
files = len(self.data)
|
||||
return f"<PyTracer at {id(self):#x}: {points} data points in {files} files>"
|
||||
return f'<PyTracer at {id(self):#x}: {points} data points in {files} files>'
|
||||
|
||||
def log(self, marker: str, *args: Any) -> None:
|
||||
"""For hard-core logging of what this tracer is doing."""
|
||||
with open("/tmp/debug_trace.txt", "a") as f:
|
||||
f.write(f"{marker} {self.id}[{len(self.data_stack)}]")
|
||||
with open('/tmp/debug_trace.txt', 'a') as f:
|
||||
f.write(f'{marker} {self.id}[{len(self.data_stack)}]')
|
||||
if 0: # if you want thread ids..
|
||||
f.write(".{:x}.{:x}".format( # type: ignore[unreachable]
|
||||
self.thread.ident,
|
||||
self.threading.current_thread().ident,
|
||||
))
|
||||
f.write(" {}".format(" ".join(map(str, args))))
|
||||
f.write(
|
||||
'.{:x}.{:x}'.format( # type: ignore[unreachable]
|
||||
self.thread.ident,
|
||||
self.threading.current_thread().ident,
|
||||
),
|
||||
)
|
||||
f.write(' {}'.format(' '.join(map(str, args))))
|
||||
if 0: # if you want callers..
|
||||
f.write(" | ") # type: ignore[unreachable]
|
||||
stack = " / ".join(
|
||||
(fname or "???").rpartition("/")[-1]
|
||||
f.write(' | ') # type: ignore[unreachable]
|
||||
stack = ' / '.join(
|
||||
(fname or '???').rpartition('/')[-1]
|
||||
for _, fname, _, _ in self.data_stack
|
||||
)
|
||||
f.write(stack)
|
||||
f.write("\n")
|
||||
f.write('\n')
|
||||
|
||||
def _trace(
|
||||
self,
|
||||
|
|
@ -142,9 +150,9 @@ class PyTracer(TracerCore):
|
|||
# thread, let's deactivate ourselves now.
|
||||
if 0:
|
||||
f = frame # type: ignore[unreachable]
|
||||
self.log("---\nX", f.f_code.co_filename, f.f_lineno)
|
||||
self.log('---\nX', f.f_code.co_filename, f.f_lineno)
|
||||
while f:
|
||||
self.log(">", f.f_code.co_filename, f.f_lineno, f.f_code.co_name, f.f_trace)
|
||||
self.log('>', f.f_code.co_filename, f.f_lineno, f.f_code.co_name, f.f_trace)
|
||||
f = f.f_back
|
||||
sys.settrace(None)
|
||||
try:
|
||||
|
|
@ -153,7 +161,7 @@ class PyTracer(TracerCore):
|
|||
)
|
||||
except IndexError:
|
||||
self.log(
|
||||
"Empty stack!",
|
||||
'Empty stack!',
|
||||
frame.f_code.co_filename,
|
||||
frame.f_lineno,
|
||||
frame.f_code.co_name,
|
||||
|
|
@ -163,7 +171,7 @@ class PyTracer(TracerCore):
|
|||
# if event != "call" and frame.f_code.co_filename != self.cur_file_name:
|
||||
# self.log("---\n*", frame.f_code.co_filename, self.cur_file_name, frame.f_lineno)
|
||||
|
||||
if event == "call":
|
||||
if event == 'call':
|
||||
# Should we start a new context?
|
||||
if self.should_start_context and self.context is None:
|
||||
context_maybe = self.should_start_context(frame)
|
||||
|
|
@ -225,13 +233,13 @@ class PyTracer(TracerCore):
|
|||
oparg = frame.f_code.co_code[frame.f_lasti + 1]
|
||||
real_call = (oparg == 0)
|
||||
else:
|
||||
real_call = (getattr(frame, "f_lasti", -1) < 0)
|
||||
real_call = (getattr(frame, 'f_lasti', -1) < 0)
|
||||
if real_call:
|
||||
self.last_line = -frame.f_code.co_firstlineno
|
||||
else:
|
||||
self.last_line = frame.f_lineno
|
||||
|
||||
elif event == "line":
|
||||
elif event == 'line':
|
||||
# Record an executed line.
|
||||
if self.cur_file_data is not None:
|
||||
flineno: TLineNo = frame.f_lineno
|
||||
|
|
@ -242,7 +250,7 @@ class PyTracer(TracerCore):
|
|||
cast(Set[TLineNo], self.cur_file_data).add(flineno)
|
||||
self.last_line = flineno
|
||||
|
||||
elif event == "return":
|
||||
elif event == 'return':
|
||||
if self.trace_arcs and self.cur_file_data:
|
||||
# Record an arc leaving the function, but beware that a
|
||||
# "return" event might just mean yielding from a generator.
|
||||
|
|
@ -322,15 +330,15 @@ class PyTracer(TracerCore):
|
|||
# has changed to None. Metacoverage also messes this up, so don't
|
||||
# warn if we are measuring ourselves.
|
||||
suppress_warning = (
|
||||
(env.PYPY and self.in_atexit and tf is None)
|
||||
or env.METACOV
|
||||
(env.PYPY and self.in_atexit and tf is None) or
|
||||
env.METACOV
|
||||
)
|
||||
if self.warn and not suppress_warning:
|
||||
if tf != self._cached_bound_method_trace: # pylint: disable=comparison-with-callable
|
||||
self.warn(
|
||||
"Trace function changed, data is likely wrong: " +
|
||||
f"{tf!r} != {self._cached_bound_method_trace!r}",
|
||||
slug="trace-changed",
|
||||
'Trace function changed, data is likely wrong: ' +
|
||||
f'{tf!r} != {self._cached_bound_method_trace!r}',
|
||||
slug='trace-changed',
|
||||
)
|
||||
|
||||
def activity(self) -> bool:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue