mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-05 04:36:52 +00:00
Add docstrings to Notifier class
This commit is contained in:
parent
57e8583e29
commit
d3a9f7d58c
1 changed files with 24 additions and 0 deletions
|
|
@ -3,9 +3,31 @@ from flake8 import _trie
|
|||
|
||||
class Notifier(object):
|
||||
def __init__(self):
|
||||
"""Initialize an empty notifier object."""
|
||||
self.listeners = _trie.Trie()
|
||||
|
||||
def listeners_for(self, error_code):
|
||||
"""Retrieve listeners for an error_code.
|
||||
|
||||
The error code does not need to be a specific error code. For example,
|
||||
There may be listeners registered for E100, E101, E110, E112, and
|
||||
E126. If you wanted to get all listeners starting with 'E1' then you
|
||||
would pass 'E1' as the error code here.
|
||||
|
||||
Example usage
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from flake8 import notifier
|
||||
|
||||
n = notifier.Notifier()
|
||||
# register listeners
|
||||
for listener in n.listeners_for('E1'):
|
||||
listener.notify(...)
|
||||
|
||||
for listener in n.listeners_for('W102'):
|
||||
listener.notify(...)
|
||||
"""
|
||||
node = self.listeners.find(error_code)
|
||||
if node is None:
|
||||
return
|
||||
|
|
@ -16,8 +38,10 @@ class Notifier(object):
|
|||
yield listener
|
||||
|
||||
def notify(self, error_code, *args, **kwargs):
|
||||
"""Notify all listeners for the specified error code."""
|
||||
for listener in self.listeners_for(error_code):
|
||||
listener.notify(*args, **kwargs)
|
||||
|
||||
def register_listener(self, error_code, listener):
|
||||
"""Register a listener for a specific error_code."""
|
||||
self.listeners.add(error_code, listener)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue