Whole file

pycqa/flake8

The author described this change as Fix logic for Notifier.listeners_for. It counts as a record because the check below fails on the code as it stood at 222be9ac4 and passes on 37b92cd4b, with nothing else changed between the two runs.

Fix saved2015-12-29
Sharing licenceMIT · LICENSE
Change size+10 15

What the code was meant to do, written into the code itself as a save note

Fix logic for Notifier.listeners_for

The change

99 def listeners_for(self, error_code):
1010 """Retrieve listeners for an error_code.
1111
12- The error code does not need to be a specific error code. For example,
13- There may be listeners registered for E100, E101, E110, E112, and
14- E126. If you wanted to get all listeners starting with 'E1' then you
15- would pass 'E1' as the error code here.
12+ There may be listeners registered for E1, E100, E101, E110, E112, and
13+ E126. To get all the listeners for one of E100, E101, E110, E112, or
14+ E126 you would also need to incorporate the listeners for E1 (since
15+ they're all in the same class).
1616
17- Example usage
17+ Example usage:
1818
1919 .. code-block:: python
2020
2222
2323 n = notifier.Notifier()
2424 # register listeners
25- for listener in n.listeners_for('E1'):
26- listener.notify(...)
27-
2825 for listener in n.listeners_for('W102'):
2926 listener.notify(...)
3027 """
31- node = self.listeners.find(error_code)
32- if node is None:
33- return
34- for listener in node.data:
35- yield listener
36- for child in node.traverse():
37- for listener in child.data:
28+ path = error_code
29+ while path:
30+ node = self.listeners.find(path)
31+ for listener in node.data:
3832 yield listener
33+ path = path[:-1]
3934
4035 def notify(self, error_code, *args, **kwargs):
4136 """Notify all listeners for the specified error code."""

The check that tells the two apart

failpass·tests/test_notifier.py::TestNotifier::test_notify

Check file tests/test_notifier.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it222be9ac4918d2ea85e9ac3d20832106c10d30a1
Broken version dated2015-12-29
Moduleflake8.notifier
Units changedNotifier
Fingerprinta1d22963b59951be
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in pycqa/flake8