-
Notifications
You must be signed in to change notification settings - Fork 174
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
Introduce mypy, ruff, and pre-commit #1215
Open
corrylc
wants to merge
12
commits into
panther-labs:main
Choose a base branch
from
corrylc:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
While isort and ruff mostly agree, ruff won't remove blank lines.
Hey @corrylc sorry for the delay on this! At this point ruff and mypy are core elements of pypanther. I don't think it makes sense to add mypy to panther-analysis, but adding a ruff pre-commit makes a lot of sense. Would you mind updating this to just add ruff? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
When writing detections for Panther, I would like to use as much python type hinting as possible, while also reducing the bugs that I run into. To enable this,
mypy
andruff
allow for extensive code quality and type hinting checks.I am open to breaking this PR up if the ruff/pre-commit portions are not acceptable upstream. While I think they would help with panther-analysis code quality, I don't want them to cause the type hinting improvements to be rejected.
In my experience
ruff
has totally supplanted pylint/flake8 as the best linting tool for Python as it is a superset of nearly all other tools, and is also radically faster.Changes
panther_base_helpers.py
and directly adjacent code until mypy was error freepanther_base_helpers.py
and directly adjacent code, then modified ruleset to align to Panther code patternspanther_base_helpers.py
and directly adjacent codeQuestions
dict
,Mapping
, andPantherEvent
(rarely) as hints for theevent
object that gets passed around. Whiledict
is not really appropriate in many cases, it isn't always clear whetherMapping
orPantherEvent
is the best choice. Open to thoughts here.ruff-format
is meant to be equivalent toblack
which is already in use in this codebase. Y'all may want to switch to it in time, since it is much faster, or remove it from this commit if you prefer usingblack
everywhere.python-core
(and to a lesser degreepanther_detection_helpers
) is not marked as having types. I would be happy to address that, but the repos are not public. Typing those libraries are the best next step.