We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pre_checkout_query does not store bot.

### Steps to reproduce
- On a PreChecoutQueryHandler, get the PreCheckoutQuery object update.pre_checkout_query

- Try to answer it, bot has not been set:

  File "/home/folarte/sexychat/nor  File "/home/folarte/sexychat/normalstate.py", line 998, in on_pcoq
    pcoq.answer(ok=True)
  File "/home/folarte/venv-sxc/local/lib/python3.6/site-packages/telegram/payment/precheckoutquery.py", line 115, in answer
    return self.bot.answer_pre_checkout_query(self.id, *args, **kwargs)
AttributeError: 'NoneType' object has no attribute 'answer_pre_checkout_query'
malstate.py", line 998, in on_pcoq
    pcoq.answer(ok=True)
  File "/home/folarte/venv-sxc/local/lib/python3.6/site-packages/telegram/payment/precheckoutquery.py", line 115, in answer
    return self.bot.answer_pre_checkout_query(self.id, *args, **kwargs)
AttributeError: 'NoneType' object has no attribute 'answer_pre_checkout_query'

### Expected behaviour

pcoq.bot should contain the bot object.

### Actual behaviour

bot object is not set. Thi is due to the de_json function being:

    @classmethod
    def de_json(cls, data, bot):
        if not data:
            return None

        data = super(PreCheckoutQuery, cls).de_json(data, bot)

        data['from_user'] = User.de_json(data.pop('from'), bot)
	data['order_info'] = OrderInfo.de_json(data.get('order_info'), bot)

        return cls(**data)

When the last call should pass the bot to the constructor, as done in the callbackquery object:

        return cls(bot=bot, **data)

When editing the line to these, it works fine.

Do not know GIT, can try to do it, but it is a trivial fix, probably a typo.

### Configuration

Amazon Linux, aws instance.

