Skip to content

Commit

Permalink
Add set.pop() to strict analyzer
Browse files Browse the repository at this point in the history
Summary: This method was missing from the strict analyzer, causing STRICTSTATIC linker errors in D35905142.

Reviewed By: sinancepel

Differential Revision: D35942257

fbshipit-source-id: bd74eab
  • Loading branch information
wmeehan authored and facebook-github-bot committed Apr 28, 2022
1 parent ee4e64e commit 7ccf3d8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
14 changes: 14 additions & 0 deletions StrictModules/Objects/iterable_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,19 @@ std::shared_ptr<BaseStrictObject> StrictSet::set__init__(
return NoneObject();
}

std::shared_ptr<BaseStrictObject> StrictSet::setPop(
std::shared_ptr<StrictSet> self,
const CallerContext& caller) {
checkExternalModification(self, caller);
if(self->data_.empty()) {
caller.raiseExceptionStr(KeyErrorType(), "pop from an empty set");
}
auto iter = self->data_.begin();
auto result = std::move(*iter);
self->data_.erase(iter);
return result;
}

std::shared_ptr<BaseStrictObject> StrictSet::setUpdate(
std::shared_ptr<StrictSet> self,
const CallerContext& caller,
Expand Down Expand Up @@ -1047,6 +1060,7 @@ void StrictSetType::addMethods() {
StrictSetLikeType::addMethods();
addMethod("add", StrictSet::setAdd);
addMethodDefault("__init__", StrictSet::set__init__, nullptr);
addMethod("pop", StrictSet::setPop);
addMethod("update", StrictSet::setUpdate);
addPyWrappedMethodObj<>(
kDunderRepr,
Expand Down
4 changes: 4 additions & 0 deletions StrictModules/Objects/iterable_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ class StrictSet final : public StrictSetLike {
const CallerContext& caller,
std::shared_ptr<BaseStrictObject> arg = nullptr);

static std::shared_ptr<BaseStrictObject> setPop(
std::shared_ptr<StrictSet> self,
const CallerContext& caller);

static std::shared_ptr<BaseStrictObject> setUpdate(
std::shared_ptr<StrictSet> self,
const CallerContext& caller,
Expand Down
4 changes: 3 additions & 1 deletion StrictModules/Tests/comparison_tests/interpreter_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3680,11 +3680,13 @@ s.update([5, 6])
l4 = len(s)
s.update([5, 6])
l5 = len(s)
s.pop() # cannot guarantee the same element popped
l6 = len(s)
b1 = set().issubset(s)
b2 = set() <= s
b3 = s <= set()
---
l1 l2 l3 l4 l5 b1 b2 b3
l1 l2 l3 l4 l5 l6 b1 b2 b3
---
---
test_frozenset_init
Expand Down

0 comments on commit 7ccf3d8

Please sign in to comment.