Skip to content
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

Fix mypy errors #31

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/rxn/chemutils/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from .exceptions import InvalidInchi, InvalidMdl, InvalidSmiles, SanitizationError

RDLogger.logger().setLevel(RDLogger.CRITICAL)
RDLogger.logger().setLevel(RDLogger.CRITICAL) # type: ignore[no-untyped-call]


def smiles_to_mol(
Expand Down Expand Up @@ -57,7 +57,7 @@ def smiles_to_mol(
# function, either with no sanitization, or with radical finding.
if not sanitize:
if find_radicals:
sanitizations = [Chem.SANITIZE_FINDRADICALS]
sanitizations: List[SanitizeFlags | int] = [Chem.SANITIZE_FINDRADICALS]
else:
sanitizations = [Chem.SANITIZE_NONE]

Expand All @@ -84,7 +84,7 @@ def inchi_to_mol(inchi: str, sanitize: bool = True, removeHs: bool = True) -> Mo
Returns:
Mol instance.
"""
mol = MolFromInchi(inchi, sanitize=sanitize, removeHs=removeHs)
mol: Mol = MolFromInchi(inchi, sanitize=sanitize, removeHs=removeHs) # type: ignore[no-untyped-call]
if not inchi or mol is None:
raise InvalidInchi(inchi)

Expand All @@ -97,7 +97,7 @@ def mol_to_smiles(mol: Mol, canonical: bool = True, isomericSmiles: bool = True)

Mainly a wrapper around MolToSmiles.
"""
return MolToSmiles(mol, canonical=canonical, isomericSmiles=isomericSmiles) # type: ignore
return MolToSmiles(mol, canonical=canonical, isomericSmiles=isomericSmiles)


def mdl_to_mol(mdl: str, sanitize: bool = True) -> Mol:
Expand Down Expand Up @@ -130,7 +130,7 @@ def mol_to_mdl(mol: Mol) -> str:

Mainly a wrapper around MolToMolBlock.
"""
return MolToMolBlock(mol) # type: ignore
return MolToMolBlock(mol)


def sanitize_mol(
Expand Down Expand Up @@ -239,7 +239,7 @@ def canonicalize_smiles(smiles: str, check_valence: bool = True) -> str:

# Sanitization as a separate step, to enable exclusion of valence check
try:
excluded_sanitizations = []
excluded_sanitizations: List[SanitizeFlags | int] = []
if not check_valence:
excluded_sanitizations.append(Chem.SANITIZE_PROPERTIES)
sanitize_mol(mol, exclude_sanitizations=excluded_sanitizations)
Expand Down
4 changes: 2 additions & 2 deletions src/rxn/chemutils/miscellaneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def atom_type_counter(smiles: str) -> typing.Counter[str]:
"""

mol: Mol = AddHs(smiles_to_mol(smiles, sanitize=False))
atoms: List[Atom] = mol.GetAtoms()
atoms: List[Atom] = mol.GetAtoms() # type: ignore[call-arg,no-untyped-call]
return Counter(atom.GetSymbol() for atom in atoms)


Expand Down Expand Up @@ -327,7 +327,7 @@ def mol_has_atom_mapping(mol: Mol) -> bool:
mol: RDKit Mol.
"""
atom: Atom
for atom in mol.GetAtoms():
for atom in mol.GetAtoms(): # type: ignore[call-arg,no-untyped-call]
if atom.GetAtomMapNum() != 0:
return True
return False
Expand Down
Loading