-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
Format generated Python parser module #347
base: main
Are you sure you want to change the base?
Conversation
c50567f
to
ab8bc7c
Compare
I’m 👎 for this change:
the reason is that you should be able to subclass AstParser and override |
- Removes configuring exclusion of any Python modules from formatting - Ensure entire library is formatted correctly - Drop redundant `or False` logic from conditionals - Drop redundant `else` conditionals after `return` within `if` clause - Skipped formatting on `state_comment` string - Challenging to generate formatted Python multiline string from C#
- Faster tooling - Better handling with linting rule conflicts - Enables extending to hundreds of linting rules - Aligns with pytest-bdd (pytest-dev/pytest-bdd#758)
ab8bc7c
to
52864a5
Compare
Makes sense - applied! Had been unsure on the same for a somewhat related reason - being too implicit by assessing "truthiness" rather than the explicit type declarations - which could become a consideration with changes down the line should users begin passing additional values. Accustomed to using in a local context without this consideration. Interesting, thank you. |
🤔 What's changed?
Token.detach
method in generated parser codeblack
toruff
ruff check gherkin/parser.py --select=I001
)or False
logic from conditionals - RET505 (ruff check gherkin/parser.py --select=RET505
)ast_builder
instance assignmentself.ast_builder = ast_builder if ast_builder is not None else AstBuilder()
->self.ast_builder = ast_builder or AstBuilder()
or
statements toany
call⚡️ What's your motivation?
black
code formatter to the python codebase #286match_token_at_'x'
methods to just 4 - which had been difficult to read and was most-likely a workaround in the generator code to satisfy both cases of running inside conditionals (with 4 spaces) and outside conditionals (8 spaces) without handling appropriately; aSyntaxError
would be raised if standardised to 4 spaces without handling (as per this pull request)ruff
is monorepo-friendly, with hierarchical and cascading configuration - which is ideal for this repository: allowing configuration to be stored within thepython
directory while allowing pre-commit, IDEs and commands run from the root of the repositoryblack
,flake8
,isort
,pyupgrade
linters and formatters toruff
pytest-dev/pytest-bdd#758)or False
is redundant - assume added as a safeguard where the proceeding args are not present (defaults to just ‘False’ in that case) pots generation - however the unit tests protect against this, failing if the args aren’t generatedany
calls against a comma-separate iterable compared to a series ofor
statements where it can't be applied on every lineelse
is redundant (superflous-else-return - RET505)useless-expression
(B018)token.detach
- updated code invokes appropriately though this doesn't actually alter behaviour (being a no-operation method) though conforms to intention and other parser implementation🏷️ What kind of change is this?
♻️ Anything particular you want feedback on?
Thoughts whether a
CHANGELOG
entry is warranted?To evaluate changes are formatted correctly:
Open a codespace (or locally alternatively):
Regenerate all parser implementations:
From a separate terminal window, install the pre-commit hook and validate all Python code is formatted (including the generated parser code):
Run Python unit and acceptance tests to validate no regression in the generated parser implementation:
Have skipped formatting on
state_comment
stringIntend to update GitHub Actions workflow in a follow up pull request to validate, or fully assess use of pre-commit-ci with this polyglot repo
📋 Checklist: