Skip to content

Commit

Permalink
Applying suggestions for review
Browse files Browse the repository at this point in the history
  • Loading branch information
SamWheating committed Aug 22, 2023
1 parent 6769f79 commit 449684b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
12 changes: 6 additions & 6 deletions doc/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -3759,20 +3759,20 @@ x.remove(2) # error: element not found
If `x` is not an element of set `S`, `S.add(x)` adds it to the set or fails if the set is frozen.
If `x` already an element of the set, `add(x)` has no effect.
`add` fails if the set does not contain `x` and is frozen.
It returns None.
```python
x = set([1, 2])
x.add(3) # None (x == set([1, 2, 3]))
x.add(3) # None (x == set([1, 2, 3]))
x.add(3) # None
x # set([1, 2, 3])
x.add(3) # None
x # set([1, 2, 3])
```
<a id='set·clear'></a>
### set·clear
`S.clear()` removes all items from the set and fails if the set is non-empty and frozen.
`S.clear()` removes all items from the set or fails if the set is non-empty and frozen.
It returns None.
Expand Down Expand Up @@ -3803,7 +3803,7 @@ x # set([1, 3])
`S.pop()` removes the first inserted item from the set and returns it.
`pop` fails if the set is empty or is frozen.
`pop` fails if the set is empty or frozen.
```python
x = set([1, 2])
Expand Down
12 changes: 5 additions & 7 deletions starlark/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -2196,12 +2196,10 @@ func set_clear(_ *Thread, b *Builtin, args Tuple, kwargs []Tuple) (Value, error)
if err := UnpackPositionalArgs(b.Name(), args, kwargs, 0); err != nil {
return nil, err
}
if b.Receiver().(*Set).Len() == 0 { // clear on an empty set is non-mutating
return None, nil
}
err := b.Receiver().(*Set).Clear()
if err != nil {
return nil, nameErr(b, err)
if b.Receiver().(*Set).Len() > 0 {
if err := b.Receiver().(*Set).Clear(); err != nil {
return nil, nameErr(b, err)
}
}
return None, nil
}
Expand All @@ -2218,7 +2216,7 @@ func set_discard(_ *Thread, b *Builtin, args Tuple, kwargs []Tuple) (Value, erro
return None, nil
}
if _, err := b.Receiver().(*Set).Delete(k); err != nil {
return nil, nameErr(b, err) // dict is frozen or key is unhashable
return nil, nameErr(b, err) // set is frozen
}
return None, nil
}
Expand Down

0 comments on commit 449684b

Please sign in to comment.