Skip to content

Commit

Permalink
[typing] Fix wrong mypy typing annotations (#4879)
Browse files Browse the repository at this point in the history
* Fix mypy abqpy issues

* Mypy typings

* Update typing annotations for SymbolicConstants

* Fixing typings

* Add future annotations

* Use list/dict/tuple instead of List/Dict/Tuple

* Fix Optional typings

* Add future annotations

* Update xyPlot.py

* Update .pre-commit-config.yaml

* Fix list typings for Python 3.7/3.8

* Fixing more typings

* Fix more typings

* Update conf.py

* Update .pre-commit-config.yaml

* Revert "Update conf.py"

This reverts commit e8449ae.

* Update conf.py

* Revert "Update conf.py"

This reverts commit 3be44d0.

* Docs Not -W
  • Loading branch information
haiiliin authored Aug 19, 2023
1 parent ccc6773 commit d7be4b4
Show file tree
Hide file tree
Showing 759 changed files with 6,206 additions and 5,538 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
run: |
sphinx-build -M ${{ matrix.builder }} ${{ env.SPHINXOPTS }} docs/source docs/build/${{ matrix.builder }}/${{ matrix.language }}
env:
SPHINXOPTS: -D language=${{ matrix.language }} -j auto -W
SPHINXOPTS: -D language=${{ matrix.language }} -j auto
- name: Upload artifacts
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@v3
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ repos:
hooks:
- id: isort
args: ["--profile", "black"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.5.1"
hooks:
- id: mypy
files: ^src/
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?= -j auto -W
SPHINXOPTS ?= -j auto
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dev = [
"crowdin-api-client",
"docformatter",
"flake8",
"mypy",
"pofmt",
"polib",
"pre-commit",
Expand Down Expand Up @@ -109,3 +110,6 @@ wrap-descriptions = 108
blank = false
in-place = true
black = true

[tool.mypy]
ignore_missing_imports = true
2 changes: 2 additions & 0 deletions src/ababltin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import re
import sys
Expand Down
17 changes: 8 additions & 9 deletions src/abaqus/AbaqusCAEDisplayPreferences/caePrefsAccess.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import List, Union
from __future__ import annotations

from typing import Union

from typing_extensions import Literal

Expand Down Expand Up @@ -34,12 +36,11 @@ def getGuiPrefsFileName() -> str:
str
A String with the default file name for the GUI preferences file.
"""
# TODO: Implement this function
...
return ""


@abaqus_function_doc
def getDisplayNamesInGuiPreferences(fileName: str) -> List[str]:
def getDisplayNamesInGuiPreferences(fileName: str) -> list[str]:
"""The abaqus_2021.gpr file stores a separate guiPreferences record for each display that you use. This
function returns a list of every displayName recorded in the preferences file.
Expand All @@ -55,11 +56,10 @@ def getDisplayNamesInGuiPreferences(fileName: str) -> List[str]:
Returns
-------
List[str]
list[str]
A list of Strings of displayNames.
"""
# TODO: Implement this function
...
return []


@abaqus_function_doc
Expand Down Expand Up @@ -95,8 +95,7 @@ def printValuesList(
A String displaying the path, name, and value for all of the options in the object that
you select.
"""
# TODO: Implement this function
...
return ""


@abaqus_function_doc
Expand Down
8 changes: 4 additions & 4 deletions src/abaqus/Adaptivity/AdaptiveMeshConstraint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from __future__ import annotations

from typing_extensions import Literal

Expand Down Expand Up @@ -29,23 +29,23 @@ class AdaptiveMeshConstraint:

#: A SymbolicConstant specifying the category of the adaptive mesh constraint. Possible
#: values are MECHANICAL and THERMAL.
category: Optional[SymbolicConstant] = None
category: SymbolicConstant

#: A Region object specifying the region to which the adaptive mesh constraint is applied.
region: Region = Region()

#: None or a DatumCsys object specifying the local coordinate system of the adaptive mesh
#: constraint's degrees of freedom. If **localCsys** = None, the degrees of freedom are defined
#: in the global coordinate system. The default value is None.
localCsys: Optional[DatumCsys] = None
localCsys: DatumCsys | None = DatumCsys()

@abaqus_method_doc
def __init__(
self,
name: str,
category: Literal[C.THERMAL, C.MECHANICAL],
region: Region,
localCsys: Optional[DatumCsys] = None,
localCsys: DatumCsys | None = None,
):
"""The AdaptiveMeshConstraint object is the abstract base type for other Arbitrary Lagrangian Eularian
(ALE) style AdaptiveMeshConstraint objects. The AdaptiveMeshConstraint object has no explicit
Expand Down
39 changes: 19 additions & 20 deletions src/abaqus/Adaptivity/AdaptiveMeshConstraintState.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from __future__ import annotations

from typing_extensions import Literal

Expand All @@ -24,7 +24,7 @@ class AdaptiveMeshConstraintState:

#: A SymbolicConstant specifying the propagation state of the amplitude reference. Possible
#: values are UNSET, SET, UNCHANGED, FREED, and MODIFIED.
amplitudeState: Optional[SymbolicConstant] = None
amplitudeState: SymbolicConstant

#: A SymbolicConstant specifying the propagation state of the AdaptiveMeshConstraintState
#: object. Possible values are:
Expand All @@ -41,7 +41,7 @@ class AdaptiveMeshConstraintState:
#: - MODIFIED_FROM_BASE_STATE
#: - DEACTIVATED_FROM_BASE_STATE
#: - BUILT_INTO_MODES
status: Optional[SymbolicConstant] = None
status: SymbolicConstant

#: A String specifying the name of the amplitude reference. The String is empty if the
#: adaptive mesh constraint has no amplitude reference.
Expand All @@ -50,23 +50,22 @@ class AdaptiveMeshConstraintState:
@abaqus_method_doc
def __init__(
self,
amplitudeState: Optional[Literal[C.UNSET, C.SET, C.FREED, C.UNCHANGED, C.MODIFIED]] = None,
status: Optional[
Literal[
C.NOT_YET_ACTIVE,
C.PROPAGATED_FROM_BASE_STATE,
C.DEACTIVATED_FROM_BASE_STATE,
C.DEACTIVATED,
C.MODIFIED_FROM_BASE_STATE,
C.PROPAGATED,
C.NO_LONGER_ACTIVE,
C.CREATED,
C.INSTANCE_NOT_APPLICABLE,
C.BUILT_INTO_MODES,
C.TYPE_NOT_APPLICABLE,
C.MODIFIED,
]
] = None,
amplitudeState: Literal[C.UNSET, C.SET, C.FREED, C.UNCHANGED, C.MODIFIED] | None = None,
status: Literal[
C.NOT_YET_ACTIVE,
C.PROPAGATED_FROM_BASE_STATE,
C.DEACTIVATED_FROM_BASE_STATE,
C.DEACTIVATED,
C.MODIFIED_FROM_BASE_STATE,
C.PROPAGATED,
C.NO_LONGER_ACTIVE,
C.CREATED,
C.INSTANCE_NOT_APPLICABLE,
C.BUILT_INTO_MODES,
C.TYPE_NOT_APPLICABLE,
C.MODIFIED,
]
| None = None,
amplitude: str = "",
):
"""The AdaptiveMeshConstraintState object is the abstract base type for other Arbitrary Lagrangian
Expand Down
18 changes: 8 additions & 10 deletions src/abaqus/Adaptivity/AdaptivityIteration.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import annotations

from typing import Dict

from abqpy.decorators import abaqus_class_doc, abaqus_method_doc

from .ErrorIndicatorResult import ErrorIndicatorResult
from .RuleResult import RuleResult
from .ErrorIndicatorResult import ErrorIndicatorResult as ErrorIndicatorResultType
from .RuleResult import RuleResult as RuleResultType


@abaqus_class_doc
Expand All @@ -23,7 +21,7 @@ class AdaptivityIteration:
#: A repository of RuleResult objects specifying the calculated results from sizing
#: functions corresponding to the RemeshingRule objects for this iteration of an adaptivity
#: process.
ruleResults: Dict[str, RuleResult] = {}
ruleResults: dict[str, RuleResultType] = {}

#: An Int specifying the sequence number for this iteration in the adaptivity process.
iteration: int
Expand Down Expand Up @@ -81,7 +79,7 @@ def __init__(
...

@abaqus_method_doc
def ErrorIndicatorResult(self, name: str, results: str) -> ErrorIndicatorResult:
def ErrorIndicatorResult(self, name: str, results: str) -> ErrorIndicatorResultType:
"""This method creates an ErrorIndicatorResult with data for an error indicator variable in a
RemeshingRule for a given adaptivity iteration.
Expand All @@ -108,18 +106,18 @@ def ErrorIndicatorResult(self, name: str, results: str) -> ErrorIndicatorResult:
------
AbaqusException
"""
self.ruleResults[name] = ruleResult = ErrorIndicatorResult(name, results)
self.ruleResults[name] = ruleResult = ErrorIndicatorResultType(name, results)
return ruleResult

@abaqus_method_doc
def RuleResult(
self,
name: str,
indicatorResults: Dict[str, ErrorIndicatorResult],
indicatorResults: dict[str, ErrorIndicatorResultType],
numElems: int,
minSizeElemCount: int,
satisfiedVars: tuple = (),
) -> RuleResult:
) -> RuleResultType:
"""This method creates a RuleResult with data for a RemeshingRule for a given adaptivity iteration.
.. note::
Expand Down Expand Up @@ -153,7 +151,7 @@ def RuleResult(
------
AbaqusException
"""
self.ruleResults[name] = ruleResult = RuleResult(
self.ruleResults[name] = ruleResult = RuleResultType(
name, indicatorResults, numElems, minSizeElemCount, satisfiedVars
)
return ruleResult
12 changes: 7 additions & 5 deletions src/abaqus/Adaptivity/AdaptivityModel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import Optional, Union
from __future__ import annotations

from typing import Union

from typing_extensions import Literal

Expand Down Expand Up @@ -65,7 +67,7 @@ def AdaptiveMeshConstraint(
name: str,
category: Literal[C.THERMAL, C.MECHANICAL],
region: Region,
localCsys: Optional[DatumCsys] = None,
localCsys: DatumCsys | None = None,
) -> AdaptiveMeshConstraint:
"""The AdaptiveMeshConstraint object is the abstract base type for other Arbitrary Lagrangian Eularian
(ALE) style AdaptiveMeshConstraint objects. The AdaptiveMeshConstraint object has no explicit
Expand Down Expand Up @@ -214,7 +216,7 @@ def DisplacementAdaptiveMeshConstraint(
ur3: Union[Literal[C.SET, C.UNSET], float] = UNSET,
amplitude: str = UNSET,
motionType: Literal[C.USER_DEFINED, C.INDEPENDENT, C.FOLLOW] = INDEPENDENT,
localCsys: Optional[DatumCsys] = None,
localCsys: DatumCsys | None = None,
) -> DisplacementAdaptiveMeshConstraint:
"""This method creates a DisplacementAdaptiveMeshConstraint object.
Expand Down Expand Up @@ -310,7 +312,7 @@ def RemeshingRule(
specifyMaxSize: Boolean = ON,
coarseningFactor: Literal[C.NOT_ALLOWED, C.DEFAULT_LIMIT] = DEFAULT_LIMIT,
refinementFactor: Literal[C.NOT_ALLOWED, C.DEFAULT_LIMIT] = DEFAULT_LIMIT,
elementCountLimit: Optional[int] = None,
elementCountLimit: int | None = None,
) -> RemeshingRule:
"""This method creates a RemeshingRule object.
Expand Down Expand Up @@ -427,7 +429,7 @@ def VelocityAdaptiveMeshConstraint(
vr2: Union[Literal[C.SET, C.UNSET], float] = UNSET,
vr3: Union[Literal[C.SET, C.UNSET], float] = UNSET,
amplitude: str = UNSET,
localCsys: Optional[DatumCsys] = None,
localCsys: DatumCsys | None = None,
motionType: Literal[C.USER_DEFINED, C.INDEPENDENT, C.FOLLOW] = INDEPENDENT,
) -> VelocityAdaptiveMeshConstraint:
"""This method creates a VelocityAdaptiveMeshConstraint object.
Expand Down
10 changes: 5 additions & 5 deletions src/abaqus/Adaptivity/AdaptivityProcess.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Optional
from __future__ import annotations

from abqpy.decorators import abaqus_class_doc, abaqus_method_doc

Expand All @@ -21,11 +21,11 @@ class AdaptivityProcess:

#: A SymbolicConstant specifying the status of the adaptivity process. Possible values are
#: SUBMITTED, RUNNING, ABORTED, TERMINATED, and COMPLETED.
status: Optional[SymbolicConstant] = None
status: SymbolicConstant

#: A repository of AdaptivityIteration objects specifying the AdaptivityIteration objects
#: received during running the adaptivity process.
iterations: Dict[int, AdaptivityIteration] = {}
iterations: dict[int, AdaptivityIteration] = {}

#: A String specifying the name of the Adaptivity Process.
name: str
Expand Down Expand Up @@ -156,7 +156,7 @@ def AdaptivityIteration(
AdaptivityIteration
An AdaptivityIteration object.
"""
self.iterations[iteration] = iteration = AdaptivityIteration(
self.iterations[iteration] = adaptivityIteration = AdaptivityIteration(
iteration, jobName, modelName, odbPath, remeshingErrors
)
return iteration
return adaptivityIteration
Loading

0 comments on commit d7be4b4

Please sign in to comment.