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.
Projectpycqa/flake8
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
| 9 | 9 | def listeners_for(self, error_code): | |
| 10 | 10 | """Retrieve listeners for an error_code. | |
| 11 | 11 | ||
| 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). | |
| 16 | 16 | ||
| 17 | - | Example usage | |
| 17 | + | Example usage: | |
| 18 | 18 | ||
| 19 | 19 | .. code-block:: python | |
| 20 | 20 | ||
| ⋯ | |||
| 22 | 22 | ||
| 23 | 23 | n = notifier.Notifier() | |
| 24 | 24 | # register listeners | |
| 25 | - | for listener in n.listeners_for('E1'): | |
| 26 | - | listener.notify(...) | |
| 27 | - | ||
| 28 | 25 | for listener in n.listeners_for('W102'): | |
| 29 | 26 | listener.notify(...) | |
| 30 | 27 | """ | |
| 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: | |
| 38 | 32 | yield listener | |
| 33 | + | path = path[:-1] | |
| 39 | 34 | ||
| 40 | 35 | def notify(self, error_code, *args, **kwargs): | |
| 41 | 36 | """Notify all listeners for the specified error code.""" | |
The check that tells the two apart
fail→pass·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
- 2022-11-08load_config
- 2021-12-24fix AttributeError when catatstrophic failure is triggered
- 2017-07-28Remediate one wafer thing decision logic bug
- 2016-02-20Notifier