anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: aws/chalice
Issue: Packager assumes wheel to be installed

Took me a while to figure out why Chalice fails to build my deployment package properly in one environment, but not the other. Funnily enough while I was trying to pin all transitive dependencies :(

Chalice appears to use [wheel](https://github.com/aws/chalice/blob/9fe9ddc0423acd202c7e3533b74d14691336d8f7/chalice/deploy/packager.py#L693) regardless of whether wheel is installed in the environment. Should wheel be a setup requirement? Or perhaps include a warning in the "Could not install dependencies..." message?

```
$ python -m venv v1
$ source v1/bin/activate
$ pip install chalice  # wheel not installed
$ chalice new-project v1-test
$ cd v1-test
$ echo "markupsafe" >> requirements.txt
$ chalice package out
Creating deployment package.

Could not install dependencies:
markupsafe==1.0
You will have to build these yourself and vendor them in
the chalice vendor folder.

Your deployment will continue but may not work correctly
if missing dependencies are not present. For more information:
http://chalice.readthedocs.io/en/latest/topics/packaging.html

$ pip install wheel

$ chalice package out       
Creating deployment package.
# Success!
```

Changed files:
setup.py

diff --git a/setup.py b/setup.py
index 535d52a..81e86c3 100644
--- a/setup.py
+++ b/setup.py
@@ -15,6 +15,8 @@ install_requires = [
     'attrs==17.4.0',
     'enum-compat>=0.0.2',
     'jmespath>=0.9.3,<1.0.0',
+    'wheel',
+    'setuptools'
 ]
 
 setup(
Repository: aws/chalice
Issue: Fail to analyze list comprehension code

Chalice does not deploy below code with error message 'key_name'.
If I change the code from item['payload'][key_name] to item['payload']['data'], it works well.

I have used version 1.0.0b1.

```python
@app.route('/data/{node_name}', methods=['GET'], cors=True, authorizer=authorizer)
def retrieve_data(node_name):
    key_name = 'data'
    response['Items'] = [
        { 'Timestamp' : 10, 'payload' : { 'data' : 1}},
        { 'Timestamp' : 11, 'payload' : { 'data' : 2}}
    ]
    stamp = [item['Timestamp'] for item in response['Items']]
    temps = [item['payload'][key_name] for item in response['Items']]
    hums = [item['payload'][key_name] for item in response['Items']]
```


Changed files:
tests/unit/test_analyzer.py, chalice/analyzer.py

diff --git a/chalice/analyzer.py b/chalice/analyzer.py
index c270aac..2b41f5e 100644
--- a/chalice/analyzer.py
+++ b/chalice/analyzer.py
@@ -565,7 +565,8 @@ class SymbolTableTypeInfer(ast.NodeVisitor):
 
     def _handle_comprehension(self, node, comprehension_type):
         # type: (Union[ast.ListComp, ast.GeneratorExp], str) -> None
-        child_scope = self._get_matching_sub_namespace(comprehension_type)
+        child_scope = self._get_matching_sub_namespace(
+            comprehension_type, node.lineno)
         if child_scope is None:
             # If there's no child scope (listcomps in py2) then we can
             # just analyze the node.elt node in the current scope instead
@@ -577,11 +578,11 @@ class SymbolTableTypeInfer(ast.NodeVisitor):
             ParsedCode(node.elt, child_table), self._binder)
         child_infer.bind_types()
 
-    def _get_matching_sub_namespace(self, name):
-        # type: (str) -> symtable.SymbolTable
+    def _get_matching_sub_namespace(self, name, lineno):
+        # type: (str, int) -> symtable.SymbolTable
         namespaces = [
             t for t in self._symbol_table.get_sub_namespaces()
-            if t.get_name() == name]
+            if t.get_name() == name and t.get_lineno() == lineno]
         if not namespaces:
             return
         # We're making a simplification and using the genexpr subnamespace.
diff --git a/tests/unit/test_analyzer.py b/tests/unit/test_analyzer.py
index 881a33c..c00ae0d 100644
--- a/tests/unit/test_analyzer.py
+++ b/tests/unit/test_analyzer.py
@@ -457,6 +457,17 @@ def test_can_handle_list_expr_with_api_calls():
     """) == {'dynamodb': set(['list_tables'])}
 
 
+def test_can_handle_multiple_listcomps():
+    assert aws_calls("""\\
+        bar_key = 'bar'
+        baz_key = 'baz'
+        items = [{'foo': 'sun', 'bar': 'moon', 'baz': 'stars'}]
+        foos = [t['foo'] for i in items]
+        bars = [t[bar_key] for t in items]
+        bazs = [t[baz_key] for t in items]
+    """) == {}
+
+
 # def test_can_handle_dict_comp():
 #     assert aws_calls("""\\
 #         import boto3
Repository: aws/chalice
Issue: Adding Content-Type to Response produced 2 Content-Type headers

`curl -v localhost:8000`
`>GET / HTTP/1.1`
`>Host: localhost:8000`
`>User-Agent: curl/7.52.1`
` >Accept: */*`
 
` HTTP 1.0, assume close after body`
`< HTTP/1.0 200 OK`
`< Server: BaseHTTP/0.3 Python/2.7.12`
`< Date: Thu, 27 Apr 2017 20:30:54 GMT`
`< Content-Length: 83`
`< Content-Type: application/xml`
`< Content-Type: application/xml`
`< `
` Curl_http_done: called premature == 0`
` Closing connection 0`
`<?xml version="1.0" encoding="UTF-8"?><Response><Say>Hello World</Say>`


Changed files:
chalice/local.py, tests/unit/test_local.py

diff --git a/chalice/local.py b/chalice/local.py
index 92bd8eb..dc2da48 100644
--- a/chalice/local.py
+++ b/chalice/local.py
@@ -120,9 +120,9 @@ class ChaliceRequestHandler(BaseHTTPRequestHandler):
         # type: (EventType, Dict[str, Any]) -> None
         self.send_response(response['statusCode'])
         self.send_header('Content-Length', str(len(response['body'])))
-        self.send_header(
-            'Content-Type',
-            response['headers'].get('Content-Type', 'application/json'))
+        content_type = response['headers'].pop(
+            'Content-Type', 'application/json')
+        self.send_header('Content-Type', content_type)
         headers = response['headers']
         for header in headers:
             self.send_header(header, headers[header])
diff --git a/tests/unit/test_local.py b/tests/unit/test_local.py
index 462fe09..914ddc9 100644
--- a/tests/unit/test_local.py
+++ b/tests/unit/test_local.py
@@ -1,4 +1,5 @@
 from chalice import local, BadRequestError
+from chalice import Response
 import json
 import decimal
 import pytest
@@ -66,6 +67,12 @@ def sample_app():
     def query_string():
         return demo.current_request.query_params
 
+    @demo.route('/custom-response')
+    def custom_response():
+        return Response(body='text',
+                        status_code=200,
+                        headers={'Content-Type': 'text/plain'})
+
     return demo
 
 
@@ -187,6 +194,16 @@ def test_querystring_is_mapped(handler):
     assert _get_body_from_response_stream(handler) == {'a': 'b', 'c': 'd'}
 
 
+def test_content_type_included_once(handler):
+    set_current_request(handler, method='GET', path='/custom-response')
+    handler.do_GET()
+    value = handler.wfile.getvalue()
+    response_lines = value.splitlines()
+    content_header_lines = [line for line in response_lines
+                            if line.startswith('Content-Type')]
+    assert len(content_header_lines) == 1
+
+
 @pytest.mark.parametrize('actual_url,matched_url', [
     ('/foo', '/foo'),
     ('/foo/bar', '/foo/bar'),
Repository: aws/chalice
Issue: @app.schedule No longer supports Rate/Cron object expression

A recent commit (afd23d7d729f8383033fe3851bc1de5effd1f22f), added types to the various decorators.  In particular, the `@app.schedule` decorator requires `expression` to be a `str`, which means that it no longer accepts the object type `Rate` or `Cron`.

I used to be able to do this (and the [Chalice documentation shows this example as well](https://aws.github.io/chalice/topics/events.html#scheduled-events))
```python
@app.schedule(Rate(1, unit=Rate.HOURS), name=f"send_call_reminders-{ENV}")
```
Now, I have to add a `to_string()` call as follows:
```python
@app.schedule(Rate(1, unit=Rate.HOURS).to_string(), name=f"send_call_reminders-{ENV}")
```

I'm thinking the type for the `schedule` decorator should probably be `Union[str, ScheduleExpression]`.

Changed files:
chalice/app.py

diff --git a/chalice/app.py b/chalice/app.py
index 5a477e8..30ef112 100644
--- a/chalice/app.py
+++ b/chalice/app.py
@@ -787,7 +787,8 @@ class DecoratorAPI(object):
             registration_kwargs={'event_pattern': event_pattern}
         )
 
-    def schedule(self, expression: str, name: Optional[str] = None,
+    def schedule(self, expression: Union[str, 'ScheduleExpression'],
+                 name: Optional[str] = None,
                  description: str = '') -> Callable[..., Any]:
         return self._create_registration_function(
             handler_type='schedule',