Skip to content

Conversation

@grahamlyons
Copy link
Contributor

pyformat does a lovely job of wrapping autoflake to make changes recommended by a linter. autoflake allows unused imports and variables to be removed, but the required flags aren't passed by pyformat.

This adds the ability, in "aggressive" mode, to request that all unused imports (not just standard library) and variables be removed (by autoflake).

pyformat.py Outdated
help='use more aggressive formatters')
parser.add_argument('--remove-all-unused-imports', action='store_true',
help='remove all unused imports, not just standard library \
(requires "aggresive")')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to avoid escaped newlines. Could you format that strings the way it is done below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was just to reduce the line length - I've used another solution (which I now see you've used in other places).

parser.add_argument('--remove-all-unused-imports', action='store_true',
help='remove all unused imports, not just standard library \
(requires "aggresive")')
parser.add_argument('--remove-unused-variables', action='store_true',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to add a check to make sure that --aggressive is used. Otherwise, the user might wonder why it isn't working. Maybe something like:

if args.remove_unused_variables and not args.aggressive:
    parser.error('--remove-unused-variables requires --aggressive')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed - good call.

@grahamlyons
Copy link
Contributor Author

Updated, and spelling mistakes corrected.

@myint myint merged commit 8d01c3c into myint:master Dec 14, 2016
@myint
Copy link
Owner

myint commented Dec 14, 2016

Thanks!

@grahamlyons
Copy link
Contributor Author

Thanks for merging this, @myint. When do you release to PyPI?

@myint
Copy link
Owner

myint commented Jan 4, 2017

@grahamlyons
Copy link
Contributor Author

Brillo. Thank you and happy New Year.

@grahamlyons grahamlyons deleted the remove_imports_and_variables branch September 25, 2019 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants