From 9222ee5a51e7c2a2c71ee83364630a5a7c2da29e Mon Sep 17 00:00:00 2001 From: Shyam D Date: Wed, 24 Feb 2021 07:23:10 -0800 Subject: [PATCH] fix mypy issues --- emmet-core/emmet/core/mpid.py | 2 +- emmet-core/emmet/core/vasp/material.py | 16 +--------------- emmet-core/emmet/core/xas.py | 2 +- emmet-core/emmet/core/xrd.py | 2 +- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/emmet-core/emmet/core/mpid.py b/emmet-core/emmet/core/mpid.py index f7a6c4f1ed..553562b46c 100644 --- a/emmet-core/emmet/core/mpid.py +++ b/emmet-core/emmet/core/mpid.py @@ -12,7 +12,7 @@ class MPID(str): mixing with the Materials Project """ - def __lt__(self, other: Union["MPID", int]): + def __lt__(self, other: Union["MPID", int, str]): # Always sort MPIDs before pure integer IDs if isinstance(other, int): diff --git a/emmet-core/emmet/core/vasp/material.py b/emmet-core/emmet/core/vasp/material.py index ca08dec5f5..aed3076d10 100644 --- a/emmet-core/emmet/core/vasp/material.py +++ b/emmet-core/emmet/core/vasp/material.py @@ -71,7 +71,7 @@ def from_tasks( # Material ID possible_mat_ids = [task.task_id for task in structure_optimizations] - possible_mat_ids = sorted(possible_mat_ids, key=ID_to_int) + possible_mat_ids = sorted(possible_mat_ids) if len(possible_mat_ids) == 0: raise Exception(f"Could not find a material ID for {task_ids}") @@ -157,17 +157,3 @@ def _structure_eval(task: TaskDocument): origins=origins, entries=entries, ) - - -def ID_to_int(s_id: str) -> Tuple[str, int]: - """ - Converts a string id to tuple - falls back to assuming ID is an Int if it can't process - Assumes string IDs are of form "[chars]-[int]" such as mp-234 - """ - if isinstance(s_id, str): - return (s_id.split("-")[0], int(str(s_id).split("-")[-1])) - elif isinstance(s_id, (int, float)): - return ("", s_id) - else: - return None diff --git a/emmet-core/emmet/core/xas.py b/emmet-core/emmet/core/xas.py index a00b173cbe..be177c898f 100644 --- a/emmet-core/emmet/core/xas.py +++ b/emmet-core/emmet/core/xas.py @@ -1,5 +1,5 @@ from datetime import datetime -from typing import List, Optional +from typing import List, Optional, Union from pydantic import BaseModel, Field, root_validator from pymatgen.analysis.xas.spectrum import XAS diff --git a/emmet-core/emmet/core/xrd.py b/emmet-core/emmet/core/xrd.py index cc227d2d1d..ba4bdd5d22 100644 --- a/emmet-core/emmet/core/xrd.py +++ b/emmet-core/emmet/core/xrd.py @@ -1,5 +1,5 @@ from enum import Enum -from typing import Dict, List, Optional, Tuple +from typing import Dict, List, Optional, Tuple, Union import numpy as np from pydantic import BaseModel, Field, root_validator