We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
IAM policy should return an empty set of the bindings do not exist
https://github.com/GoogleCloudPlatform/google-cloud-python/blob/bd9fdfba07fac63a91847628613928a569250c0f/core/google/cloud/iam.py#L71

Should return an empty set if no bindings are set for that role.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `core/google/cloud/iam.py`
Content:
```
1 # Copyright 2017 Google Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """Non-API-specific IAM policy definitions
15 
16 For allowed roles / permissions, see:
17 https://cloud.google.com/iam/docs/understanding-roles
18 """
19 
20 import collections
21 import warnings
22 
23 # Generic IAM roles
24 
25 OWNER_ROLE = 'roles/owner'
26 """Generic role implying all rights to an object."""
27 
28 EDITOR_ROLE = 'roles/editor'
29 """Generic role implying rights to modify an object."""
30 
31 VIEWER_ROLE = 'roles/viewer'
32 """Generic role implying rights to access an object."""
33 
34 _ASSIGNMENT_DEPRECATED_MSG = """\
35 Assigning to '{}' is deprecated.  Replace with 'policy[{}] = members."""
36 
37 
38 class Policy(collections.MutableMapping):
39     """IAM Policy
40 
41     See:
42     https://cloud.google.com/iam/reference/rest/v1/Policy
43 
44     :type etag: str
45     :param etag: ETag used to identify a unique of the policy
46 
47     :type version: int
48     :param version: unique version of the policy
49     """
50     _OWNER_ROLES = (OWNER_ROLE,)
51     """Roles mapped onto our ``owners`` attribute."""
52 
53     _EDITOR_ROLES = (EDITOR_ROLE,)
54     """Roles mapped onto our ``editors`` attribute."""
55 
56     _VIEWER_ROLES = (VIEWER_ROLE,)
57     """Roles mapped onto our ``viewers`` attribute."""
58 
59     def __init__(self, etag=None, version=None):
60         self.etag = etag
61         self.version = version
62         self._bindings = {}
63 
64     def __iter__(self):
65         return iter(self._bindings)
66 
67     def __len__(self):
68         return len(self._bindings)
69 
70     def __getitem__(self, key):
71         return self._bindings[key]
72 
73     def __setitem__(self, key, value):
74         self._bindings[key] = set(value)
75 
76     def __delitem__(self, key):
77         del self._bindings[key]
78 
79     @property
80     def owners(self):
81         """Legacy access to owner role."""
82         result = set()
83         for role in self._OWNER_ROLES:
84             for member in self._bindings.get(role, ()):
85                 result.add(member)
86         return frozenset(result)
87 
88     @owners.setter
89     def owners(self, value):
90         """Update owners."""
91         warnings.warn(
92             _ASSIGNMENT_DEPRECATED_MSG.format('owners', OWNER_ROLE),
93             DeprecationWarning)
94         self[OWNER_ROLE] = value
95 
96     @property
97     def editors(self):
98         """Legacy access to editor role."""
99         result = set()
100         for role in self._EDITOR_ROLES:
101             for member in self._bindings.get(role, ()):
102                 result.add(member)
103         return frozenset(result)
104 
105     @editors.setter
106     def editors(self, value):
107         """Update editors."""
108         warnings.warn(
109             _ASSIGNMENT_DEPRECATED_MSG.format('editors', EDITOR_ROLE),
110             DeprecationWarning)
111         self[EDITOR_ROLE] = value
112 
113     @property
114     def viewers(self):
115         """Legacy access to viewer role."""
116         result = set()
117         for role in self._VIEWER_ROLES:
118             for member in self._bindings.get(role, ()):
119                 result.add(member)
120         return frozenset(result)
121 
122     @viewers.setter
123     def viewers(self, value):
124         """Update viewers."""
125         warnings.warn(
126             _ASSIGNMENT_DEPRECATED_MSG.format('viewers', VIEWER_ROLE),
127             DeprecationWarning)
128         self[VIEWER_ROLE] = value
129 
130     @staticmethod
131     def user(email):
132         """Factory method for a user member.
133 
134         :type email: str
135         :param email: E-mail for this particular user.
136 
137         :rtype: str
138         :returns: A member string corresponding to the given user.
139         """
140         return 'user:%s' % (email,)
141 
142     @staticmethod
143     def service_account(email):
144         """Factory method for a service account member.
145 
146         :type email: str
147         :param email: E-mail for this particular service account.
148 
149         :rtype: str
150         :returns: A member string corresponding to the given service account.
151         """
152         return 'serviceAccount:%s' % (email,)
153 
154     @staticmethod
155     def group(email):
156         """Factory method for a group member.
157 
158         :type email: str
159         :param email: An id or e-mail for this particular group.
160 
161         :rtype: str
162         :returns: A member string corresponding to the given group.
163         """
164         return 'group:%s' % (email,)
165 
166     @staticmethod
167     def domain(domain):
168         """Factory method for a domain member.
169 
170         :type domain: str
171         :param domain: The domain for this member.
172 
173         :rtype: str
174         :returns: A member string corresponding to the given domain.
175         """
176         return 'domain:%s' % (domain,)
177 
178     @staticmethod
179     def all_users():
180         """Factory method for a member representing all users.
181 
182         :rtype: str
183         :returns: A member string representing all users.
184         """
185         return 'allUsers'
186 
187     @staticmethod
188     def authenticated_users():
189         """Factory method for a member representing all authenticated users.
190 
191         :rtype: str
192         :returns: A member string representing all authenticated users.
193         """
194         return 'allAuthenticatedUsers'
195 
196     @classmethod
197     def from_api_repr(cls, resource):
198         """Create a policy from the resource returned from the API.
199 
200         :type resource: dict
201         :param resource: resource returned from the ``getIamPolicy`` API.
202 
203         :rtype: :class:`Policy`
204         :returns: the parsed policy
205         """
206         version = resource.get('version')
207         etag = resource.get('etag')
208         policy = cls(etag, version)
209         for binding in resource.get('bindings', ()):
210             role = binding['role']
211             members = sorted(binding['members'])
212             policy[role] = members
213         return policy
214 
215     def to_api_repr(self):
216         """Construct a Policy resource.
217 
218         :rtype: dict
219         :returns: a resource to be passed to the ``setIamPolicy`` API.
220         """
221         resource = {}
222 
223         if self.etag is not None:
224             resource['etag'] = self.etag
225 
226         if self.version is not None:
227             resource['version'] = self.version
228 
229         if len(self._bindings) > 0:
230             bindings = resource['bindings'] = []
231             for role, members in sorted(self._bindings.items()):
232                 if len(members) > 0:
233                     bindings.append(
234                         {'role': role, 'members': sorted(set(members))})
235 
236             if len(bindings) == 0:
237                 del resource['bindings']
238 
239         return resource
240 
241 
242 collections.MutableMapping.register(Policy)
243
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/core/google/cloud/iam.py b/core/google/cloud/iam.py
--- a/core/google/cloud/iam.py
+++ b/core/google/cloud/iam.py
@@ -59,7 +59,7 @@
     def __init__(self, etag=None, version=None):
         self.etag = etag
         self.version = version
-        self._bindings = {}
+        self._bindings = collections.defaultdict(set)
 
     def __iter__(self):
         return iter(self._bindings)

{"golden_diff": "diff --git a/core/google/cloud/iam.py b/core/google/cloud/iam.py\n--- a/core/google/cloud/iam.py\n+++ b/core/google/cloud/iam.py\n@@ -59,7 +59,7 @@\n     def __init__(self, etag=None, version=None):\n         self.etag = etag\n         self.version = version\n-        self._bindings = {}\n+        self._bindings = collections.defaultdict(set)\n \n     def __iter__(self):\n         return iter(self._bindings)\n", "issue": "IAM policy should return an empty set of the bindings do not exist\nhttps://github.com/GoogleCloudPlatform/google-cloud-python/blob/bd9fdfba07fac63a91847628613928a569250c0f/core/google/cloud/iam.py#L71\r\n\r\nShould return an empty set if no bindings are set for that role.\n", "before_files": [{"content": "# Copyright 2017 Google Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Non-API-specific IAM policy definitions\n\nFor allowed roles / permissions, see:\nhttps://cloud.google.com/iam/docs/understanding-roles\n\"\"\"\n\nimport collections\nimport warnings\n\n# Generic IAM roles\n\nOWNER_ROLE = 'roles/owner'\n\"\"\"Generic role implying all rights to an object.\"\"\"\n\nEDITOR_ROLE = 'roles/editor'\n\"\"\"Generic role implying rights to modify an object.\"\"\"\n\nVIEWER_ROLE = 'roles/viewer'\n\"\"\"Generic role implying rights to access an object.\"\"\"\n\n_ASSIGNMENT_DEPRECATED_MSG = \"\"\"\\\nAssigning to '{}' is deprecated.  Replace with 'policy[{}] = members.\"\"\"\n\n\nclass Policy(collections.MutableMapping):\n    \"\"\"IAM Policy\n\n    See:\n    https://cloud.google.com/iam/reference/rest/v1/Policy\n\n    :type etag: str\n    :param etag: ETag used to identify a unique of the policy\n\n    :type version: int\n    :param version: unique version of the policy\n    \"\"\"\n    _OWNER_ROLES = (OWNER_ROLE,)\n    \"\"\"Roles mapped onto our ``owners`` attribute.\"\"\"\n\n    _EDITOR_ROLES = (EDITOR_ROLE,)\n    \"\"\"Roles mapped onto our ``editors`` attribute.\"\"\"\n\n    _VIEWER_ROLES = (VIEWER_ROLE,)\n    \"\"\"Roles mapped onto our ``viewers`` attribute.\"\"\"\n\n    def __init__(self, etag=None, version=None):\n        self.etag = etag\n        self.version = version\n        self._bindings = {}\n\n    def __iter__(self):\n        return iter(self._bindings)\n\n    def __len__(self):\n        return len(self._bindings)\n\n    def __getitem__(self, key):\n        return self._bindings[key]\n\n    def __setitem__(self, key, value):\n        self._bindings[key] = set(value)\n\n    def __delitem__(self, key):\n        del self._bindings[key]\n\n    @property\n    def owners(self):\n        \"\"\"Legacy access to owner role.\"\"\"\n        result = set()\n        for role in self._OWNER_ROLES:\n            for member in self._bindings.get(role, ()):\n                result.add(member)\n        return frozenset(result)\n\n    @owners.setter\n    def owners(self, value):\n        \"\"\"Update owners.\"\"\"\n        warnings.warn(\n            _ASSIGNMENT_DEPRECATED_MSG.format('owners', OWNER_ROLE),\n            DeprecationWarning)\n        self[OWNER_ROLE] = value\n\n    @property\n    def editors(self):\n        \"\"\"Legacy access to editor role.\"\"\"\n        result = set()\n        for role in self._EDITOR_ROLES:\n            for member in self._bindings.get(role, ()):\n                result.add(member)\n        return frozenset(result)\n\n    @editors.setter\n    def editors(self, value):\n        \"\"\"Update editors.\"\"\"\n        warnings.warn(\n            _ASSIGNMENT_DEPRECATED_MSG.format('editors', EDITOR_ROLE),\n            DeprecationWarning)\n        self[EDITOR_ROLE] = value\n\n    @property\n    def viewers(self):\n        \"\"\"Legacy access to viewer role.\"\"\"\n        result = set()\n        for role in self._VIEWER_ROLES:\n            for member in self._bindings.get(role, ()):\n                result.add(member)\n        return frozenset(result)\n\n    @viewers.setter\n    def viewers(self, value):\n        \"\"\"Update viewers.\"\"\"\n        warnings.warn(\n            _ASSIGNMENT_DEPRECATED_MSG.format('viewers', VIEWER_ROLE),\n            DeprecationWarning)\n        self[VIEWER_ROLE] = value\n\n    @staticmethod\n    def user(email):\n        \"\"\"Factory method for a user member.\n\n        :type email: str\n        :param email: E-mail for this particular user.\n\n        :rtype: str\n        :returns: A member string corresponding to the given user.\n        \"\"\"\n        return 'user:%s' % (email,)\n\n    @staticmethod\n    def service_account(email):\n        \"\"\"Factory method for a service account member.\n\n        :type email: str\n        :param email: E-mail for this particular service account.\n\n        :rtype: str\n        :returns: A member string corresponding to the given service account.\n        \"\"\"\n        return 'serviceAccount:%s' % (email,)\n\n    @staticmethod\n    def group(email):\n        \"\"\"Factory method for a group member.\n\n        :type email: str\n        :param email: An id or e-mail for this particular group.\n\n        :rtype: str\n        :returns: A member string corresponding to the given group.\n        \"\"\"\n        return 'group:%s' % (email,)\n\n    @staticmethod\n    def domain(domain):\n        \"\"\"Factory method for a domain member.\n\n        :type domain: str\n        :param domain: The domain for this member.\n\n        :rtype: str\n        :returns: A member string corresponding to the given domain.\n        \"\"\"\n        return 'domain:%s' % (domain,)\n\n    @staticmethod\n    def all_users():\n        \"\"\"Factory method for a member representing all users.\n\n        :rtype: str\n        :returns: A member string representing all users.\n        \"\"\"\n        return 'allUsers'\n\n    @staticmethod\n    def authenticated_users():\n        \"\"\"Factory method for a member representing all authenticated users.\n\n        :rtype: str\n        :returns: A member string representing all authenticated users.\n        \"\"\"\n        return 'allAuthenticatedUsers'\n\n    @classmethod\n    def from_api_repr(cls, resource):\n        \"\"\"Create a policy from the resource returned from the API.\n\n        :type resource: dict\n        :param resource: resource returned from the ``getIamPolicy`` API.\n\n        :rtype: :class:`Policy`\n        :returns: the parsed policy\n        \"\"\"\n        version = resource.get('version')\n        etag = resource.get('etag')\n        policy = cls(etag, version)\n        for binding in resource.get('bindings', ()):\n            role = binding['role']\n            members = sorted(binding['members'])\n            policy[role] = members\n        return policy\n\n    def to_api_repr(self):\n        \"\"\"Construct a Policy resource.\n\n        :rtype: dict\n        :returns: a resource to be passed to the ``setIamPolicy`` API.\n        \"\"\"\n        resource = {}\n\n        if self.etag is not None:\n            resource['etag'] = self.etag\n\n        if self.version is not None:\n            resource['version'] = self.version\n\n        if len(self._bindings) > 0:\n            bindings = resource['bindings'] = []\n            for role, members in sorted(self._bindings.items()):\n                if len(members) > 0:\n                    bindings.append(\n                        {'role': role, 'members': sorted(set(members))})\n\n            if len(bindings) == 0:\n                del resource['bindings']\n\n        return resource\n\n\ncollections.MutableMapping.register(Policy)\n", "path": "core/google/cloud/iam.py"}], "after_files": [{"content": "# Copyright 2017 Google Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Non-API-specific IAM policy definitions\n\nFor allowed roles / permissions, see:\nhttps://cloud.google.com/iam/docs/understanding-roles\n\"\"\"\n\nimport collections\nimport warnings\n\n# Generic IAM roles\n\nOWNER_ROLE = 'roles/owner'\n\"\"\"Generic role implying all rights to an object.\"\"\"\n\nEDITOR_ROLE = 'roles/editor'\n\"\"\"Generic role implying rights to modify an object.\"\"\"\n\nVIEWER_ROLE = 'roles/viewer'\n\"\"\"Generic role implying rights to access an object.\"\"\"\n\n_ASSIGNMENT_DEPRECATED_MSG = \"\"\"\\\nAssigning to '{}' is deprecated.  Replace with 'policy[{}] = members.\"\"\"\n\n\nclass Policy(collections.MutableMapping):\n    \"\"\"IAM Policy\n\n    See:\n    https://cloud.google.com/iam/reference/rest/v1/Policy\n\n    :type etag: str\n    :param etag: ETag used to identify a unique of the policy\n\n    :type version: int\n    :param version: unique version of the policy\n    \"\"\"\n    _OWNER_ROLES = (OWNER_ROLE,)\n    \"\"\"Roles mapped onto our ``owners`` attribute.\"\"\"\n\n    _EDITOR_ROLES = (EDITOR_ROLE,)\n    \"\"\"Roles mapped onto our ``editors`` attribute.\"\"\"\n\n    _VIEWER_ROLES = (VIEWER_ROLE,)\n    \"\"\"Roles mapped onto our ``viewers`` attribute.\"\"\"\n\n    def __init__(self, etag=None, version=None):\n        self.etag = etag\n        self.version = version\n        self._bindings = collections.defaultdict(set)\n\n    def __iter__(self):\n        return iter(self._bindings)\n\n    def __len__(self):\n        return len(self._bindings)\n\n    def __getitem__(self, key):\n        return self._bindings[key]\n\n    def __setitem__(self, key, value):\n        self._bindings[key] = set(value)\n\n    def __delitem__(self, key):\n        del self._bindings[key]\n\n    @property\n    def owners(self):\n        \"\"\"Legacy access to owner role.\"\"\"\n        result = set()\n        for role in self._OWNER_ROLES:\n            for member in self._bindings.get(role, ()):\n                result.add(member)\n        return frozenset(result)\n\n    @owners.setter\n    def owners(self, value):\n        \"\"\"Update owners.\"\"\"\n        warnings.warn(\n            _ASSIGNMENT_DEPRECATED_MSG.format('owners', OWNER_ROLE),\n            DeprecationWarning)\n        self[OWNER_ROLE] = value\n\n    @property\n    def editors(self):\n        \"\"\"Legacy access to editor role.\"\"\"\n        result = set()\n        for role in self._EDITOR_ROLES:\n            for member in self._bindings.get(role, ()):\n                result.add(member)\n        return frozenset(result)\n\n    @editors.setter\n    def editors(self, value):\n        \"\"\"Update editors.\"\"\"\n        warnings.warn(\n            _ASSIGNMENT_DEPRECATED_MSG.format('editors', EDITOR_ROLE),\n            DeprecationWarning)\n        self[EDITOR_ROLE] = value\n\n    @property\n    def viewers(self):\n        \"\"\"Legacy access to viewer role.\"\"\"\n        result = set()\n        for role in self._VIEWER_ROLES:\n            for member in self._bindings.get(role, ()):\n                result.add(member)\n        return frozenset(result)\n\n    @viewers.setter\n    def viewers(self, value):\n        \"\"\"Update viewers.\"\"\"\n        warnings.warn(\n            _ASSIGNMENT_DEPRECATED_MSG.format('viewers', VIEWER_ROLE),\n            DeprecationWarning)\n        self[VIEWER_ROLE] = value\n\n    @staticmethod\n    def user(email):\n        \"\"\"Factory method for a user member.\n\n        :type email: str\n        :param email: E-mail for this particular user.\n\n        :rtype: str\n        :returns: A member string corresponding to the given user.\n        \"\"\"\n        return 'user:%s' % (email,)\n\n    @staticmethod\n    def service_account(email):\n        \"\"\"Factory method for a service account member.\n\n        :type email: str\n        :param email: E-mail for this particular service account.\n\n        :rtype: str\n        :returns: A member string corresponding to the given service account.\n        \"\"\"\n        return 'serviceAccount:%s' % (email,)\n\n    @staticmethod\n    def group(email):\n        \"\"\"Factory method for a group member.\n\n        :type email: str\n        :param email: An id or e-mail for this particular group.\n\n        :rtype: str\n        :returns: A member string corresponding to the given group.\n        \"\"\"\n        return 'group:%s' % (email,)\n\n    @staticmethod\n    def domain(domain):\n        \"\"\"Factory method for a domain member.\n\n        :type domain: str\n        :param domain: The domain for this member.\n\n        :rtype: str\n        :returns: A member string corresponding to the given domain.\n        \"\"\"\n        return 'domain:%s' % (domain,)\n\n    @staticmethod\n    def all_users():\n        \"\"\"Factory method for a member representing all users.\n\n        :rtype: str\n        :returns: A member string representing all users.\n        \"\"\"\n        return 'allUsers'\n\n    @staticmethod\n    def authenticated_users():\n        \"\"\"Factory method for a member representing all authenticated users.\n\n        :rtype: str\n        :returns: A member string representing all authenticated users.\n        \"\"\"\n        return 'allAuthenticatedUsers'\n\n    @classmethod\n    def from_api_repr(cls, resource):\n        \"\"\"Create a policy from the resource returned from the API.\n\n        :type resource: dict\n        :param resource: resource returned from the ``getIamPolicy`` API.\n\n        :rtype: :class:`Policy`\n        :returns: the parsed policy\n        \"\"\"\n        version = resource.get('version')\n        etag = resource.get('etag')\n        policy = cls(etag, version)\n        for binding in resource.get('bindings', ()):\n            role = binding['role']\n            members = sorted(binding['members'])\n            policy[role] = members\n        return policy\n\n    def to_api_repr(self):\n        \"\"\"Construct a Policy resource.\n\n        :rtype: dict\n        :returns: a resource to be passed to the ``setIamPolicy`` API.\n        \"\"\"\n        resource = {}\n\n        if self.etag is not None:\n            resource['etag'] = self.etag\n\n        if self.version is not None:\n            resource['version'] = self.version\n\n        if len(self._bindings) > 0:\n            bindings = resource['bindings'] = []\n            for role, members in sorted(self._bindings.items()):\n                if len(members) > 0:\n                    bindings.append(\n                        {'role': role, 'members': sorted(set(members))})\n\n            if len(bindings) == 0:\n                del resource['bindings']\n\n        return resource\n\n\ncollections.MutableMapping.register(Policy)\n", "path": "core/google/cloud/iam.py"}]}