Skip to content

Commit

Permalink
Try make mypy happy about str
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerwooo committed Feb 10, 2025
1 parent aedd558 commit 5bfbab5
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion torchattack/att.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(
if hook_cfg:
# Explicit config name takes precedence over inferred model.model_name
self.hook_cfg = hook_cfg
elif hasattr(model, 'model_name'):
elif isinstance(model, AttackModel):
# If model is initialized via `torchattack.AttackModel`, the model_name
# is automatically attached to the model during instantiation.
self.hook_cfg = model.model_name
Expand Down
2 changes: 1 addition & 1 deletion torchattack/dr.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(

# If model is initialized via `torchattack.AttackModel`, infer its model_name
# from automatically attached attribute during instantiation.
if not model_name and hasattr(model, 'model_name'):
if not model_name and isinstance(model, AttackModel):
model_name = model.model_name

self.eps = eps
Expand Down
2 changes: 1 addition & 1 deletion torchattack/pna_patchout.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(
if hook_cfg:
# Explicit config name takes precedence over inferred model.model_name
self.hook_cfg = hook_cfg
elif hasattr(model, 'model_name'):
elif isinstance(model, AttackModel):
# If model is initialized via `torchattack.AttackModel`, the model_name
# is automatically attached to the model during instantiation.
self.hook_cfg = model.model_name
Expand Down
2 changes: 1 addition & 1 deletion torchattack/tgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(
if hook_cfg:
# Explicit config name takes precedence over inferred model.model_name
self.hook_cfg = hook_cfg
elif hasattr(model, 'model_name'):
elif isinstance(model, AttackModel):
# If model is initialized via `torchattack.AttackModel`, the model_name
# is automatically attached to the model during instantiation.
self.hook_cfg = model.model_name
Expand Down
3 changes: 1 addition & 2 deletions torchattack/vdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ def __init__(
if hook_cfg:
# Explicit config name takes precedence over inferred model.model_name
self.hook_cfg = hook_cfg
elif hasattr(model, 'model_name'):
elif isinstance(model, AttackModel):
# If model is initialized via `torchattack.AttackModel`, the model_name
# is automatically attached to the model during instantiation.
assert isinstance(str, model.model_name)
self.hook_cfg = model.model_name

self.eps = eps
Expand Down

0 comments on commit 5bfbab5

Please sign in to comment.