Skip to content

Commit

Permalink
update isort and imports for min py38
Browse files Browse the repository at this point in the history
  • Loading branch information
loriab committed Nov 27, 2024
1 parent 69e557c commit 69491d3
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 80 deletions.
4 changes: 1 addition & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ repos:
- id: detect-secrets
stages: [commit]
exclude: "raw_data/nist_data/"
# TODO: Update to 5.12.x once we drop Python3.7 support
# https://levelup.gitconnected.com/fix-runtimeerror-poetry-isort-5db7c67b60ff
- repo: https://github.com/PyCQA/isort
rev: 5.11.5
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/psf/black
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test = [
lint = [
"pre-commit",
"black >=22.1.0,<23.0a0", # if running outside of pre-commit
"isort ==5.11.5", # if running outside of pre-commit
"isort >=5.13.2", # if running outside of pre-commit
# "mypy",
# "autoflake",
# "flake8",
Expand Down
8 changes: 1 addition & 7 deletions qcelemental/models/v1/basis.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from enum import Enum
from typing import Dict, List, Optional

try:
from typing import Literal
except ImportError:
# remove when minimum py38
from typing_extensions import Literal
from typing import Dict, List, Literal, Optional

from pydantic.v1 import ConstrainedInt, Field, constr, validator

Expand Down
8 changes: 1 addition & 7 deletions qcelemental/models/v1/procedures.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from enum import Enum
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union

try:
from typing import Literal
except ImportError:
# remove when minimum py38
from typing_extensions import Literal
from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, Tuple, Union

from pydantic.v1 import Field, conlist, constr, validator

Expand Down
8 changes: 1 addition & 7 deletions qcelemental/models/v1/results.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from enum import Enum
from functools import partial
from typing import TYPE_CHECKING, Any, Dict, Optional, Set, Union

try:
from typing import Literal
except ImportError:
# remove when minimum py38
from typing_extensions import Literal
from typing import TYPE_CHECKING, Any, Dict, Literal, Optional, Set, Union

import numpy as np
from pydantic.v1 import Field, constr, validator
Expand Down
8 changes: 1 addition & 7 deletions qcelemental/models/v2/basis.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from enum import Enum
from typing import Dict, List, Optional

try:
from typing import Literal
except ImportError:
# remove when minimum py38
from typing_extensions import Literal
from typing import Dict, List, Literal, Optional

from pydantic import Field, constr, field_validator
from typing_extensions import Annotated
Expand Down
8 changes: 1 addition & 7 deletions qcelemental/models/v2/common_models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from enum import Enum
from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, Tuple, Union

try:
from typing import Literal
except ImportError:
# remove when minimum py38
from typing_extensions import Literal
from typing import TYPE_CHECKING, Any, Dict, Literal, Optional, Sequence, Tuple, Union

import numpy as np
from pydantic import Field, field_validator
Expand Down
8 changes: 1 addition & 7 deletions qcelemental/models/v2/procedures.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from enum import Enum
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union

try:
from typing import Literal
except ImportError:
# remove when minimum py38
from typing_extensions import Literal
from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, Tuple, Union

from pydantic import Field, conlist, constr, field_validator

Expand Down
8 changes: 1 addition & 7 deletions qcelemental/models/v2/results.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from enum import Enum
from functools import partial
from typing import TYPE_CHECKING, Any, Dict, Optional, Set, Union

try:
from typing import Literal
except ImportError:
# remove when minimum py38
from typing_extensions import Literal
from typing import TYPE_CHECKING, Any, Dict, Literal, Optional, Set, Union

import numpy as np
from pydantic import Field, constr, field_validator
Expand Down
36 changes: 9 additions & 27 deletions qcelemental/tests/test_model_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,13 +898,9 @@ def test_model_survey_success(smodel1, smodel2, every_model_fixture, request, sc
instance = model(**data)
fld = "success"
if ans is None:
cptd = getattr(instance, fieldsattr)
assert fld not in cptd, f"[a] field {fld} unexpectedly present: {cptd}"
# py38: assert fld not in (cptd := getattr(instance, fieldsattr)), f"[a] field {fld} unexpectedly present: {cptd}"
assert fld not in (cptd := getattr(instance, fieldsattr)), f"[a] field {fld} unexpectedly present: {cptd}"
else:
cptd = getattr(instance, fld, "not found!")
assert cptd == ans, f"[a] field {fld} = {cptd} != {ans}"
# py38: assert (cptd := getattr(instance, fld, "not found!")) == ans, f"[a] field {fld} = {cptd} != {ans}"
assert (cptd := getattr(instance, fld, "not found!")) == ans, f"[a] field {fld} = {cptd} != {ans}"

# check success override
if ans is not None:
Expand All @@ -913,15 +909,11 @@ def test_model_survey_success(smodel1, smodel2, every_model_fixture, request, sc
# v2 has enforced T/F
with pytest.raises(pydantic.ValidationError) as e:
instance = model(**data)
cptd = getattr(instance, fld, "not found!")
assert cptd == ans, f"[b] field {fld} = {cptd} != {ans}"
# py38: assert (cptd := getattr(instance, fld, "not found!")) == ans, f"[b] field {fld} = {cptd} != {ans}"
assert (cptd := getattr(instance, fld, "not found!")) == ans, f"[b] field {fld} = {cptd} != {ans}"
else:
# v1 can be reset to T/F
instance = model(**data)
cptd = getattr(instance, fld, "not found!")
assert cptd == (not ans), f"[b] field {fld} = {cptd} != {not ans}"
# py38: assert (cptd := getattr(instance, fld, "not found!")) == (not ans), f"[b] field {fld} = {cptd} != {not ans}"
assert (cptd := getattr(instance, fld, "not found!")) == (not ans), f"[b] field {fld} = {cptd} != {not ans}"


@pytest.mark.parametrize("smodel1,smodel2", _model_classes_struct)
Expand Down Expand Up @@ -976,13 +968,9 @@ def test_model_survey_schema_version(smodel1, smodel2, every_model_fixture, requ
instance = model(**data)
fld = "schema_version"
if ans is None:
cptd = getattr(instance, fieldsattr)
assert fld not in cptd, f"[a] field {fld} unexpectedly present: {cptd}"
# py38: assert fld not in (cptd := getattr(instance, fieldsattr)), f"[a] field {fld} unexpectedly present: {cptd}"
assert fld not in (cptd := getattr(instance, fieldsattr)), f"[a] field {fld} unexpectedly present: {cptd}"
else:
cptd = getattr(instance, fld, "not found!")
assert cptd == ans, f"[a] field {fld} = {cptd} != {ans}"
# py38: assert (cptd := getattr(instance, fld, "not found!")) == ans, f"[a] field {fld} = {cptd} != {ans}"
assert (cptd := getattr(instance, fld, "not found!")) == ans, f"[a] field {fld} = {cptd} != {ans}"

# check version override
if ans is not None:
Expand All @@ -994,9 +982,7 @@ def test_model_survey_schema_version(smodel1, smodel2, every_model_fixture, requ
else:
instance = model(**data)
# "v1" used to be changeable, but now the version is a stamp, not a signal
cptd = getattr(instance, fld, "not found!")
assert cptd == ans, f"[b] field {fld} = {cptd} != {ans}"
# py38: assert (cptd := getattr(instance, fld, "not found!")) == ans, f"[b] field {fld} = {cptd} != {ans}"
assert (cptd := getattr(instance, fld, "not found!")) == ans, f"[b] field {fld} = {cptd} != {ans}"


@pytest.mark.parametrize("smodel1,smodel2", _model_classes_struct)
Expand Down Expand Up @@ -1051,13 +1037,9 @@ def test_model_survey_extras(smodel1, smodel2, every_model_fixture, request, sch
instance = model(**data)
fld = "extras"
if ans is None:
cptd = getattr(instance, fieldsattr)
assert fld not in cptd, f"[a] field {fld} unexpectedly present: {cptd}"
# py38: assert fld not in (cptd := getattr(instance, fieldsattr)), f"[a] field {fld} unexpectedly present: {cptd}"
assert fld not in (cptd := getattr(instance, fieldsattr)), f"[a] field {fld} unexpectedly present: {cptd}"
else:
cptd = getattr(instance, fld, "not found!")
assert cptd == ans, f"[a] field {fld} = {cptd} != {ans}"
# py38: assert (cptd := getattr(instance, fld, "not found!")) == ans, f"[a] field {fld} = {cptd} != {ans}"
assert (cptd := getattr(instance, fld, "not found!")) == ans, f"[a] field {fld} = {cptd} != {ans}"


@pytest.mark.parametrize("smodel1,smodel2", _model_classes_struct)
Expand Down

0 comments on commit 69491d3

Please sign in to comment.