Opened on 09/11/2018 at 01:21:10 PM
Closed on 09/24/2018 at 10:39:13 AM
#6943 closed change (fixed)
[python-abp] Use filter.type == x instead of isinstance(filter, X) in production code
Reported by: | kvas | Assignee: | atudor |
---|---|---|---|
Priority: | P4 | Milestone: | |
Module: | Sitescripts | Keywords: | goodfirstbug |
Cc: | Blocked By: | ||
Blocking: | Platform: | Unknown / Cross platform | |
Ready: | yes | Confidential: | no |
Tester: | Unknown | Verified working: | no |
Review URL(s): |
Description
Background
The code of python-abp that works with filters mostly uses isinstance(filter, FilterClass) to match different types of filters. At the same time, all filters have .type attribute that allows distinguishing them. In fact, the main purpose of this attribute is to allow external users to write concise and simpler code and not have to import the filter classes from python-abp. We can use the same API inside of python-abp to improve clarity and speed.
What to change
Replace isinstance(filter, FilterClass) with filter.type == 'type' everywhere in production code. Introduce constants as necessary.
Already fixed in this commit: https://github.com/adblockplus/python-abp/commit/207499e5efd80495b5a5876790201ff7ca11f97c