summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2019-11-11 05:50:17 -0500
committerNed Batchelder <ned@nedbatchelder.com>2019-11-11 05:50:17 -0500
commit12ebfecd95995300caf7cd268bfd96e826552c05 (patch)
tree1f713d98adad12ecc5d1b5cfa23821ceef850f2b
parent2cbcf03f8f1f16b4edc8ddcd63361d4e00208ca3 (diff)
downloadpython-coveragepy-git-12ebfecd95995300caf7cd268bfd96e826552c05.tar.gz
Napoleon gets noisy if you use informal types
-rw-r--r--coverage/numbits.py35
-rw-r--r--coverage/sqldata.py12
2 files changed, 20 insertions, 27 deletions
diff --git a/coverage/numbits.py b/coverage/numbits.py
index 504452d7..367ec6a1 100644
--- a/coverage/numbits.py
+++ b/coverage/numbits.py
@@ -31,12 +31,13 @@ else:
new_contract('blob', lambda v: isinstance(v, buffer)) # pylint: disable=undefined-variable
+
@contract(nums='Iterable', returns='blob')
def nums_to_numbits(nums):
"""Convert `nums` into a numbits.
Arguments:
- nums (a reusable iterable of integers): the line numbers to store.
+ nums: a reusable iterable of integers, the line numbers to store.
Returns:
A binary blob.
@@ -51,15 +52,16 @@ def nums_to_numbits(nums):
b[num//8] |= 1 << num % 8
return _to_blob(bytes(b))
+
@contract(numbits='blob', returns='list[int]')
def numbits_to_nums(numbits):
"""Convert a numbits into a list of numbers.
Arguments:
- numbits (a binary blob): the packed number set.
+ numbits: a binary blob, the packed number set.
Returns:
- A list of integers.
+ A list of ints.
"""
nums = []
for byte_i, byte in enumerate(bytes_to_ints(numbits)):
@@ -68,33 +70,30 @@ def numbits_to_nums(numbits):
nums.append(byte_i * 8 + bit_i)
return nums
+
@contract(numbits1='blob', numbits2='blob', returns='blob')
def numbits_union(numbits1, numbits2):
"""Compute the union of two numbits.
- Arguments:
- numbits1, numbits2: packed number sets.
-
Returns:
- A new numbits, the union of the two number sets.
+ A new numbits, the union of `numbits1` and `numbits2`.
"""
byte_pairs = zip_longest(bytes_to_ints(numbits1), bytes_to_ints(numbits2), fillvalue=0)
return _to_blob(binary_bytes(b1 | b2 for b1, b2 in byte_pairs))
+
@contract(numbits1='blob', numbits2='blob', returns='blob')
def numbits_intersection(numbits1, numbits2):
"""Compute the intersection of two numbits.
- Arguments:
- numbits1, numbits2: packed number sets.
-
Returns:
- A new numbits, the intersection of the two number sets.
+ A new numbits, the intersection `numbits1` and `numbits2`.
"""
byte_pairs = zip_longest(bytes_to_ints(numbits1), bytes_to_ints(numbits2), fillvalue=0)
intersection_bytes = binary_bytes(b1 & b2 for b1, b2 in byte_pairs)
return _to_blob(intersection_bytes.rstrip(b'\0'))
+
@contract(numbits1='blob', numbits2='blob', returns='bool')
def numbits_any_intersection(numbits1, numbits2):
"""Is there any number that appears in both numbits?
@@ -102,32 +101,26 @@ def numbits_any_intersection(numbits1, numbits2):
Determine whether two number sets have a non-empty intersection. This is
faster than computing the intersection.
- Arguments:
- numbits1, numbits2: packed number sets.
-
Returns:
- A boolean, true if there is any number in both of the number sets.
+ A bool, True if there is any number in both `numbits1` and `numbits2`.
"""
byte_pairs = zip_longest(bytes_to_ints(numbits1), bytes_to_ints(numbits2), fillvalue=0)
return any(b1 & b2 for b1, b2 in byte_pairs)
+
@contract(num='int', numbits='blob', returns='bool')
def num_in_numbits(num, numbits):
"""Does the integer `num` appear in `numbits`?
- Arguments:
- num (integer)
-
- numbits (binary blob)
-
Returns:
- A boolean, true if `num` is a member of `numbits`.
+ A bool, True if `num` is a member of `numbits`.
"""
nbyte, nbit = divmod(num, 8)
if nbyte >= len(numbits):
return False
return bool(byte_to_int(numbits[nbyte]) & (1 << nbit))
+
def register_sqlite_functions(connection):
"""
Define numbits functions in a SQLite connection.
diff --git a/coverage/sqldata.py b/coverage/sqldata.py
index 6ce059e5..56468e64 100644
--- a/coverage/sqldata.py
+++ b/coverage/sqldata.py
@@ -164,7 +164,7 @@ class CoverageData(SimpleReprMixin):
that are convenient for coverage.py.
To record data for contexts, use :meth:`set_context` to set a context to
- be used for subsequent :meth:`add_line` and :meth:`add_arcs` calls.
+ be used for subsequent :meth:`add_lines` and :meth:`add_arcs` calls.
To add a source file without any measured data, use :meth:`touch_file`.
@@ -185,13 +185,13 @@ class CoverageData(SimpleReprMixin):
Arguments:
basename (str): the base name of the data file, defaulting to
".coverage".
- suffix (str or boolean): has the same meaning as the `data_suffix`
+ suffix (str or bool): has the same meaning as the `data_suffix`
argument to :class:`coverage.Coverage`.
- no_disk (boolean): if True, keep all data in memory, and don't
+ no_disk (bool): if True, keep all data in memory, and don't
write any disk file.
- warn (function): is a warning callback, accepting a warning message
+ warn: a warning callback function, accepting a warning message
argument.
- debug (function): a debug callback to use.
+ debug: a debug callback function.
"""
self._no_disk = no_disk
@@ -337,7 +337,7 @@ class CoverageData(SimpleReprMixin):
undefined what happens if the object already has data in it.
Arguments:
- data (byte string): serialized data produced by :meth:`dumps`.
+ data: A byte string of serialized data produced by :meth:`dumps`.
.. versionadded:: 5.0