New syntax and fully qualified names
We’ve continued to make our custom rules more powerful!
This includes:
-
A new
...syntax for matching anything in a position. Say you want to write a rule that matches anyprintstatement. You can now writepattern: print(...)and this will find all print statements with any number of positional or keyword arguments. -
Fully qualified name recognition. Say you want to transform
typing.Listintolistin line with PEP 585. You can define the following rule:rules: - id: convert-typing-list pattern: typing.List replacement: list description: Use `list` rather than `typing.List`This will find all occurrences of
typing.Listand replace them withlist, even if they have been imported usingfrom typing import List.
Added
- Conditions for filtering out captures
- Match anything
...or nothing!!!in patterns is_identifierpublic condition to match variables that are valid identifiersstatement_countcustom rule condition - this lets you count how many statements you matched.
Changed
- Custom rule patterns will now leniently match for type annotations in
assignments, parameters and function definitions. This means that the pattern
${target} = ${value}will now match assignments such asi: int = 0. - Recognize fully qualified names in custom rule patterns. This means that the
pattern
os.path.joinwill matchjoinif it is imported asfrom os.path import join(and all of the possible variations). - Run custom rule conditions on the entire match using the
patternname. - Disallow
patternfrom being used as a regular capture name. - Docstring values can now be captured by using any existing syntax inside the string
Fixed
- Don’t propose
default-mutable-argif the arg name is shadowed in the default argument. e.g.def f(arg=[arg]) - Don’t propose
dict-assign-update-to-unionwhen the update accesses the dict variable - Don’t propose
remove-redundant-except-handlerfor non-built-in exceptions - Escape HTML in PyCharm diffs