prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Vision: Single feature functions generated by cloud vision client library does not support parameter max_results
  As specified in [the gRPC reference](https://cloud.google.com/vision/docs/reference/rpc/google.cloud.vision.v1#google.cloud.vision.v1.AnnotateImageRequest), AnnotateImageRequest message have three fields, _image_, _features[]_ and _image_context_, in which the _features[]_ field determines what feature user is request (_type_) and max number of returned results (_max_results_). The code for generating single-feature functions (for example, _face_detection()_), however, does not allow user to specify _max_results_:
  
  ```
  feature_value = {'type': enum.__dict__[feature]}
  def inner(self, image, options=None, **kwargs):
          request = dict(
              image=image,
              features=[feature_value],
              **kwargs
          )
          return self.annotate_image(request, options=options)
  ```
  
  Reported in https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1173
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `vision/google/cloud/vision_helpers/decorators.py`
  Content:
  ```
  1 # Copyright 2017, Google LLC All rights reserved.
  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 
  15 from __future__ import absolute_import
  16 
  17 
  18 def add_single_feature_methods(cls):
  19     """Custom decorator intended for :class:`~vision.helpers.VisionHelpers`.
  20 
  21     This metaclass adds a `{feature}` method for every feature
  22     defined on the Feature enum.
  23     """
  24     # Sanity check: This only makes sense if we are building the GAPIC
  25     # subclass and have enums already attached.
  26     if not hasattr(cls, 'enums'):
  27         return cls
  28 
  29     # Iterate over the Feature.Type enum and add get a list of
  30     # features which will receive single-feature detection methods.
  31     features = [k for k in cls.enums.Feature.Type.__dict__.keys()
  32                 if k.replace('_', '').isalpha() and k.upper() == k]
  33 
  34     # Add each single-feature method to the class.
  35     for feature in features:
  36         # Sanity check: Do not make a method for the falsy feature.
  37         if feature == 'TYPE_UNSPECIFIED':
  38             continue
  39 
  40         # Assign the appropriate metadata to the function.
  41         detect = _create_single_feature_method(feature, cls.enums.Feature.Type)
  42 
  43         # Assign a qualified name to the function, and perform module
  44         # replacement on the docstring.
  45         detect.__qualname__ = '{cls}.{name}'.format(
  46             cls=cls.__name__,
  47             name=detect.__name__,
  48         )
  49         detect.__doc__ = detect.__doc__.format(
  50             module=cls.__module__,
  51         )
  52 
  53         # Place the function on the class being created.
  54         setattr(cls, detect.__name__, detect)
  55 
  56     # Done; return the class.
  57     return cls
  58 
  59 
  60 def _create_single_feature_method(feature, enum):
  61     """Return a function that will detect a single feature.
  62 
  63     Args:
  64         feature (str): A specific feature defined as an attribute on
  65             :class:`~enums.Feature.Type`.
  66         enum (class): The :class:`~enums.Feature.Type` class.
  67 
  68     Returns:
  69         function: A helper function to detect just that feature.
  70     """
  71     # Define the function properties.
  72     fx_name = feature.lower()
  73     if 'detection' in fx_name:
  74         fx_doc = 'Perform {0}.'.format(fx_name.replace('_', ' '))
  75     else:
  76         fx_doc = 'Return {desc} information.'.format(
  77             desc=fx_name.replace('_', ' '),
  78         )
  79 
  80     # Provide a complete docstring with argument and return value
  81     # information.
  82     fx_doc += """
  83 
  84     Args:
  85         image (:class:`~.{module}.types.Image`): The image to analyze.
  86         options (:class:`google.gax.CallOptions`): Overrides the
  87             default settings for this call, e.g, timeout, retries, etc.
  88         kwargs (dict): Additional properties to be set on the
  89             :class:`~.{module}.types.AnnotateImageRequest`.
  90 
  91     Returns:
  92         :class:`~.{module}.types.AnnotateImageResponse`: The API response.
  93     """
  94 
  95     # Get the actual feature value to send.
  96     feature_value = {'type': enum.__dict__[feature]}
  97 
  98     # Define the function to be returned.
  99     def inner(self, image, retry=None, timeout=None, **kwargs):
  100         """Return a single feature annotation for the given image.
  101 
  102         Intended for use with functools.partial, to create the particular
  103         single-feature methods.
  104         """
  105         request = dict(
  106             image=image,
  107             features=[feature_value],
  108             **kwargs
  109         )
  110         return self.annotate_image(request, retry=retry, timeout=timeout)
  111 
  112     # Set the appropriate function metadata.
  113     inner.__name__ = fx_name
  114     inner.__doc__ = fx_doc
  115 
  116     # Return the final function.
  117     return inner
  118
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/vision/google/cloud/vision_helpers/decorators.py b/vision/google/cloud/vision_helpers/decorators.py
  --- a/vision/google/cloud/vision_helpers/decorators.py
  +++ b/vision/google/cloud/vision_helpers/decorators.py
  @@ -83,8 +83,11 @@
   
       Args:
           image (:class:`~.{module}.types.Image`): The image to analyze.
  -        options (:class:`google.gax.CallOptions`): Overrides the
  -            default settings for this call, e.g, timeout, retries, etc.
  +        max_results (int):
  +            Number of results to return, does not apply for
  +            TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.
  +        retry (int): Number of retries to do before giving up.
  +        timeout (int): Number of seconds before timing out.
           kwargs (dict): Additional properties to be set on the
               :class:`~.{module}.types.AnnotateImageRequest`.
   
  @@ -96,18 +99,23 @@
       feature_value = {'type': enum.__dict__[feature]}
   
       # Define the function to be returned.
  -    def inner(self, image, retry=None, timeout=None, **kwargs):
  +    def inner(self, image, max_results=None,
  +              retry=None, timeout=None, **kwargs):
           """Return a single feature annotation for the given image.
   
           Intended for use with functools.partial, to create the particular
           single-feature methods.
           """
  +        copied_features = feature_value.copy()
  +        if max_results is not None:
  +            copied_features['max_results'] = max_results
           request = dict(
               image=image,
  -            features=[feature_value],
  +            features=[copied_features],
               **kwargs
           )
  -        return self.annotate_image(request, retry=retry, timeout=timeout)
  +        response = self.annotate_image(request, retry=retry, timeout=timeout)
  +        return response
   
       # Set the appropriate function metadata.
       inner.__name__ = fx_name
  
verification_info: {"golden_diff": "diff --git a/vision/google/cloud/vision_helpers/decorators.py b/vision/google/cloud/vision_helpers/decorators.py\n--- a/vision/google/cloud/vision_helpers/decorators.py\n+++ b/vision/google/cloud/vision_helpers/decorators.py\n@@ -83,8 +83,11 @@\n \n     Args:\n         image (:class:`~.{module}.types.Image`): The image to analyze.\n-        options (:class:`google.gax.CallOptions`): Overrides the\n-            default settings for this call, e.g, timeout, retries, etc.\n+        max_results (int):\n+            Number of results to return, does not apply for\n+            TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.\n+        retry (int): Number of retries to do before giving up.\n+        timeout (int): Number of seconds before timing out.\n         kwargs (dict): Additional properties to be set on the\n             :class:`~.{module}.types.AnnotateImageRequest`.\n \n@@ -96,18 +99,23 @@\n     feature_value = {'type': enum.__dict__[feature]}\n \n     # Define the function to be returned.\n-    def inner(self, image, retry=None, timeout=None, **kwargs):\n+    def inner(self, image, max_results=None,\n+              retry=None, timeout=None, **kwargs):\n         \"\"\"Return a single feature annotation for the given image.\n \n         Intended for use with functools.partial, to create the particular\n         single-feature methods.\n         \"\"\"\n+        copied_features = feature_value.copy()\n+        if max_results is not None:\n+            copied_features['max_results'] = max_results\n         request = dict(\n             image=image,\n-            features=[feature_value],\n+            features=[copied_features],\n             **kwargs\n         )\n-        return self.annotate_image(request, retry=retry, timeout=timeout)\n+        response = self.annotate_image(request, retry=retry, timeout=timeout)\n+        return response\n \n     # Set the appropriate function metadata.\n     inner.__name__ = fx_name\n", "issue": "Vision: Single feature functions generated by cloud vision client library does not support parameter max_results\nAs specified in [the gRPC reference](https://cloud.google.com/vision/docs/reference/rpc/google.cloud.vision.v1#google.cloud.vision.v1.AnnotateImageRequest), AnnotateImageRequest message have three fields, _image_, _features[]_ and _image_context_, in which the _features[]_ field determines what feature user is request (_type_) and max number of returned results (_max_results_). The code for generating single-feature functions (for example, _face_detection()_), however, does not allow user to specify _max_results_:\r\n\r\n```\r\nfeature_value = {'type': enum.__dict__[feature]}\r\ndef inner(self, image, options=None, **kwargs):\r\n        request = dict(\r\n            image=image,\r\n            features=[feature_value],\r\n            **kwargs\r\n        )\r\n        return self.annotate_image(request, options=options)\r\n```\r\n\r\nReported in https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1173\n", "before_files": [{"content": "# Copyright 2017, Google LLC All rights reserved.\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\nfrom __future__ import absolute_import\n\n\ndef add_single_feature_methods(cls):\n    \"\"\"Custom decorator intended for :class:`~vision.helpers.VisionHelpers`.\n\n    This metaclass adds a `{feature}` method for every feature\n    defined on the Feature enum.\n    \"\"\"\n    # Sanity check: This only makes sense if we are building the GAPIC\n    # subclass and have enums already attached.\n    if not hasattr(cls, 'enums'):\n        return cls\n\n    # Iterate over the Feature.Type enum and add get a list of\n    # features which will receive single-feature detection methods.\n    features = [k for k in cls.enums.Feature.Type.__dict__.keys()\n                if k.replace('_', '').isalpha() and k.upper() == k]\n\n    # Add each single-feature method to the class.\n    for feature in features:\n        # Sanity check: Do not make a method for the falsy feature.\n        if feature == 'TYPE_UNSPECIFIED':\n            continue\n\n        # Assign the appropriate metadata to the function.\n        detect = _create_single_feature_method(feature, cls.enums.Feature.Type)\n\n        # Assign a qualified name to the function, and perform module\n        # replacement on the docstring.\n        detect.__qualname__ = '{cls}.{name}'.format(\n            cls=cls.__name__,\n            name=detect.__name__,\n        )\n        detect.__doc__ = detect.__doc__.format(\n            module=cls.__module__,\n        )\n\n        # Place the function on the class being created.\n        setattr(cls, detect.__name__, detect)\n\n    # Done; return the class.\n    return cls\n\n\ndef _create_single_feature_method(feature, enum):\n    \"\"\"Return a function that will detect a single feature.\n\n    Args:\n        feature (str): A specific feature defined as an attribute on\n            :class:`~enums.Feature.Type`.\n        enum (class): The :class:`~enums.Feature.Type` class.\n\n    Returns:\n        function: A helper function to detect just that feature.\n    \"\"\"\n    # Define the function properties.\n    fx_name = feature.lower()\n    if 'detection' in fx_name:\n        fx_doc = 'Perform {0}.'.format(fx_name.replace('_', ' '))\n    else:\n        fx_doc = 'Return {desc} information.'.format(\n            desc=fx_name.replace('_', ' '),\n        )\n\n    # Provide a complete docstring with argument and return value\n    # information.\n    fx_doc += \"\"\"\n\n    Args:\n        image (:class:`~.{module}.types.Image`): The image to analyze.\n        options (:class:`google.gax.CallOptions`): Overrides the\n            default settings for this call, e.g, timeout, retries, etc.\n        kwargs (dict): Additional properties to be set on the\n            :class:`~.{module}.types.AnnotateImageRequest`.\n\n    Returns:\n        :class:`~.{module}.types.AnnotateImageResponse`: The API response.\n    \"\"\"\n\n    # Get the actual feature value to send.\n    feature_value = {'type': enum.__dict__[feature]}\n\n    # Define the function to be returned.\n    def inner(self, image, retry=None, timeout=None, **kwargs):\n        \"\"\"Return a single feature annotation for the given image.\n\n        Intended for use with functools.partial, to create the particular\n        single-feature methods.\n        \"\"\"\n        request = dict(\n            image=image,\n            features=[feature_value],\n            **kwargs\n        )\n        return self.annotate_image(request, retry=retry, timeout=timeout)\n\n    # Set the appropriate function metadata.\n    inner.__name__ = fx_name\n    inner.__doc__ = fx_doc\n\n    # Return the final function.\n    return inner\n", "path": "vision/google/cloud/vision_helpers/decorators.py"}], "after_files": [{"content": "# Copyright 2017, Google LLC All rights reserved.\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\nfrom __future__ import absolute_import\n\n\ndef add_single_feature_methods(cls):\n    \"\"\"Custom decorator intended for :class:`~vision.helpers.VisionHelpers`.\n\n    This metaclass adds a `{feature}` method for every feature\n    defined on the Feature enum.\n    \"\"\"\n    # Sanity check: This only makes sense if we are building the GAPIC\n    # subclass and have enums already attached.\n    if not hasattr(cls, 'enums'):\n        return cls\n\n    # Iterate over the Feature.Type enum and add get a list of\n    # features which will receive single-feature detection methods.\n    features = [k for k in cls.enums.Feature.Type.__dict__.keys()\n                if k.replace('_', '').isalpha() and k.upper() == k]\n\n    # Add each single-feature method to the class.\n    for feature in features:\n        # Sanity check: Do not make a method for the falsy feature.\n        if feature == 'TYPE_UNSPECIFIED':\n            continue\n\n        # Assign the appropriate metadata to the function.\n        detect = _create_single_feature_method(feature, cls.enums.Feature.Type)\n\n        # Assign a qualified name to the function, and perform module\n        # replacement on the docstring.\n        detect.__qualname__ = '{cls}.{name}'.format(\n            cls=cls.__name__,\n            name=detect.__name__,\n        )\n        detect.__doc__ = detect.__doc__.format(\n            module=cls.__module__,\n        )\n\n        # Place the function on the class being created.\n        setattr(cls, detect.__name__, detect)\n\n    # Done; return the class.\n    return cls\n\n\ndef _create_single_feature_method(feature, enum):\n    \"\"\"Return a function that will detect a single feature.\n\n    Args:\n        feature (str): A specific feature defined as an attribute on\n            :class:`~enums.Feature.Type`.\n        enum (class): The :class:`~enums.Feature.Type` class.\n\n    Returns:\n        function: A helper function to detect just that feature.\n    \"\"\"\n    # Define the function properties.\n    fx_name = feature.lower()\n    if 'detection' in fx_name:\n        fx_doc = 'Perform {0}.'.format(fx_name.replace('_', ' '))\n    else:\n        fx_doc = 'Return {desc} information.'.format(\n            desc=fx_name.replace('_', ' '),\n        )\n\n    # Provide a complete docstring with argument and return value\n    # information.\n    fx_doc += \"\"\"\n\n    Args:\n        image (:class:`~.{module}.types.Image`): The image to analyze.\n        max_results (int):\n            Number of results to return, does not apply for\n            TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.\n        retry (int): Number of retries to do before giving up.\n        timeout (int): Number of seconds before timing out.\n        kwargs (dict): Additional properties to be set on the\n            :class:`~.{module}.types.AnnotateImageRequest`.\n\n    Returns:\n        :class:`~.{module}.types.AnnotateImageResponse`: The API response.\n    \"\"\"\n\n    # Get the actual feature value to send.\n    feature_value = {'type': enum.__dict__[feature]}\n\n    # Define the function to be returned.\n    def inner(self, image, max_results=None,\n              retry=None, timeout=None, **kwargs):\n        \"\"\"Return a single feature annotation for the given image.\n\n        Intended for use with functools.partial, to create the particular\n        single-feature methods.\n        \"\"\"\n        copied_features = feature_value.copy()\n        if max_results is not None:\n            copied_features['max_results'] = max_results\n        request = dict(\n            image=image,\n            features=[copied_features],\n            **kwargs\n        )\n        response = self.annotate_image(request, retry=retry, timeout=timeout)\n        return response\n\n    # Set the appropriate function metadata.\n    inner.__name__ = fx_name\n    inner.__doc__ = fx_doc\n\n    # Return the final function.\n    return inner\n", "path": "vision/google/cloud/vision_helpers/decorators.py"}]}