Skip to content

Commit

Permalink
fix mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamd committed Feb 24, 2021
1 parent 70e5f1f commit 9222ee5
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 18 deletions.
2 changes: 1 addition & 1 deletion emmet-core/emmet/core/mpid.py
Expand Up @@ -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):
Expand Down
16 changes: 1 addition & 15 deletions emmet-core/emmet/core/vasp/material.py
Expand Up @@ -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}")
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion 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
Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Down

0 comments on commit 9222ee5

Please sign in to comment.