chore: enforce type hints across attacks, config, and safemodel modules#422
chore: enforce type hints across attacks, config, and safemodel modules#422shamykyzer wants to merge 20 commits intomainfrom
Conversation
for more information, see https://pre-commit.ci
1cb8014 to
ec98cae
Compare
|
Looks like a good start - anything and everything we can lock down the better - adding them to the variable definitions inside functions too would be good because it's such an easy way to catch any unexpected behaviour. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #422 +/- ##
==========================================
- Coverage 99.51% 99.51% -0.01%
==========================================
Files 23 23
Lines 2687 2686 -1
==========================================
- Hits 2674 2673 -1
Misses 13 13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Signed-off-by: Shamy <110725453+shamykyzer@users.noreply.github.com>
|
hello @rpreen, can you have a look at this and let me know if there is anything you want me to add or change? |
|
This also needs a slight change to |
|
Hi @rpreen , I was going through the type hints and ran into a couple of things worth noting:
Also found what I think is a pre-existing bug: It works correctly when saving but not during loading, was this intentional? |
Good find - we need a bug fix PR for this as high priority. |
Thankfully it looks like this doesn't actually effect anything because the test indices aren't used when computing the LiRA scores (the check is simply if not in train indices) - but still important to fix in case they get used in future code. |
|
@shamykyzer nice find!. this is why collaborative s/w is best |
|
Hello @rpreen, can you review this PR when you get a chance?
Should I expand the mypy files list beyond the current 8 files and are the 16 Any usages fine or should I narrow them? Also, current ruff configuration only flags missing hints, wouldn't it be worth adding monkeytype or autotyping to auto-generate them going forward? Or is it good as it is? Thanks. |
|
This looks good as it is I think - I don't think we need to have everything perfectly typed, just adding as much as we can sensibly helps. I don't know enough about auto-generating types to comment on whether that would be useful to add - but I would think that is not something that would be added to Ruff/pre-commit, but would be done in a special PR like this (or a future one) and carefully reviewed. I suspect that since you have 99% done here that an auto-generator would likely struggle with the remaining complex cases and possibly just put My only last question here: is there a reason for removing the existing types from We can expand more files later. |
Well, I thought since every function now has type annotations on its parameters and return values, mypy will infer the local variable types from the function call so annotating the variable too would've been redundant. Here Same with This applies to all the removed annotations in both files, happy to restore them if you prefer? Also I agree on expanding later, I think the |
Linting & CI:
ANNrule set to require type hints on all function signaturesANN401to permitAnyin cases where interfaces are intentionally dynamicmypy(v1.19.1) pre-commit hook for static type analysisAnnotations:
attacks/,config/, andsafemodel/Cleanup:
PyTorchDataHandler,SklearnDataHandler) fromtarget.pyCloses #415