$ python -m telegram
python-telegram-bot 9.0.0
certifi 2017.11.05
future 0.16.0
Python 3.6.2 (default, Nov  2 2017, 19:34:31)  [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `telegram/payment/precheckoutquery.py`
Content:
```
1 #!/usr/bin/env python
2 #
3 # A library that provides a Python interface to the Telegram Bot API
4 # Copyright (C) 2015-2017
5 # Leandro Toledo de Souza <devs@python-telegram-bot.org>
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Lesser Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Lesser Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser Public License
18 # along with this program.  If not, see [http://www.gnu.org/licenses/].
19 """This module contains an object that represents a Telegram PreCheckoutQuery."""
20 
21 from telegram import TelegramObject, User, OrderInfo
22 
23 
24 class PreCheckoutQuery(TelegramObject):
25     """This object contains information about an incoming pre-checkout query.
26 
27     Note:
28         * In Python `from` is a reserved word, use `from_user` instead.
29 
30     Attributes:
31         id (:obj:`str`): Unique query identifier.
32         from_user (:class:`telegram.User`): User who sent the query.
33         currency (:obj:`str`): Three-letter ISO 4217 currency code.
34         total_amount (:obj:`int`): Total price in the smallest units of the currency.
35         invoice_payload (:obj:`str`): Bot specified invoice payload.
36         shipping_option_id (:obj:`str`): Optional. Identifier of the shipping option chosen by the
37             user.
38         order_info (:class:`telegram.OrderInfo`): Optional. Order info provided by the user.
39         bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods.
40 
41     Args:
42         id (:obj:`str`): Unique query identifier.
43         from_user (:class:`telegram.User`): User who sent the query.
44         currency (:obj:`str`): Three-letter ISO 4217 currency code
45         total_amount (:obj:`int`): Total price in the smallest units of the currency (integer, not
46             float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp
47             parameter in currencies.json, it shows the number of digits past the decimal point for
48             each currency (2 for the majority of currencies).
49         invoice_payload (:obj:`str`): Bot specified invoice payload.
50         shipping_option_id (:obj:`str`, optional): Identifier of the shipping option chosen by the
51             user.
52         order_info (:class:`telegram.OrderInfo`, optional): Order info provided by the user.
53         bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods.
54         **kwargs (:obj:`dict`): Arbitrary keyword arguments.
55 
56     """
57 
58     def __init__(self,
59                  id,
60                  from_user,
61                  currency,
62                  total_amount,
63                  invoice_payload,
64                  shipping_option_id=None,
65                  order_info=None,
66                  bot=None,
67                  **kwargs):
68         self.id = id
69         self.from_user = from_user
70         self.currency = currency
71         self.total_amount = total_amount
72         self.invoice_payload = invoice_payload
73         self.shipping_option_id = shipping_option_id
74         self.order_info = order_info
75 
76         self.bot = bot
77 
78         self._id_attrs = (self.id,)
79 
80     @classmethod
81     def de_json(cls, data, bot):
82         if not data:
83             return None
84 
85         data = super(PreCheckoutQuery, cls).de_json(data, bot)
86 
87         data['from_user'] = User.de_json(data.pop('from'), bot)
88         data['order_info'] = OrderInfo.de_json(data.get('order_info'), bot)
89 
90         return cls(**data)
91 
92     def to_dict(self):
93         data = super(PreCheckoutQuery, self).to_dict()
94 
95         data['from'] = data.pop('from_user', None)
96 
97         return data
98 
99     def answer(self, *args, **kwargs):
100         """Shortcut for::
101 
102             bot.answer_pre_checkout_query(update.pre_checkout_query.id, *args, **kwargs)
103 
104         Args:
105             ok (:obj:`bool`): Specify True if everything is alright (goods are available, etc.) and
106                 the bot is ready to proceed with the order. Use False if there are any problems.
107             error_message (:obj:`str`, optional): Required if ok is False. Error message in human
108                 readable form that explains the reason for failure to proceed with the checkout
109                 (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you
110                 were busy filling out your payment details. Please choose a different color or
111                 garment!"). Telegram will display this message to the user.
112             **kwargs (:obj:`dict`): Arbitrary keyword arguments.
113 
114         """
115         return self.bot.answer_pre_checkout_query(self.id, *args, **kwargs)
116
```
--- 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/telegram/payment/precheckoutquery.py b/telegram/payment/precheckoutquery.py
--- a/telegram/payment/precheckoutquery.py
+++ b/telegram/payment/precheckoutquery.py
@@ -87,7 +87,7 @@
         data['from_user'] = User.de_json(data.pop('from'), bot)
         data['order_info'] = OrderInfo.de_json(data.get('order_info'), bot)
 
-        return cls(**data)
+        return cls(bot=bot, **data)
 
     def to_dict(self):
         data = super(PreCheckoutQuery, self).to_dict()

{"golden_diff": "diff --git a/telegram/payment/precheckoutquery.py b/telegram/payment/precheckoutquery.py\n--- a/telegram/payment/precheckoutquery.py\n+++ b/telegram/payment/precheckoutquery.py\n@@ -87,7 +87,7 @@\n         data['from_user'] = User.de_json(data.pop('from'), bot)\n         data['order_info'] = OrderInfo.de_json(data.get('order_info'), bot)\n \n-        return cls(**data)\n+        return cls(bot=bot, **data)\n \n     def to_dict(self):\n         data = super(PreCheckoutQuery, self).to_dict()\n", "issue": "pre_checkout_query does not store bot.\n\r\n### Steps to reproduce\r\n- On a PreChecoutQueryHandler, get the PreCheckoutQuery object update.pre_checkout_query\r\n\r\n- Try to answer it, bot has not been set:\r\n\r\n  File \"/home/folarte/sexychat/nor  File \"/home/folarte/sexychat/normalstate.py\", line 998, in on_pcoq\r\n    pcoq.answer(ok=True)\r\n  File \"/home/folarte/venv-sxc/local/lib/python3.6/site-packages/telegram/payment/precheckoutquery.py\", line 115, in answer\r\n    return self.bot.answer_pre_checkout_query(self.id, *args, **kwargs)\r\nAttributeError: 'NoneType' object has no attribute 'answer_pre_checkout_query'\r\nmalstate.py\", line 998, in on_pcoq\r\n    pcoq.answer(ok=True)\r\n  File \"/home/folarte/venv-sxc/local/lib/python3.6/site-packages/telegram/payment/precheckoutquery.py\", line 115, in answer\r\n    return self.bot.answer_pre_checkout_query(self.id, *args, **kwargs)\r\nAttributeError: 'NoneType' object has no attribute 'answer_pre_checkout_query'\r\n\r\n### Expected behaviour\r\n\r\npcoq.bot should contain the bot object.\r\n\r\n### Actual behaviour\r\n\r\nbot object is not set. Thi is due to the de_json function being:\r\n\r\n    @classmethod\r\n    def de_json(cls, data, bot):\r\n        if not data:\r\n            return None\r\n\r\n        data = super(PreCheckoutQuery, cls).de_json(data, bot)\r\n\r\n        data['from_user'] = User.de_json(data.pop('from'), bot)\r\n\tdata['order_info'] = OrderInfo.de_json(data.get('order_info'), bot)\r\n\r\n        return cls(**data)\r\n\r\nWhen the last call should pass the bot to the constructor, as done in the callbackquery object:\r\n\r\n        return cls(bot=bot, **data)\r\n\r\nWhen editing the line to these, it works fine.\r\n\r\nDo not know GIT, can try to do it, but it is a trivial fix, probably a typo.\r\n\r\n### Configuration\r\n\r\nAmazon Linux, aws instance.\r\n\r\n$ python -m telegram\r\npython-telegram-bot 9.0.0\r\ncertifi 2017.11.05\r\nfuture 0.16.0\r\nPython 3.6.2 (default, Nov  2 2017, 19:34:31)  [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]\r\n\n", "before_files": [{"content": "#!/usr/bin/env python\n#\n# A library that provides a Python interface to the Telegram Bot API\n# Copyright (C) 2015-2017\n# Leandro Toledo de Souza <devs@python-telegram-bot.org>\n#\n# This program is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Lesser Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Lesser Public License for more details.\n#\n# You should have received a copy of the GNU Lesser Public License\n# along with this program.  If not, see [http://www.gnu.org/licenses/].\n\"\"\"This module contains an object that represents a Telegram PreCheckoutQuery.\"\"\"\n\nfrom telegram import TelegramObject, User, OrderInfo\n\n\nclass PreCheckoutQuery(TelegramObject):\n    \"\"\"This object contains information about an incoming pre-checkout query.\n\n    Note:\n        * In Python `from` is a reserved word, use `from_user` instead.\n\n    Attributes:\n        id (:obj:`str`): Unique query identifier.\n        from_user (:class:`telegram.User`): User who sent the query.\n        currency (:obj:`str`): Three-letter ISO 4217 currency code.\n        total_amount (:obj:`int`): Total price in the smallest units of the currency.\n        invoice_payload (:obj:`str`): Bot specified invoice payload.\n        shipping_option_id (:obj:`str`): Optional. Identifier of the shipping option chosen by the\n            user.\n        order_info (:class:`telegram.OrderInfo`): Optional. Order info provided by the user.\n        bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods.\n\n    Args:\n        id (:obj:`str`): Unique query identifier.\n        from_user (:class:`telegram.User`): User who sent the query.\n        currency (:obj:`str`): Three-letter ISO 4217 currency code\n        total_amount (:obj:`int`): Total price in the smallest units of the currency (integer, not\n            float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp\n            parameter in currencies.json, it shows the number of digits past the decimal point for\n            each currency (2 for the majority of currencies).\n        invoice_payload (:obj:`str`): Bot specified invoice payload.\n        shipping_option_id (:obj:`str`, optional): Identifier of the shipping option chosen by the\n            user.\n        order_info (:class:`telegram.OrderInfo`, optional): Order info provided by the user.\n        bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods.\n        **kwargs (:obj:`dict`): Arbitrary keyword arguments.\n\n    \"\"\"\n\n    def __init__(self,\n                 id,\n                 from_user,\n                 currency,\n                 total_amount,\n                 invoice_payload,\n                 shipping_option_id=None,\n                 order_info=None,\n                 bot=None,\n                 **kwargs):\n        self.id = id\n        self.from_user = from_user\n        self.currency = currency\n        self.total_amount = total_amount\n        self.invoice_payload = invoice_payload\n        self.shipping_option_id = shipping_option_id\n        self.order_info = order_info\n\n        self.bot = bot\n\n        self._id_attrs = (self.id,)\n\n    @classmethod\n    def de_json(cls, data, bot):\n        if not data:\n            return None\n\n        data = super(PreCheckoutQuery, cls).de_json(data, bot)\n\n        data['from_user'] = User.de_json(data.pop('from'), bot)\n        data['order_info'] = OrderInfo.de_json(data.get('order_info'), bot)\n\n        return cls(**data)\n\n    def to_dict(self):\n        data = super(PreCheckoutQuery, self).to_dict()\n\n        data['from'] = data.pop('from_user', None)\n\n        return data\n\n    def answer(self, *args, **kwargs):\n        \"\"\"Shortcut for::\n\n            bot.answer_pre_checkout_query(update.pre_checkout_query.id, *args, **kwargs)\n\n        Args:\n            ok (:obj:`bool`): Specify True if everything is alright (goods are available, etc.) and\n                the bot is ready to proceed with the order. Use False if there are any problems.\n            error_message (:obj:`str`, optional): Required if ok is False. Error message in human\n                readable form that explains the reason for failure to proceed with the checkout\n                (e.g. \"Sorry, somebody just bought the last of our amazing black T-shirts while you\n                were busy filling out your payment details. Please choose a different color or\n                garment!\"). Telegram will display this message to the user.\n            **kwargs (:obj:`dict`): Arbitrary keyword arguments.\n\n        \"\"\"\n        return self.bot.answer_pre_checkout_query(self.id, *args, **kwargs)\n", "path": "telegram/payment/precheckoutquery.py"}], "after_files": [{"content": "#!/usr/bin/env python\n#\n# A library that provides a Python interface to the Telegram Bot API\n# Copyright (C) 2015-2017\n# Leandro Toledo de Souza <devs@python-telegram-bot.org>\n#\n# This program is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Lesser Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Lesser Public License for more details.\n#\n# You should have received a copy of the GNU Lesser Public License\n# along with this program.  If not, see [http://www.gnu.org/licenses/].\n\"\"\"This module contains an object that represents a Telegram PreCheckoutQuery.\"\"\"\n\nfrom telegram import TelegramObject, User, OrderInfo\n\n\nclass PreCheckoutQuery(TelegramObject):\n    \"\"\"This object contains information about an incoming pre-checkout query.\n\n    Note:\n        * In Python `from` is a reserved word, use `from_user` instead.\n\n    Attributes:\n        id (:obj:`str`): Unique query identifier.\n        from_user (:class:`telegram.User`): User who sent the query.\n        currency (:obj:`str`): Three-letter ISO 4217 currency code.\n        total_amount (:obj:`int`): Total price in the smallest units of the currency.\n        invoice_payload (:obj:`str`): Bot specified invoice payload.\n        shipping_option_id (:obj:`str`): Optional. Identifier of the shipping option chosen by the\n            user.\n        order_info (:class:`telegram.OrderInfo`): Optional. Order info provided by the user.\n        bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods.\n\n    Args:\n        id (:obj:`str`): Unique query identifier.\n        from_user (:class:`telegram.User`): User who sent the query.\n        currency (:obj:`str`): Three-letter ISO 4217 currency code\n        total_amount (:obj:`int`): Total price in the smallest units of the currency (integer, not\n            float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp\n            parameter in currencies.json, it shows the number of digits past the decimal point for\n            each currency (2 for the majority of currencies).\n        invoice_payload (:obj:`str`): Bot specified invoice payload.\n        shipping_option_id (:obj:`str`, optional): Identifier of the shipping option chosen by the\n            user.\n        order_info (:class:`telegram.OrderInfo`, optional): Order info provided by the user.\n        bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods.\n        **kwargs (:obj:`dict`): Arbitrary keyword arguments.\n\n    \"\"\"\n\n    def __init__(self,\n                 id,\n                 from_user,\n                 currency,\n                 total_amount,\n                 invoice_payload,\n                 shipping_option_id=None,\n                 order_info=None,\n                 bot=None,\n                 **kwargs):\n        self.id = id\n        self.from_user = from_user\n        self.currency = currency\n        self.total_amount = total_amount\n        self.invoice_payload = invoice_payload\n        self.shipping_option_id = shipping_option_id\n        self.order_info = order_info\n\n        self.bot = bot\n\n        self._id_attrs = (self.id,)\n\n    @classmethod\n    def de_json(cls, data, bot):\n        if not data:\n            return None\n\n        data = super(PreCheckoutQuery, cls).de_json(data, bot)\n\n        data['from_user'] = User.de_json(data.pop('from'), bot)\n        data['order_info'] = OrderInfo.de_json(data.get('order_info'), bot)\n\n        return cls(bot=bot, **data)\n\n    def to_dict(self):\n        data = super(PreCheckoutQuery, self).to_dict()\n\n        data['from'] = data.pop('from_user', None)\n\n        return data\n\n    def answer(self, *args, **kwargs):\n        \"\"\"Shortcut for::\n\n            bot.answer_pre_checkout_query(update.pre_checkout_query.id, *args, **kwargs)\n\n        Args:\n            ok (:obj:`bool`): Specify True if everything is alright (goods are available, etc.) and\n                the bot is ready to proceed with the order. Use False if there are any problems.\n            error_message (:obj:`str`, optional): Required if ok is False. Error message in human\n                readable form that explains the reason for failure to proceed with the checkout\n                (e.g. \"Sorry, somebody just bought the last of our amazing black T-shirts while you\n                were busy filling out your payment details. Please choose a different color or\n                garment!\"). Telegram will display this message to the user.\n            **kwargs (:obj:`dict`): Arbitrary keyword arguments.\n\n        \"\"\"\n        return self.bot.answer_pre_checkout_query(self.id, *args, **kwargs)\n", "path": "telegram/payment/precheckoutquery.py"}]}