Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add standalone command line args #163

Merged
merged 1 commit into from
Mar 23, 2023
Merged

add standalone command line args #163

merged 1 commit into from
Mar 23, 2023

Conversation

jakkdl
Copy link
Member

@jakkdl jakkdl commented Mar 21, 2023

And just for funsies let's open a fourth PR 😁
It's branched on top of #162, so the diff will be slightly smaller once that's merged.

Ready for review, though I can probably polish it a bit if giving it another look tomorrow.
Had a decently long thonk on whether to just have an --enable and no --disable, or whether to get the full flake8 experience with --extend-[...] flags. Settled on this compromise.

91x does not respect --autofix parameter value properly atm, hence the commented out code with that, would like #159 in order to work on that.

Will probably have some merge conflicts and need rebasing once other PR's get merged

@jakkdl jakkdl force-pushed the args branch 4 times, most recently from 334c495 to 4eb714c Compare March 22, 2023 12:20
Copy link
Member Author

@jakkdl jakkdl left a comment

Choose a reason for hiding this comment

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

Lots of minor stuff getting renamed in a million places, but also some substantive changes hidden in the diffs 🙃

flake8_trio/__init__.py Show resolved Hide resolved
flake8_trio/__init__.py Show resolved Hide resolved
flake8_trio/__init__.py Show resolved Hide resolved

@dataclass
class Options:
# enable and disable have been expanded to contain full codes, and have no overlap
Copy link
Member Author

Choose a reason for hiding this comment

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

not sure having both enable and disable is any upside. And if anything should have a enabled_or_autofixed ?

Copy link
Member

Choose a reason for hiding this comment

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

I'd also find it useful to comment on what autofix means here. Might be good to have a more substantial docstring?

And non-redundant data structures are good in general, "make illegal states unrepresentable" etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

ye I realized as I wrote my comment that it was bad design, also renamed the variables and improved comments.

problems: list[Error] = field(default_factory=list)
library: tuple[str, ...] = ()
typed_calls: dict[str, str] = field(default_factory=dict)
variables: dict[str, str] = field(default_factory=dict)


class Flake8TrioRunner(ast.NodeVisitor):
def __init__(self, options: Namespace):
class CommonRunner(ABC): # noqa: B024 # no abstract methods
Copy link
Member Author

Choose a reason for hiding this comment

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

split out so selected doesn't have to be updated in two places

Copy link
Member

Choose a reason for hiding this comment

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

If there are no abstract methods, we don't need to inherit from ABC, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

hm, I like showing in some way that it's not meant to be used/constructed directly .. but I guess I can give it a docstring saying so and add a double underscore to the name. If it was referenced outside the module it'd certainly want to inherit from ABC, but I suppose in that case it's likely it has a method that can be @abstracted

flake8_trio/visitors/helpers.py Show resolved Hide resolved
flake8_trio/visitors/helpers.py Show resolved Hide resolved
Comment on lines -51 to -58
# flake8 6 added a required named parameter formatter_names
def _default_option_manager():
kwargs = {}
if flake8_version_info[0] >= 6:
kwargs["formatter_names"] = ["default"]
return OptionManager(version="", plugin_versions="", parents=[], **kwargs)


Copy link
Member Author

Choose a reason for hiding this comment

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

hell yes! Begone!
That ... might mean we can get rid of some stubs? and I'm not sure we need to parametrize tests on flake8 anymore, though I guess it doesn't really hurt

Copy link
Member

Choose a reason for hiding this comment

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

My usual approach here is to keep the extra tests until the first time you find them annoying, and then delete them unless they've also been useful by then. Maximally lazy development!

Copy link
Member Author

Choose a reason for hiding this comment

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

it doubles runtime of tests in CI, which definitely is quite annoying. I guess one could rejig the CI to run flake8_5 separately, but eh...

Copy link
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

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

Looks good to me; some comments below but feel free to merge when you've addressed them (or decided not to) to your satisfaction 👍


@dataclass
class Options:
# enable and disable have been expanded to contain full codes, and have no overlap
Copy link
Member

Choose a reason for hiding this comment

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

I'd also find it useful to comment on what autofix means here. Might be good to have a more substantial docstring?

And non-redundant data structures are good in general, "make illegal states unrepresentable" etc.

problems: list[Error] = field(default_factory=list)
library: tuple[str, ...] = ()
typed_calls: dict[str, str] = field(default_factory=dict)
variables: dict[str, str] = field(default_factory=dict)


class Flake8TrioRunner(ast.NodeVisitor):
def __init__(self, options: Namespace):
class CommonRunner(ABC): # noqa: B024 # no abstract methods
Copy link
Member

Choose a reason for hiding this comment

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

If there are no abstract methods, we don't need to inherit from ABC, right?

flake8_trio/runner.py Outdated Show resolved Hide resolved
Comment on lines -51 to -58
# flake8 6 added a required named parameter formatter_names
def _default_option_manager():
kwargs = {}
if flake8_version_info[0] >= 6:
kwargs["formatter_names"] = ["default"]
return OptionManager(version="", plugin_versions="", parents=[], **kwargs)


Copy link
Member

Choose a reason for hiding this comment

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

My usual approach here is to keep the extra tests until the first time you find them annoying, and then delete them unless they've also been useful by then. Maximally lazy development!

Comment on lines 321 to 326
for code in enable_codes.split(","):
if error.code.startswith(code):
Copy link
Member

Choose a reason for hiding this comment

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

I'm concerned that a repeated-comma typo would enable everything here, might be worth checking that the code starts with TRIO?

Copy link
Member Author

Choose a reason for hiding this comment

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

got confused for a moment that this was talking about the user-supplied string, but added tests that it won't break for users, and improved logic in the test so it'll warn about bad codes.

flake8_trio/visitors/flake8triovisitor.py Outdated Show resolved Hide resolved
@jakkdl jakkdl merged commit c8061fe into python-trio:main Mar 23, 2023
@jakkdl jakkdl deleted the args branch March 23, 2023 14:24
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