Document that system:pop() may raise IndexDefect (#21070)

* Document system:pop() may raise IndexDefect

* Add backticks to KeyError
This commit is contained in:
Xavier Noria
2022-12-13 08:47:01 +01:00
committed by GitHub
parent 7ae7832f76
commit e4aadcf1c1
2 changed files with 5 additions and 3 deletions

View File

@@ -347,7 +347,7 @@ proc missingOrExcl*[A](s: var HashSet[A], key: A): bool =
proc pop*[A](s: var HashSet[A]): A =
## Removes and returns an arbitrary element from the set `s`.
##
## Raises KeyError if the set `s` is empty.
## Raises `KeyError` if the set `s` is empty.
##
## See also:
## * `clear proc <#clear,HashSet[A]>`_
@@ -425,7 +425,7 @@ proc intersection*[A](s1, s2: HashSet[A]): HashSet[A] =
assert c == toHashSet(["b"])
result = initHashSet[A](max(min(s1.data.len, s2.data.len), 2))
# iterate over the elements of the smaller set
if s1.data.len < s2.data.len:
for item in s1:
@@ -433,7 +433,7 @@ proc intersection*[A](s1, s2: HashSet[A]): HashSet[A] =
else:
for item in s2:
if item in s1: incl(result, item)
proc difference*[A](s1, s2: HashSet[A]): HashSet[A] =
## Returns the difference of the sets `s1` and `s2`.

View File

@@ -1664,6 +1664,8 @@ proc contains*[T](a: openArray[T], item: T): bool {.inline.}=
proc pop*[T](s: var seq[T]): T {.inline, noSideEffect.} =
## Returns the last item of `s` and decreases `s.len` by one. This treats
## `s` as a stack and implements the common *pop* operation.
##
## Raises `IndexDefect` if `s` is empty.
runnableExamples:
var a = @[1, 3, 5, 7]
let b = pop(a)