Skip to content

Fix all 1746 ruff lint errors and add missing class - #60

Draft
cosmic-hydra wants to merge 3 commits into
mainfrom
claude/lucid-ptolemy-Fvg5y
Draft

Fix all 1746 ruff lint errors and add missing class#60
cosmic-hydra wants to merge 3 commits into
mainfrom
claude/lucid-ptolemy-Fvg5y

Conversation

@cosmic-hydra

Copy link
Copy Markdown
Owner

Summary

  • Fixed all 1746 ruff lint errors across 220 files after expanding ruff rules to include bugbear (B), bandit (S), simplify (SIM), and ruff-specific (RUF) checks
  • Added missing PositionalEncoding class in drug_discovery/models/transformer.py (was causing F821 undefined name errors)
  • Fixed 3 real bugs: undefined variable ccol in pipeline.py, missing Any import in similarity_search.py, missing asyncio import in test_2024_breakthroughs.py
  • Auto-fixed 1547 issues: sorted imports (isort), modernized type annotations (Dictdict, Listlist, Optional[T]T | None), removed unused imports, cleaned trailing whitespace
  • Tuned ruff.toml with targeted ignores for false positives (scientific naming conventions, optional dependency detection patterns, simulation randomness, etc.)

This is a follow-up to PR #59 where the lint-and-scan CI check failed due to the expanded ruff configuration catching pre-existing issues across the codebase.

Test plan

  • ruff check . passes with 0 errors
  • Verify CI lint-and-scan job passes
  • Spot-check that auto-fixed imports don't break runtime behavior
  • Confirm PositionalEncoding class works in transformer model tests

Generated by Claude Code

claude added 2 commits June 5, 2026 21:58
Auto-fix pass: sorted imports, modernized type annotations (Dict->dict,
List->list, Optional->T|None), removed trailing whitespace, cleaned
unused imports, and upgraded deprecated patterns across 178 files.

Manual fixes:
- Add missing PositionalEncoding class to drug_discovery/models/transformer.py
  (was undefined, causing F821 at runtime)
- Add missing `Any` import in drug_discovery/drug_repurposing/similarity_search.py
- Add missing `asyncio` import in tests/test_2024_breakthroughs.py
- Tune ruff.toml to suppress false positives for this codebase:
  scientific naming (mRNA), simulation random, optional-dep try/except,
  server binding, and style preferences

Result: `ruff check .` now passes clean (0 errors).

https://claude.ai/code/session_01HUgvX4uQBHnTVQR5BJHjbd
145 files reformatted to comply with black's code style.
Both ruff check and black --check now pass cleanly.

https://claude.ai/code/session_01HUgvX4uQBHnTVQR5BJHjbd

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request focuses on repository-wide code cleanup, including import reorganization, modernizing type annotations, and fixing minor linter warnings. The review feedback identifies a critical runtime error in PositionalEncoding when d_model is odd, points out several dead expressions left over from refactoring, and suggests more Pythonic implementations for list flattening and dictionary iteration.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +21 to +23
pe[:, 0::2] = torch.sin(position * div_term)
pe[:, 1::2] = torch.cos(position * div_term)
pe = pe.unsqueeze(0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation of PositionalEncoding will raise a RuntimeError at runtime if d_model is an odd number. This is because pe[:, 1::2] expects a size of d_model // 2, but div_term has a size of (d_model + 1) // 2 when d_model is odd, leading to a shape mismatch during assignment. Slicing div_term to match the target slice size resolves this issue and makes the encoding robust for both even and odd dimensions.

        div_term = torch.exp(torch.arange(0, d_model, 2).float() * (-math.log(10000.0) / d_model))\n        pe[:, 0::2] = torch.sin(position * div_term)\n        pe[:, 1::2] = torch.cos(position * div_term[:d_model // 2])

Comment on lines 82 to +83
"similarity": round(max_sim, 4),
"commercial_dose": match['commercial_dose'],
"smiles": match['smiles']
"commercial_dose": match["commercial_dose"],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The statement {c['smiles'] for c in zane_compounds} is a useless set comprehension that is evaluated and immediately discarded. Since zane_smiles_set was removed as an unused variable, this statement has no effect and should be removed entirely to avoid unnecessary computation.

Suggested change
"similarity": round(max_sim, 4),
"commercial_dose": match['commercial_dose'],
"smiles": match['smiles']
"commercial_dose": match["commercial_dose"],
comm_smiles = commercial_match.get('smiles', '')

return True

return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since the key _name is unused in the loop, it is more Pythonic and efficient to iterate directly over the dictionary's values using .values() instead of .items().

Suggested change
return False
for smarts in phototoxicity_alerts.values():

Comment on lines 119 to 121
tpsa = float(rdMolDescriptors.CalcTPSA(mol))
logp = float(Crippen.MolLogP(mol))
float(Crippen.MolLogP(mol))
heavy = int(mol.GetNumHeavyAtoms())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The statement float(Crippen.MolLogP(mol)) is a useless expression that computes the LogP value and discards it. Since the logp variable was removed because it was unused, this line should be deleted entirely to save unnecessary CPU cycles during batch processing.

    tpsa = float(rdMolDescriptors.CalcTPSA(mol))\n    heavy = int(mol.GetNumHeavyAtoms())

folds[smallest].extend(ss)
sizes[smallest] += len(ss)
return [(sum([folds[j] for j in range(n_folds) if j != i], []), folds[i]) for i in range(n_folds)]
return [

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using functools.reduce with operator.iadd to flatten a list of lists is overly complex and less readable. A standard list comprehension is much more Pythonic, performs better, and eliminates the need to import functools and operator.

Suggested change
return [
return [([item for j in range(n_folds) if j != i for item in folds[j]], folds[i]) for i in range(n_folds)]

- Comment out equibind/openfold in requirements.txt (not on PyPI)
- Fix PositionalEncoding for odd d_model dimensions
- Remove dead expressions in qm_mm_metabolites.py and fda_drug_matcher.py
- Use .values() instead of .items() when key is unused
- Simplify list flattening with comprehension, remove unused imports

https://claude.ai/code/session_01HUgvX4uQBHnTVQR5BJHjbd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants