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 anyprint
statement. 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.List
intolist
in 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.List
and 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_identifier
public condition to match variables that are valid identifiersstatement_count
custom 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.join
will matchjoin
if it is imported asfrom os.path import join
(and all of the possible variations). - Run custom rule conditions on the entire match using the
pattern
name. - Disallow
pattern
from 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-arg
if the arg name is shadowed in the default argument. e.g.def f(arg=[arg])
- Don’t propose
dict-assign-update-to-union
when the update accesses the dict variable - Don’t propose
remove-redundant-except-handler
for non-built-in exceptions - Escape HTML in PyCharm diffs