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 import order for if TYPE_CHECKING: block #3711

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
from monty.json import MSONable
from scipy.spatial import Voronoi

if TYPE_CHECKING:
from typing_extensions import Self

from pymatgen.analysis.chemenv.utils.coordination_geometry_utils import (
get_lower_and_upper_f,
rectangle_surface_intersection,
Expand All @@ -24,6 +21,9 @@
from pymatgen.core.sites import PeriodicSite
from pymatgen.core.structure import Structure

if TYPE_CHECKING:
from typing_extensions import Self

__author__ = "David Waroquiers"
__copyright__ = "Copyright 2012, The Materials Project"
__credits__ = "Geoffroy Hautier"
Expand Down
6 changes: 3 additions & 3 deletions pymatgen/analysis/molecule_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@

from pymatgen.core.structure import Molecule

if TYPE_CHECKING:
from typing_extensions import Self

try:
from openbabel import openbabel

from pymatgen.io.babel import BabelMolAdaptor
except ImportError:
openbabel = None

if TYPE_CHECKING:
from typing_extensions import Self


__author__ = "Xiaohui Qu, Adam Fekete"
__version__ = "1.0"
Expand Down
1 change: 1 addition & 0 deletions pymatgen/electronic_structure/boltztrap2.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
except ImportError:
raise BoltztrapError("BoltzTraP2 has to be installed and working")


__author__ = "Francesco Ricci"
__copyright__ = "Copyright 2018, The Materials Project"
__version__ = "1.0"
Expand Down
14 changes: 7 additions & 7 deletions pymatgen/io/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@

from pymatgen.core.structure import Molecule, Structure

if TYPE_CHECKING:
from typing import Any

from numpy.typing import ArrayLike

from pymatgen.core.structure import SiteCollection

try:
from ase.atoms import Atoms
from ase.calculators.singlepoint import SinglePointDFTCalculator
Expand All @@ -38,6 +31,13 @@ def __init__(self, *args, **kwargs):
raise no_ase_err


Copy link
Member

Choose a reason for hiding this comment

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

i would stick to single blank line above if TYPE_CHECKING:. would be nice if ruff enforced this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to remove the extra blank line but ruff added it back. ruff seem to have a weird interaction with if TYPE_CHECKING: for some reason?

Copy link
Member

Choose a reason for hiding this comment

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

i see, no worries. not that important

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing. I guess for such issues we'd better wait until ruff has some solution (or perhaps already has but we don't know about), and run ruff to fix all issues.

if TYPE_CHECKING:
from typing import Any

from numpy.typing import ArrayLike

from pymatgen.core.structure import SiteCollection

__author__ = "Shyue Ping Ong, Andrew S. Rosen"
__copyright__ = "Copyright 2012, The Materials Project"
__version__ = "1.0"
Expand Down
9 changes: 5 additions & 4 deletions pymatgen/io/lammps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
from pymatgen.io.packmol import PackmolBoxGen
from pymatgen.util.coord import get_angle

try:
from openbabel import pybel
except ImportError:
pybel = None

if TYPE_CHECKING:
from collections.abc import Sequence

from numpy.typing import ArrayLike

try:
from openbabel import pybel
except ImportError:
pybel = None

__author__ = "Kiran Mathew, Brandon Wood, Michael Humbert"
__email__ = "[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/io/vasp/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
from pymatgen.util.io_utils import clean_lines, micro_pyawk
from pymatgen.util.num import make_symmetric_matrix_from_upper_tri

logger = logging.getLogger(__name__)

if TYPE_CHECKING:
from typing_extensions import Self

logger = logging.getLogger(__name__)


def _parse_parameters(val_type, val):
"""
Expand Down
1 change: 0 additions & 1 deletion pymatgen/phonon/thermal_displacements.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from numpy.typing import ArrayLike
from typing_extensions import Self


__author__ = "J. George"
__copyright__ = "Copyright 2022, The Materials Project"
__version__ = "0.1"
Expand Down
1 change: 1 addition & 0 deletions pymatgen/symmetry/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from pymatgen.symmetry.groups import CrystalSystem

logger = logging.getLogger(__name__)

LatticeType = Literal["cubic", "hexagonal", "monoclinic", "orthorhombic", "rhombohedral", "tetragonal", "triclinic"]

cite_conventional_cell_algo = due.dcite(
Expand Down
11 changes: 6 additions & 5 deletions pymatgen/util/provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@

from pymatgen.core.structure import Molecule, Structure

if TYPE_CHECKING:
from collections.abc import Sequence

from typing_extensions import Self

try:
from pybtex import errors
from pybtex.database.input import bibtex
except ImportError:
pybtex = bibtex = None

if TYPE_CHECKING:
from collections.abc import Sequence

from typing_extensions import Self


__author__ = "Anubhav Jain, Shyue Ping Ong"
__credits__ = "Dan Gunter"

Expand Down
6 changes: 3 additions & 3 deletions pymatgen/vis/structure_vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
from pymatgen.core import PeriodicSite, Species, Structure
from pymatgen.util.coord import in_coord_list

if TYPE_CHECKING:
from collections.abc import Sequence

try:
import vtk
from vtk import vtkInteractorStyleTrackballCamera as TrackballCamera
DanielYang59 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -27,6 +24,9 @@
vtk = None
TrackballCamera = object

if TYPE_CHECKING:
from collections.abc import Sequence

module_dir = os.path.dirname(os.path.abspath(__file__))
EL_COLORS = loadfn(f"{module_dir}/ElementColorSchemes.yaml")

Expand Down
3 changes: 2 additions & 1 deletion tests/core/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

from typing import TYPE_CHECKING

from pymatgen.core import _load_pmg_settings

if TYPE_CHECKING:
from pathlib import Path

from pytest import MonkeyPatch

from pymatgen.core import _load_pmg_settings

__author__ = "Janosh Riebesell"
__date__ = "2022-10-21"
Expand Down