prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Remove Python 2 syntax from events examples in comments
  # Description
  
  In `pyhf.events` there are a two examples of Python 2 syntax being used for 
  
  https://github.com/scikit-hep/pyhf/blob/29c3df0e23a428004a065aed61cefb6a526a7332/src/pyhf/events.py#L46-L53
  
  and 
  
  https://github.com/scikit-hep/pyhf/blob/29c3df0e23a428004a065aed61cefb6a526a7332/src/pyhf/events.py#L69-L87
  
  These examples should be updated to use Python 3 syntax.
  
  Also the examples are wrong themselves. For example, the first example should be
  
  ```python
  >>> import pyhf
  >>> @pyhf.events.subscribe('myevent')
  ... def test(a,b):
  ...     print(a+b)
  ... 
  >>> pyhf.events.trigger("myevent")(1,2)
  3
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/pyhf/events.py`
  Content:
  ```
  1 import weakref
  2 from functools import wraps
  3 
  4 __events = {}
  5 __disabled_events = set()
  6 
  7 __all__ = [
  8     "Callables",
  9     "disable",
  10     "enable",
  11     "noop",
  12     "register",
  13     "subscribe",
  14     "trigger",
  15 ]
  16 
  17 
  18 def __dir__():
  19     return __all__
  20 
  21 
  22 def noop(*args, **kwargs):
  23     pass
  24 
  25 
  26 class Callables:
  27     def __init__(self):
  28         self._callbacks = []
  29 
  30     @property
  31     def callbacks(self):
  32         """
  33         Get the current list of living callbacks.
  34         """
  35         self._flush()
  36         return self._callbacks
  37 
  38     def append(self, callback):
  39         """
  40         Append a new bound method as a callback to the list of callables.
  41         """
  42         try:
  43             # methods
  44             callback_ref = weakref.ref(callback.__func__), weakref.ref(
  45                 callback.__self__
  46             )
  47         except AttributeError:
  48             callback_ref = weakref.ref(callback), None
  49         self._callbacks.append(callback_ref)
  50 
  51     def _flush(self):
  52         """
  53         Flush the list of callbacks with those who are weakly-referencing deleted objects.
  54 
  55         Note: must interact with the self._callbacks directly, and not
  56         self.callbacks, to avoid infinite recursion.
  57         """
  58         _callbacks = []
  59         for func, arg in self._callbacks:
  60             if arg is not None:
  61                 arg_ref = arg()
  62                 if arg_ref is None:
  63                     continue
  64             _callbacks.append((func, arg))
  65         self._callbacks = _callbacks
  66 
  67     def __call__(self, *args, **kwargs):
  68         for func, arg in self.callbacks:
  69             # weakref: needs to be de-ref'd first before calling
  70             if arg is not None:
  71                 func()(arg(), *args, **kwargs)
  72             else:
  73                 func()(*args, **kwargs)
  74 
  75     def __iter__(self):
  76         return iter(self.callbacks)
  77 
  78     def __getitem__(self, index):
  79         return self.callbacks[index]
  80 
  81     def __len__(self):
  82         return len(self.callbacks)
  83 
  84     def __repr__(self):
  85         return f"Callables({self.callbacks})"
  86 
  87 
  88 def subscribe(event):
  89     """
  90     Subscribe a function or object method as a callback to an event.
  91 
  92     Note: this is meant to be used as a decorator.
  93 
  94     Args:
  95         event (:obj:`str`): The name of the event to subscribe to.
  96 
  97     Returns:
  98         :obj:`function`: Decorated function.
  99     """
  100     # Example:
  101     #
  102     # >>> @pyhf.events.subscribe('myevent')
  103     # ... def test(a,b):
  104     # ...   print a+b
  105     # ...
  106     # >>> pyhf.events.trigger_myevent(1,2)
  107     # 3
  108     global __events
  109 
  110     def __decorator(func):
  111         __events.setdefault(event, Callables()).append(func)
  112         return func
  113 
  114     return __decorator
  115 
  116 
  117 def register(event):
  118     """
  119     Register a function or object method to trigger an event.  This creates two
  120     events: ``{event_name}::before`` and ``{event_name}::after``.
  121 
  122     Note: this is meant to be used as a decorator.
  123 
  124     Args:
  125         event (:obj:`str`): The name of the event to subscribe to.
  126 
  127     Returns:
  128         :obj:`function`: Decorated function.
  129 
  130     """
  131     # Examples:
  132     #
  133     # >>> @pyhf.events.register('test_func')
  134     # ... def test(a,b):
  135     # ...   print a+b
  136     # ...
  137     # >>> @pyhf.events.subscribe('test_func::before')
  138     # ... def precall():
  139     # ...   print 'before call'
  140     # ...
  141     # >>> @pyhf.events.subscribe('test_func::after')
  142     # ... def postcall():
  143     # ...   print 'after call'
  144     # ...
  145     # >>> test(1,2)
  146     # "before call"
  147     # 3
  148     # "after call"
  149     # >>>
  150 
  151     def _register(func):
  152         @wraps(func)
  153         def register_wrapper(*args, **kwargs):
  154             trigger(f"{event:s}::before")()
  155             result = func(*args, **kwargs)
  156             trigger(f"{event:s}::after")()
  157             return result
  158 
  159         return register_wrapper
  160 
  161     return _register
  162 
  163 
  164 def trigger(event):
  165     """
  166     Trigger an event if not disabled.
  167     """
  168     global __events, __disabled_events, noop
  169     is_noop = bool(event in __disabled_events or event not in __events)
  170     return noop if is_noop else __events.get(event)
  171 
  172 
  173 def disable(event):
  174     """
  175     Disable an event from firing.
  176     """
  177     global __disabled_events
  178     __disabled_events.add(event)
  179 
  180 
  181 def enable(event):
  182     """
  183     Enable an event to be fired if disabled.
  184     """
  185     global __disabled_events
  186     __disabled_events.remove(event)
  187
  ```
  --- 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/src/pyhf/events.py b/src/pyhf/events.py
  --- a/src/pyhf/events.py
  +++ b/src/pyhf/events.py
  @@ -89,22 +89,27 @@
       """
       Subscribe a function or object method as a callback to an event.
   
  -    Note: this is meant to be used as a decorator.
  +    .. note::
  +
  +     This is meant to be used as a decorator.
   
       Args:
           event (:obj:`str`): The name of the event to subscribe to.
   
       Returns:
           :obj:`function`: Decorated function.
  +
  +    Example:
  +        >>> import pyhf
  +        >>> @pyhf.events.subscribe("myevent")
  +        ... def test(a, b):
  +        ...     print(a + b)
  +        ...
  +        >>> pyhf.events.trigger("myevent")(1, 2)
  +        3
  +
       """
  -    # Example:
  -    #
  -    # >>> @pyhf.events.subscribe('myevent')
  -    # ... def test(a,b):
  -    # ...   print a+b
  -    # ...
  -    # >>> pyhf.events.trigger_myevent(1,2)
  -    # 3
  +
       global __events
   
       def __decorator(func):
  @@ -119,7 +124,9 @@
       Register a function or object method to trigger an event.  This creates two
       events: ``{event_name}::before`` and ``{event_name}::after``.
   
  -    Note: this is meant to be used as a decorator.
  +    .. note::
  +
  +     This is meant to be used as a decorator.
   
       Args:
           event (:obj:`str`): The name of the event to subscribe to.
  @@ -127,26 +134,26 @@
       Returns:
           :obj:`function`: Decorated function.
   
  +    Example:
  +        >>> import pyhf
  +        >>> @pyhf.events.register("test_func")
  +        ... def test(a, b):
  +        ...     print(a + b)
  +        ...
  +        >>> @pyhf.events.subscribe("test_func::before")
  +        ... def precall():
  +        ...     print("before call")
  +        ...
  +        >>> @pyhf.events.subscribe("test_func::after")
  +        ... def postcall():
  +        ...     print("after call")
  +        ...
  +        >>> test(1, 2)
  +        before call
  +        3
  +        after call
  +
       """
  -    # Examples:
  -    #
  -    # >>> @pyhf.events.register('test_func')
  -    # ... def test(a,b):
  -    # ...   print a+b
  -    # ...
  -    # >>> @pyhf.events.subscribe('test_func::before')
  -    # ... def precall():
  -    # ...   print 'before call'
  -    # ...
  -    # >>> @pyhf.events.subscribe('test_func::after')
  -    # ... def postcall():
  -    # ...   print 'after call'
  -    # ...
  -    # >>> test(1,2)
  -    # "before call"
  -    # 3
  -    # "after call"
  -    # >>>
   
       def _register(func):
           @wraps(func)
  
verification_info: {"golden_diff": "diff --git a/src/pyhf/events.py b/src/pyhf/events.py\n--- a/src/pyhf/events.py\n+++ b/src/pyhf/events.py\n@@ -89,22 +89,27 @@\n     \"\"\"\n     Subscribe a function or object method as a callback to an event.\n \n-    Note: this is meant to be used as a decorator.\n+    .. note::\n+\n+     This is meant to be used as a decorator.\n \n     Args:\n         event (:obj:`str`): The name of the event to subscribe to.\n \n     Returns:\n         :obj:`function`: Decorated function.\n+\n+    Example:\n+        >>> import pyhf\n+        >>> @pyhf.events.subscribe(\"myevent\")\n+        ... def test(a, b):\n+        ...     print(a + b)\n+        ...\n+        >>> pyhf.events.trigger(\"myevent\")(1, 2)\n+        3\n+\n     \"\"\"\n-    # Example:\n-    #\n-    # >>> @pyhf.events.subscribe('myevent')\n-    # ... def test(a,b):\n-    # ...   print a+b\n-    # ...\n-    # >>> pyhf.events.trigger_myevent(1,2)\n-    # 3\n+\n     global __events\n \n     def __decorator(func):\n@@ -119,7 +124,9 @@\n     Register a function or object method to trigger an event.  This creates two\n     events: ``{event_name}::before`` and ``{event_name}::after``.\n \n-    Note: this is meant to be used as a decorator.\n+    .. note::\n+\n+     This is meant to be used as a decorator.\n \n     Args:\n         event (:obj:`str`): The name of the event to subscribe to.\n@@ -127,26 +134,26 @@\n     Returns:\n         :obj:`function`: Decorated function.\n \n+    Example:\n+        >>> import pyhf\n+        >>> @pyhf.events.register(\"test_func\")\n+        ... def test(a, b):\n+        ...     print(a + b)\n+        ...\n+        >>> @pyhf.events.subscribe(\"test_func::before\")\n+        ... def precall():\n+        ...     print(\"before call\")\n+        ...\n+        >>> @pyhf.events.subscribe(\"test_func::after\")\n+        ... def postcall():\n+        ...     print(\"after call\")\n+        ...\n+        >>> test(1, 2)\n+        before call\n+        3\n+        after call\n+\n     \"\"\"\n-    # Examples:\n-    #\n-    # >>> @pyhf.events.register('test_func')\n-    # ... def test(a,b):\n-    # ...   print a+b\n-    # ...\n-    # >>> @pyhf.events.subscribe('test_func::before')\n-    # ... def precall():\n-    # ...   print 'before call'\n-    # ...\n-    # >>> @pyhf.events.subscribe('test_func::after')\n-    # ... def postcall():\n-    # ...   print 'after call'\n-    # ...\n-    # >>> test(1,2)\n-    # \"before call\"\n-    # 3\n-    # \"after call\"\n-    # >>>\n \n     def _register(func):\n         @wraps(func)\n", "issue": "Remove Python 2 syntax from events examples in comments\n# Description\r\n\r\nIn `pyhf.events` there are a two examples of Python 2 syntax being used for \r\n\r\nhttps://github.com/scikit-hep/pyhf/blob/29c3df0e23a428004a065aed61cefb6a526a7332/src/pyhf/events.py#L46-L53\r\n\r\nand \r\n\r\nhttps://github.com/scikit-hep/pyhf/blob/29c3df0e23a428004a065aed61cefb6a526a7332/src/pyhf/events.py#L69-L87\r\n\r\nThese examples should be updated to use Python 3 syntax.\r\n\r\nAlso the examples are wrong themselves. For example, the first example should be\r\n\r\n```python\r\n>>> import pyhf\r\n>>> @pyhf.events.subscribe('myevent')\r\n... def test(a,b):\r\n...     print(a+b)\r\n... \r\n>>> pyhf.events.trigger(\"myevent\")(1,2)\r\n3\r\n```\n", "before_files": [{"content": "import weakref\nfrom functools import wraps\n\n__events = {}\n__disabled_events = set()\n\n__all__ = [\n    \"Callables\",\n    \"disable\",\n    \"enable\",\n    \"noop\",\n    \"register\",\n    \"subscribe\",\n    \"trigger\",\n]\n\n\ndef __dir__():\n    return __all__\n\n\ndef noop(*args, **kwargs):\n    pass\n\n\nclass Callables:\n    def __init__(self):\n        self._callbacks = []\n\n    @property\n    def callbacks(self):\n        \"\"\"\n        Get the current list of living callbacks.\n        \"\"\"\n        self._flush()\n        return self._callbacks\n\n    def append(self, callback):\n        \"\"\"\n        Append a new bound method as a callback to the list of callables.\n        \"\"\"\n        try:\n            # methods\n            callback_ref = weakref.ref(callback.__func__), weakref.ref(\n                callback.__self__\n            )\n        except AttributeError:\n            callback_ref = weakref.ref(callback), None\n        self._callbacks.append(callback_ref)\n\n    def _flush(self):\n        \"\"\"\n        Flush the list of callbacks with those who are weakly-referencing deleted objects.\n\n        Note: must interact with the self._callbacks directly, and not\n        self.callbacks, to avoid infinite recursion.\n        \"\"\"\n        _callbacks = []\n        for func, arg in self._callbacks:\n            if arg is not None:\n                arg_ref = arg()\n                if arg_ref is None:\n                    continue\n            _callbacks.append((func, arg))\n        self._callbacks = _callbacks\n\n    def __call__(self, *args, **kwargs):\n        for func, arg in self.callbacks:\n            # weakref: needs to be de-ref'd first before calling\n            if arg is not None:\n                func()(arg(), *args, **kwargs)\n            else:\n                func()(*args, **kwargs)\n\n    def __iter__(self):\n        return iter(self.callbacks)\n\n    def __getitem__(self, index):\n        return self.callbacks[index]\n\n    def __len__(self):\n        return len(self.callbacks)\n\n    def __repr__(self):\n        return f\"Callables({self.callbacks})\"\n\n\ndef subscribe(event):\n    \"\"\"\n    Subscribe a function or object method as a callback to an event.\n\n    Note: this is meant to be used as a decorator.\n\n    Args:\n        event (:obj:`str`): The name of the event to subscribe to.\n\n    Returns:\n        :obj:`function`: Decorated function.\n    \"\"\"\n    # Example:\n    #\n    # >>> @pyhf.events.subscribe('myevent')\n    # ... def test(a,b):\n    # ...   print a+b\n    # ...\n    # >>> pyhf.events.trigger_myevent(1,2)\n    # 3\n    global __events\n\n    def __decorator(func):\n        __events.setdefault(event, Callables()).append(func)\n        return func\n\n    return __decorator\n\n\ndef register(event):\n    \"\"\"\n    Register a function or object method to trigger an event.  This creates two\n    events: ``{event_name}::before`` and ``{event_name}::after``.\n\n    Note: this is meant to be used as a decorator.\n\n    Args:\n        event (:obj:`str`): The name of the event to subscribe to.\n\n    Returns:\n        :obj:`function`: Decorated function.\n\n    \"\"\"\n    # Examples:\n    #\n    # >>> @pyhf.events.register('test_func')\n    # ... def test(a,b):\n    # ...   print a+b\n    # ...\n    # >>> @pyhf.events.subscribe('test_func::before')\n    # ... def precall():\n    # ...   print 'before call'\n    # ...\n    # >>> @pyhf.events.subscribe('test_func::after')\n    # ... def postcall():\n    # ...   print 'after call'\n    # ...\n    # >>> test(1,2)\n    # \"before call\"\n    # 3\n    # \"after call\"\n    # >>>\n\n    def _register(func):\n        @wraps(func)\n        def register_wrapper(*args, **kwargs):\n            trigger(f\"{event:s}::before\")()\n            result = func(*args, **kwargs)\n            trigger(f\"{event:s}::after\")()\n            return result\n\n        return register_wrapper\n\n    return _register\n\n\ndef trigger(event):\n    \"\"\"\n    Trigger an event if not disabled.\n    \"\"\"\n    global __events, __disabled_events, noop\n    is_noop = bool(event in __disabled_events or event not in __events)\n    return noop if is_noop else __events.get(event)\n\n\ndef disable(event):\n    \"\"\"\n    Disable an event from firing.\n    \"\"\"\n    global __disabled_events\n    __disabled_events.add(event)\n\n\ndef enable(event):\n    \"\"\"\n    Enable an event to be fired if disabled.\n    \"\"\"\n    global __disabled_events\n    __disabled_events.remove(event)\n", "path": "src/pyhf/events.py"}], "after_files": [{"content": "import weakref\nfrom functools import wraps\n\n__events = {}\n__disabled_events = set()\n\n__all__ = [\n    \"Callables\",\n    \"disable\",\n    \"enable\",\n    \"noop\",\n    \"register\",\n    \"subscribe\",\n    \"trigger\",\n]\n\n\ndef __dir__():\n    return __all__\n\n\ndef noop(*args, **kwargs):\n    pass\n\n\nclass Callables:\n    def __init__(self):\n        self._callbacks = []\n\n    @property\n    def callbacks(self):\n        \"\"\"\n        Get the current list of living callbacks.\n        \"\"\"\n        self._flush()\n        return self._callbacks\n\n    def append(self, callback):\n        \"\"\"\n        Append a new bound method as a callback to the list of callables.\n        \"\"\"\n        try:\n            # methods\n            callback_ref = weakref.ref(callback.__func__), weakref.ref(\n                callback.__self__\n            )\n        except AttributeError:\n            callback_ref = weakref.ref(callback), None\n        self._callbacks.append(callback_ref)\n\n    def _flush(self):\n        \"\"\"\n        Flush the list of callbacks with those who are weakly-referencing deleted objects.\n\n        Note: must interact with the self._callbacks directly, and not\n        self.callbacks, to avoid infinite recursion.\n        \"\"\"\n        _callbacks = []\n        for func, arg in self._callbacks:\n            if arg is not None:\n                arg_ref = arg()\n                if arg_ref is None:\n                    continue\n            _callbacks.append((func, arg))\n        self._callbacks = _callbacks\n\n    def __call__(self, *args, **kwargs):\n        for func, arg in self.callbacks:\n            # weakref: needs to be de-ref'd first before calling\n            if arg is not None:\n                func()(arg(), *args, **kwargs)\n            else:\n                func()(*args, **kwargs)\n\n    def __iter__(self):\n        return iter(self.callbacks)\n\n    def __getitem__(self, index):\n        return self.callbacks[index]\n\n    def __len__(self):\n        return len(self.callbacks)\n\n    def __repr__(self):\n        return f\"Callables({self.callbacks})\"\n\n\ndef subscribe(event):\n    \"\"\"\n    Subscribe a function or object method as a callback to an event.\n\n    .. note::\n\n     This is meant to be used as a decorator.\n\n    Args:\n        event (:obj:`str`): The name of the event to subscribe to.\n\n    Returns:\n        :obj:`function`: Decorated function.\n\n    Example:\n        >>> import pyhf\n        >>> @pyhf.events.subscribe(\"myevent\")\n        ... def test(a, b):\n        ...     print(a + b)\n        ...\n        >>> pyhf.events.trigger(\"myevent\")(1, 2)\n        3\n\n    \"\"\"\n\n    global __events\n\n    def __decorator(func):\n        __events.setdefault(event, Callables()).append(func)\n        return func\n\n    return __decorator\n\n\ndef register(event):\n    \"\"\"\n    Register a function or object method to trigger an event.  This creates two\n    events: ``{event_name}::before`` and ``{event_name}::after``.\n\n    .. note::\n\n     This is meant to be used as a decorator.\n\n    Args:\n        event (:obj:`str`): The name of the event to subscribe to.\n\n    Returns:\n        :obj:`function`: Decorated function.\n\n    Example:\n        >>> import pyhf\n        >>> @pyhf.events.register(\"test_func\")\n        ... def test(a, b):\n        ...     print(a + b)\n        ...\n        >>> @pyhf.events.subscribe(\"test_func::before\")\n        ... def precall():\n        ...     print(\"before call\")\n        ...\n        >>> @pyhf.events.subscribe(\"test_func::after\")\n        ... def postcall():\n        ...     print(\"after call\")\n        ...\n        >>> test(1, 2)\n        before call\n        3\n        after call\n\n    \"\"\"\n\n    def _register(func):\n        @wraps(func)\n        def register_wrapper(*args, **kwargs):\n            trigger(f\"{event:s}::before\")()\n            result = func(*args, **kwargs)\n            trigger(f\"{event:s}::after\")()\n            return result\n\n        return register_wrapper\n\n    return _register\n\n\ndef trigger(event):\n    \"\"\"\n    Trigger an event if not disabled.\n    \"\"\"\n    global __events, __disabled_events, noop\n    is_noop = bool(event in __disabled_events or event not in __events)\n    return noop if is_noop else __events.get(event)\n\n\ndef disable(event):\n    \"\"\"\n    Disable an event from firing.\n    \"\"\"\n    global __disabled_events\n    __disabled_events.add(event)\n\n\ndef enable(event):\n    \"\"\"\n    Enable an event to be fired if disabled.\n    \"\"\"\n    global __disabled_events\n    __disabled_events.remove(event)\n", "path": "src/pyhf/events.py"}]}