Skip to content

Hide all type-hint-only imports behind if TYPE_CHECKING - #2992

Merged
janosh merged 6 commits into
masterfrom
ruff-tch
May 16, 2023
Merged

Hide all type-hint-only imports behind if TYPE_CHECKING#2992
janosh merged 6 commits into
masterfrom
ruff-tch

Conversation

@janosh

@janosh janosh commented May 16, 2023

Copy link
Copy Markdown
Member

4 main motivations for this change:

  1. reduces chance of circular imports
  2. can help contributors run tests without installing extra deps like pymatgen.analysis.defects if they were previously in a test's import stack but only used for type hints
  3. helps with readability by clearly separating type-only imports
  4. can decrease startup time since TYPE_CHECKING=False at run time means some modules won't have to be imported. somewhat negated by the annoyingly long import time of the std lib typing module itself but that has been steadily coming down with newer Python versions.

@janosh janosh added linting Linting and quality assurance types Type all the things imports Import changes and formatting labels May 16, 2023
@janosh
janosh enabled auto-merge (squash) May 16, 2023 15:10
@janosh

janosh commented May 16, 2023

Copy link
Copy Markdown
Member Author

Ci failure is due to flaky test:

    @unittest.skipIf(
        not SETTINGS.get("PMG_MAPI_KEY") or website_down,
        "PMG_MAPI_KEY environment variable not set or MP is down.",
    )
    def test_get_snls_mp(self):
        with OptimadeRester("mp") as optimade:
            structs = optimade.get_snls(elements=["Ga", "N"], nelements=2)
    
        with OptimadeRester("mp") as optimade:
            response_field_structs_single = optimade.get_snls(
                elements=["Ga", "N"], nelements=2, additional_response_fields="nsites"
            )
            response_field_structs_set = optimade.get_snls(
                elements=["Ga", "N"], nelements=2, additional_response_fields={"nsites", "nelements"}
            )
            if ("mp" in response_field_structs_single) and ("mp" in response_field_structs_set):
>               assert len(structs["mp"]) == len(response_field_structs_single["mp"])
E               KeyError: 'mp'

pymatgen/ext/tests/test_optimade.py:55: KeyError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

imports Import changes and formatting linting Linting and quality assurance types Type all the things

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant