prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  lazy.when
  # Issue description
  
  I found this quite oldy [`config.py`](https://gist.github.com/cjbarnes18/4151805) that uses a `when` operation to limit the keybinding to a layout but it throws an exception. I also couldn't find it in the docs, so is it supposed to exist? Is there another similar intended way to limit key bindings to a layout.
  
  
  ```python
  from libqtile.lazy import lazy
  ```
  ...
  ```python
      Key([mod], 'Left',
          lazy.layout.left().when('xmonadtall'))
  ```
  
  # Qtile version
  
  v0.15.0
  
  # Stack traces
  
  ```
  libqtile xcore.py:_xpoll():L277  Got an exception in poll loop
  Traceback (most recent call last):
    File "/share/git/qtile/libqtile/backend/x11/xcore.py", line 246, in _xpoll
      ret = target(event)
    File "/share/git/qtile/libqtile/backend/x11/xcore.py", line 494, in handle_KeyPress
      self.qtile.process_key_event(keysym, event.state & self._valid_mask)
    File "/share/git/qtile/libqtile/core/manager.py", line 342, in process_key_event
      if cmd.check(self):
  AttributeError: 'NoneType' object has no attribute 'check'
  ```
  
  Thanks for any help
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `libqtile/lazy.py`
  Content:
  ```
  1 # Copyright (c) 2019, Sean Vig. All rights reserved.
  2 #
  3 # Permission is hereby granted, free of charge, to any person obtaining a copy
  4 # of this software and associated documentation files (the "Software"), to deal
  5 # in the Software without restriction, including without limitation the rights
  6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7 # copies of the Software, and to permit persons to whom the Software is
  8 # furnished to do so, subject to the following conditions:
  9 #
  10 # The above copyright notice and this permission notice shall be included in
  11 # all copies or substantial portions of the Software.
  12 #
  13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  19 # SOFTWARE.
  20 
  21 from typing import Dict, List, Optional, Tuple, Union  # noqa: F401
  22 
  23 from libqtile.command_client import InteractiveCommandClient
  24 from libqtile.command_graph import (
  25     CommandGraphCall,
  26     CommandGraphNode,
  27     SelectorType,
  28 )
  29 from libqtile.command_interface import CommandInterface
  30 
  31 
  32 class LazyCall:
  33     def __init__(self, call: CommandGraphCall, args: Tuple, kwargs: Dict) -> None:
  34         """The lazily evaluated command graph call
  35 
  36         Parameters
  37         ----------
  38         call : CommandGraphCall
  39             The call that is made
  40         args : Tuple
  41             The args passed to the call when it is evaluated.
  42         kwargs : Dict
  43             The kwargs passed to the call when it is evaluated.
  44         """
  45         self._call = call
  46         self._args = args
  47         self._kwargs = kwargs
  48 
  49         self._layout = None  # type: Optional[str]
  50         self._when_floating = True
  51 
  52     @property
  53     def selectors(self) -> List[SelectorType]:
  54         """The selectors for the given call"""
  55         return self._call.selectors
  56 
  57     @property
  58     def name(self) -> str:
  59         """The name of the given call"""
  60         return self._call.name
  61 
  62     @property
  63     def args(self) -> Tuple:
  64         """The args to the given call"""
  65         return self._args
  66 
  67     @property
  68     def kwargs(self) -> Dict:
  69         """The kwargs to the given call"""
  70         return self._kwargs
  71 
  72     def when(self, layout=None, when_floating=True):
  73         self._layout = layout
  74         self._when_floating = when_floating
  75 
  76     def check(self, q) -> bool:
  77         if self._layout is not None:
  78             if self._layout == 'floating':
  79                 if q.current_window.floating:
  80                     return True
  81                 return False
  82             if q.current_layout.name != self._layout:
  83                 if q.current_window and q.current_window.floating and not self._when_floating:
  84                     return False
  85         return True
  86 
  87 
  88 class LazyCommandObject(CommandInterface):
  89     """A lazy loading command object
  90 
  91     Allows all commands and items to be resolved at run time, and returns
  92     lazily evaluated commands.
  93     """
  94 
  95     def execute(self, call: CommandGraphCall, args: Tuple, kwargs: Dict) -> LazyCall:
  96         """Lazily evaluate the given call"""
  97         return LazyCall(call, args, kwargs)
  98 
  99     def has_command(self, node: CommandGraphNode, command: str) -> bool:
  100         """Lazily resolve the given command"""
  101         return True
  102 
  103     def has_item(self, node: CommandGraphNode, object_type: str, item: Union[str, int]) -> bool:
  104         """Lazily resolve the given item"""
  105         return True
  106 
  107 
  108 lazy = InteractiveCommandClient(LazyCommandObject())
  109
  ```
  --- 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/libqtile/lazy.py b/libqtile/lazy.py
  --- a/libqtile/lazy.py
  +++ b/libqtile/lazy.py
  @@ -72,6 +72,7 @@
       def when(self, layout=None, when_floating=True):
           self._layout = layout
           self._when_floating = when_floating
  +        return self
   
       def check(self, q) -> bool:
           if self._layout is not None:
  
verification_info: {"golden_diff": "diff --git a/libqtile/lazy.py b/libqtile/lazy.py\n--- a/libqtile/lazy.py\n+++ b/libqtile/lazy.py\n@@ -72,6 +72,7 @@\n     def when(self, layout=None, when_floating=True):\n         self._layout = layout\n         self._when_floating = when_floating\n+        return self\n \n     def check(self, q) -> bool:\n         if self._layout is not None:\n", "issue": "lazy.when\n# Issue description\r\n\r\nI found this quite oldy [`config.py`](https://gist.github.com/cjbarnes18/4151805) that uses a `when` operation to limit the keybinding to a layout but it throws an exception. I also couldn't find it in the docs, so is it supposed to exist? Is there another similar intended way to limit key bindings to a layout.\r\n\r\n\r\n```python\r\nfrom libqtile.lazy import lazy\r\n```\r\n...\r\n```python\r\n    Key([mod], 'Left',\r\n        lazy.layout.left().when('xmonadtall'))\r\n```\r\n\r\n# Qtile version\r\n\r\nv0.15.0\r\n\r\n# Stack traces\r\n\r\n```\r\nlibqtile xcore.py:_xpoll():L277  Got an exception in poll loop\r\nTraceback (most recent call last):\r\n  File \"/share/git/qtile/libqtile/backend/x11/xcore.py\", line 246, in _xpoll\r\n    ret = target(event)\r\n  File \"/share/git/qtile/libqtile/backend/x11/xcore.py\", line 494, in handle_KeyPress\r\n    self.qtile.process_key_event(keysym, event.state & self._valid_mask)\r\n  File \"/share/git/qtile/libqtile/core/manager.py\", line 342, in process_key_event\r\n    if cmd.check(self):\r\nAttributeError: 'NoneType' object has no attribute 'check'\r\n```\r\n\r\nThanks for any help\n", "before_files": [{"content": "# Copyright (c) 2019, Sean Vig. All rights reserved.\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n# SOFTWARE.\n\nfrom typing import Dict, List, Optional, Tuple, Union  # noqa: F401\n\nfrom libqtile.command_client import InteractiveCommandClient\nfrom libqtile.command_graph import (\n    CommandGraphCall,\n    CommandGraphNode,\n    SelectorType,\n)\nfrom libqtile.command_interface import CommandInterface\n\n\nclass LazyCall:\n    def __init__(self, call: CommandGraphCall, args: Tuple, kwargs: Dict) -> None:\n        \"\"\"The lazily evaluated command graph call\n\n        Parameters\n        ----------\n        call : CommandGraphCall\n            The call that is made\n        args : Tuple\n            The args passed to the call when it is evaluated.\n        kwargs : Dict\n            The kwargs passed to the call when it is evaluated.\n        \"\"\"\n        self._call = call\n        self._args = args\n        self._kwargs = kwargs\n\n        self._layout = None  # type: Optional[str]\n        self._when_floating = True\n\n    @property\n    def selectors(self) -> List[SelectorType]:\n        \"\"\"The selectors for the given call\"\"\"\n        return self._call.selectors\n\n    @property\n    def name(self) -> str:\n        \"\"\"The name of the given call\"\"\"\n        return self._call.name\n\n    @property\n    def args(self) -> Tuple:\n        \"\"\"The args to the given call\"\"\"\n        return self._args\n\n    @property\n    def kwargs(self) -> Dict:\n        \"\"\"The kwargs to the given call\"\"\"\n        return self._kwargs\n\n    def when(self, layout=None, when_floating=True):\n        self._layout = layout\n        self._when_floating = when_floating\n\n    def check(self, q) -> bool:\n        if self._layout is not None:\n            if self._layout == 'floating':\n                if q.current_window.floating:\n                    return True\n                return False\n            if q.current_layout.name != self._layout:\n                if q.current_window and q.current_window.floating and not self._when_floating:\n                    return False\n        return True\n\n\nclass LazyCommandObject(CommandInterface):\n    \"\"\"A lazy loading command object\n\n    Allows all commands and items to be resolved at run time, and returns\n    lazily evaluated commands.\n    \"\"\"\n\n    def execute(self, call: CommandGraphCall, args: Tuple, kwargs: Dict) -> LazyCall:\n        \"\"\"Lazily evaluate the given call\"\"\"\n        return LazyCall(call, args, kwargs)\n\n    def has_command(self, node: CommandGraphNode, command: str) -> bool:\n        \"\"\"Lazily resolve the given command\"\"\"\n        return True\n\n    def has_item(self, node: CommandGraphNode, object_type: str, item: Union[str, int]) -> bool:\n        \"\"\"Lazily resolve the given item\"\"\"\n        return True\n\n\nlazy = InteractiveCommandClient(LazyCommandObject())\n", "path": "libqtile/lazy.py"}], "after_files": [{"content": "# Copyright (c) 2019, Sean Vig. All rights reserved.\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n# SOFTWARE.\n\nfrom typing import Dict, List, Optional, Tuple, Union  # noqa: F401\n\nfrom libqtile.command_client import InteractiveCommandClient\nfrom libqtile.command_graph import (\n    CommandGraphCall,\n    CommandGraphNode,\n    SelectorType,\n)\nfrom libqtile.command_interface import CommandInterface\n\n\nclass LazyCall:\n    def __init__(self, call: CommandGraphCall, args: Tuple, kwargs: Dict) -> None:\n        \"\"\"The lazily evaluated command graph call\n\n        Parameters\n        ----------\n        call : CommandGraphCall\n            The call that is made\n        args : Tuple\n            The args passed to the call when it is evaluated.\n        kwargs : Dict\n            The kwargs passed to the call when it is evaluated.\n        \"\"\"\n        self._call = call\n        self._args = args\n        self._kwargs = kwargs\n\n        self._layout = None  # type: Optional[str]\n        self._when_floating = True\n\n    @property\n    def selectors(self) -> List[SelectorType]:\n        \"\"\"The selectors for the given call\"\"\"\n        return self._call.selectors\n\n    @property\n    def name(self) -> str:\n        \"\"\"The name of the given call\"\"\"\n        return self._call.name\n\n    @property\n    def args(self) -> Tuple:\n        \"\"\"The args to the given call\"\"\"\n        return self._args\n\n    @property\n    def kwargs(self) -> Dict:\n        \"\"\"The kwargs to the given call\"\"\"\n        return self._kwargs\n\n    def when(self, layout=None, when_floating=True):\n        self._layout = layout\n        self._when_floating = when_floating\n        return self\n\n    def check(self, q) -> bool:\n        if self._layout is not None:\n            if self._layout == 'floating':\n                if q.current_window.floating:\n                    return True\n                return False\n            if q.current_layout.name != self._layout:\n                if q.current_window and q.current_window.floating and not self._when_floating:\n                    return False\n        return True\n\n\nclass LazyCommandObject(CommandInterface):\n    \"\"\"A lazy loading command object\n\n    Allows all commands and items to be resolved at run time, and returns\n    lazily evaluated commands.\n    \"\"\"\n\n    def execute(self, call: CommandGraphCall, args: Tuple, kwargs: Dict) -> LazyCall:\n        \"\"\"Lazily evaluate the given call\"\"\"\n        return LazyCall(call, args, kwargs)\n\n    def has_command(self, node: CommandGraphNode, command: str) -> bool:\n        \"\"\"Lazily resolve the given command\"\"\"\n        return True\n\n    def has_item(self, node: CommandGraphNode, object_type: str, item: Union[str, int]) -> bool:\n        \"\"\"Lazily resolve the given item\"\"\"\n        return True\n\n\nlazy = InteractiveCommandClient(LazyCommandObject())\n", "path": "libqtile/lazy.py"}]}