Skip to content

Commit

Permalink
refactor (#287)
Browse files Browse the repository at this point in the history
* lint all aisdc subpackages

* remove useless pylint suppression and clean up

* refactor

* clean up

* upgrade Python syntax

* remove unncessary assignments before return

* clean up imports

* clean up

* clean up

* clean up

* simplifiy

* pep8 naming

* remove useless pylint suppression

* add type hints

* add type hints; clean up

* standardise variable naming; clean up

* add type hints

* standardising naming
  • Loading branch information
rpreen authored Jun 16, 2024
1 parent cb1ab69 commit 790e17f
Show file tree
Hide file tree
Showing 63 changed files with 1,132 additions and 1,271 deletions.
1 change: 1 addition & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ ignore:
- "aisdc/safemodel/classifiers/new_model_template.py"
- "aisdc/preprocessing"
- "user_stories"
- "examples"
...
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ jobs:
- name: pylint
run: |
pylint -v --recursive=True aisdc.safemodel aisdc.attacks tests --fail-under 10
pylint -v --recursive=True aisdc tests --fail-under 10
...
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $ pip install aisdc[safemodel]

## Running

To run an example, simply execute the desired script or start up `jupyter notebook` and run one of the notebooks. For example, to run the LiRA example:
To run an example, simply execute the desired script. For example, to run LiRA:

```
$ python -m lira_attack_example
Expand Down
11 changes: 5 additions & 6 deletions aisdc/attacks/attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
class Attack:
"""Base (abstract) class to represent an attack."""

def __init__(self):
def __init__(self) -> None:
self.attack_config_json_file_name = None

def attack(self, target: Target) -> None:
"""Run an attack."""
raise NotImplementedError

def __str__(self):
def __str__(self) -> str:
"""Return the string representation of an attack."""
raise NotImplementedError

Expand All @@ -28,17 +28,16 @@ def _update_params_from_config_file(self) -> None:
setattr(self, key, value)

@classmethod
def _get_param_names(cls):
def _get_param_names(cls) -> list[str]:
"""Get parameter names."""
init_signature = inspect.signature(cls.__init__)
parameters = [
return [
p.name
for p in init_signature.parameters.values()
if p.name != "self" and p.kind != p.VAR_KEYWORD
]
return parameters

def get_params(self):
def get_params(self) -> dict:
"""Get parameters for this attack.
Returns
Expand Down
Loading

0 comments on commit 790e17f

Please sign in to comment.