Zac-HD / shed

`shed` canonicalises Python code. Shed your legacy, stop bikeshedding, and move on. Black++
https://pypi.org/project/shed/
GNU Affero General Public License v3.0
343 stars 23 forks source link

Fix one example of invalid code produced by refactoring #85

Closed DRMacIver closed 1 year ago

DRMacIver commented 1 year ago

This pull request makes it so:


if isinstance(x, int) or isinstance(x, float):
    pass

This is one of the issues from #84 but this PR doesn't address the others.

Correctly transforms to

if isinstance(x, (int, float)):
    pass

The underlying issue is https://github.com/Instagram/LibCST/issues/888 which this works around by creating a wrapper decorator that implements the (to me, and implicitly to you when you wrote this code assuming it!) desired behaviour of not running a transformation if it doesn't apply to the current version of the code after previous transformations have run.

This results in a change to example C414.txt where previously list(list(iterable)) was being incorrectly transformed to iterable when it should have been transformed to list(iterable).

Probably there were other examples of this sort of problem lurking in shed, but I haven't made any attempt to trigger them.