Skip to content

Commit 4b57c79

Browse files
committed
Merge branch '286-python-typehints-use-standard-types-instead-of-typing-module' into 'development'
typing.{Tuple,Dict,List} not needed anymore Closes #286 See merge request damask/DAMASK!1010
2 parents 621ade8 + 0e85208 commit 4b57c79

10 files changed

+89
-89
lines changed

python/damask/_configmaterial.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional, Union, Sequence, Dict, Any, List
1+
from typing import Optional, Union, Sequence, Any
22

33
import numpy as np
44
import h5py
@@ -25,10 +25,10 @@ class ConfigMaterial(YAML):
2525
"""
2626

2727
def __init__(self,
28-
config: Optional[Union[str,Dict[str,Any]]] = None,*,
29-
homogenization: Optional[Dict[str,Dict]] = None,
30-
phase: Optional[Dict[str,Dict]] = None,
31-
material: Optional[List[Dict[str,Any]]] = None):
28+
config: Optional[Union[str,dict[str,Any]]] = None,*,
29+
homogenization: Optional[dict[str,dict]] = None,
30+
phase: Optional[dict[str,dict]] = None,
31+
material: Optional[list[dict[str,Any]]] = None):
3232
"""
3333
New material configuration.
3434
@@ -46,7 +46,7 @@ def __init__(self,
4646
Materialpoint configuration.
4747
Defaults to an empty list if 'config' is not given.
4848
"""
49-
kwargs: Dict[str,Union[Dict[str,Dict],List[Dict[str,Any]]]] = {}
49+
kwargs: dict[str,Union[dict[str,dict],list[dict[str,Any]]]] = {}
5050
for arg,value in zip(['homogenization','phase','material'],[homogenization,phase,material]):
5151
if value is None and config is None:
5252
kwargs[arg] = [] if arg == 'material' else {}
@@ -358,7 +358,7 @@ def is_valid(self) -> bool:
358358

359359

360360
def material_rename_phase(self,
361-
mapping: Dict[str, str],
361+
mapping: dict[str, str],
362362
ID: Optional[Sequence[int]] = None,
363363
constituent: Optional[Sequence[int]] = None) -> 'ConfigMaterial':
364364
"""
@@ -391,7 +391,7 @@ def material_rename_phase(self,
391391

392392

393393
def material_rename_homogenization(self,
394-
mapping: Dict[str, str],
394+
mapping: dict[str, str],
395395
ID: Optional[Sequence[int]] = None) -> 'ConfigMaterial':
396396
"""
397397
Change homogenization name in material.

python/damask/_crystal.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional, Union, Dict, List, Tuple, Literal
1+
from typing import Optional, Union, Literal
22

33
import numpy as np
44

@@ -7,7 +7,7 @@
77
from . import Rotation
88

99

10-
_kinematics: Dict[BravaisLattice, Dict[CrystalKinematics, List[np.ndarray]]] = {
10+
_kinematics: dict[BravaisLattice, dict[CrystalKinematics, list[np.ndarray]]] = {
1111
'cF': {
1212
'slip': [np.array([
1313
[ 0,+1,-1, +1,+1,+1],
@@ -244,7 +244,7 @@
244244
}
245245

246246

247-
lattice_symmetries: Dict[Optional[BravaisLattice], CrystalFamily] = {
247+
lattice_symmetries: dict[Optional[BravaisLattice], CrystalFamily] = {
248248
'aP': 'triclinic',
249249

250250
'mP': 'monoclinic',
@@ -265,7 +265,7 @@
265265
'cF': 'cubic',
266266
}
267267

268-
orientation_relationships: Dict[str, Dict[str,List[np.ndarray]]] = {
268+
orientation_relationships: dict[str, dict[str,list[np.ndarray]]] = {
269269
'KS': { # https://doi.org/10.1016/j.jallcom.2012.02.004
270270
'cF-->cI' : [
271271
np.repeat(np.array([
@@ -800,17 +800,17 @@ def __eq__(self,
800800
self.family == other.family)
801801

802802
@property
803-
def parameters(self) -> Optional[Dict]:
803+
def parameters(self) -> Optional[dict]:
804804
"""Return lattice parameters a, b, c, alpha, beta, gamma."""
805805
has_parameters = all([hasattr(self,p) for p in ['a','b','c','alpha','beta','gamma']])
806806
return dict(a=self.a,b=self.b,c=self.c,
807807
alpha=self.alpha,beta=self.beta,gamma=self.gamma) if has_parameters else None
808808

809809
@property
810-
def immutable(self) -> Dict[str, float]:
810+
def immutable(self) -> dict[str, float]:
811811
"""Return immutable lattice parameters."""
812812
# ToDo: use pattern matching in Python 3.10
813-
_immutable: Dict[CrystalFamily, Dict[str,float]] = {
813+
_immutable: dict[CrystalFamily, dict[str,float]] = {
814814
'cubic': {
815815
'b': 1.0,
816816
'c': 1.0,
@@ -845,13 +845,13 @@ def immutable(self) -> Dict[str, float]:
845845

846846

847847
@property
848-
def orientation_relationships(self) -> List[str]:
848+
def orientation_relationships(self) -> list[str]:
849849
"""Return labels of orientation relationships."""
850850
return [k for k,v in orientation_relationships.items() if np.any([m.startswith(str(self.lattice)) for m in v])]
851851

852852

853853
@property
854-
def standard_triangle(self) -> Union[Dict[str, np.ndarray], None]:
854+
def standard_triangle(self) -> Union[dict[str, np.ndarray], None]:
855855
"""
856856
Corners of the standard triangle.
857857
@@ -878,7 +878,7 @@ def standard_triangle(self) -> Union[Dict[str, np.ndarray], None]:
878878
... [0.,1.,0.]]).T), # blue
879879
... }
880880
"""
881-
_basis: Dict[CrystalFamily, Dict[str, np.ndarray]] = {
881+
_basis: dict[CrystalFamily, dict[str, np.ndarray]] = {
882882
'cubic': {'improper':np.array([ [-1. , 0. , 1. ],
883883
[ np.sqrt(2.) , -np.sqrt(2.) , 0. ],
884884
[ 0. , np.sqrt(3.) , 0. ] ]),
@@ -944,7 +944,7 @@ def symmetry_operations(self) -> Rotation:
944944
945945
https://en.wikipedia.org/wiki/Crystal_system#Crystal_classes
946946
"""
947-
_symmetry_operations: Dict[CrystalFamily, List] = {
947+
_symmetry_operations: dict[CrystalFamily, list] = {
948948
'cubic': [
949949
[ 1.0, 0.0, 0.0, 0.0 ],
950950
[ 0.0, 1.0, 0.0, 0.0 ],
@@ -1058,7 +1058,7 @@ def basis_reciprocal(self) -> np.ndarray:
10581058
@property
10591059
def lattice_points(self) -> np.ndarray:
10601060
"""Return lattice points."""
1061-
_lattice_points: Dict[str, List] = {
1061+
_lattice_points: dict[str, list] = {
10621062
'P': [
10631063
],
10641064
'S': [
@@ -1152,7 +1152,7 @@ def to_frame(self, *,
11521152

11531153

11541154
def kinematics(self,
1155-
mode: CrystalKinematics) -> Dict[str, List[np.ndarray]]:
1155+
mode: CrystalKinematics) -> dict[str, list[np.ndarray]]:
11561156
"""
11571157
Return crystal kinematics systems.
11581158
@@ -1189,7 +1189,7 @@ def kinematics(self,
11891189

11901190

11911191
def characteristic_shear_twin(self,
1192-
N_twin: Union[List[int], Literal['*']] = '*') -> np.ndarray:
1192+
N_twin: Union[list[int], Literal['*']] = '*') -> np.ndarray:
11931193
"""
11941194
Return characteristic shear for twinning.
11951195
@@ -1229,7 +1229,7 @@ def characteristic_shear_twin(self,
12291229

12301230
def relation_operations(self,
12311231
model: str,
1232-
target = None) -> Tuple[BravaisLattice, Rotation]:
1232+
target = None) -> tuple[BravaisLattice, Rotation]:
12331233
"""
12341234
Crystallographic orientation relationships for phase transformations.
12351235

python/damask/_geomgrid.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import copy
33
import multiprocessing as mp
44
from functools import partial
5-
from typing import Optional, Union, Sequence, Dict
5+
from typing import Optional, Union, Sequence
66
from pathlib import Path
77

88
import numpy as np
@@ -40,7 +40,7 @@ def __init__(self,
4040
material: np.ndarray,
4141
size: FloatSequence,
4242
origin: FloatSequence = np.zeros(3),
43-
initial_conditions: Optional[Dict[str,np.ndarray]] = None,
43+
initial_conditions: Optional[dict[str,np.ndarray]] = None,
4444
comments: Union[None, str, Sequence[str]] = None):
4545
"""
4646
New geometry definition for grid solvers.
@@ -163,7 +163,7 @@ def origin(self,
163163
self._origin = np.array(origin,np.float64)
164164

165165
@property
166-
def initial_conditions(self) -> Dict[str,np.ndarray]:
166+
def initial_conditions(self) -> dict[str,np.ndarray]:
167167
"""Fields of initial conditions."""
168168
self._ic = dict(zip(self._ic.keys(), # type: ignore[has-type]
169169
[v if isinstance(v,np.ndarray) else
@@ -172,7 +172,7 @@ def initial_conditions(self) -> Dict[str,np.ndarray]:
172172

173173
@initial_conditions.setter
174174
def initial_conditions(self,
175-
ic: Dict[str,np.ndarray]):
175+
ic: dict[str,np.ndarray]):
176176
if not isinstance(ic,dict):
177177
raise TypeError('initial conditions is not a dictionary')
178178

python/damask/_loadcasegrid.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional, Union, Dict, Any, List
1+
from typing import Optional, Union, Any
22

33
from numpy import ma
44

@@ -20,10 +20,10 @@ class LoadcaseGrid(YAML):
2020
"""Load case for grid solver."""
2121

2222
def __init__(self,
23-
config: Optional[Union[str,Dict[str,Any]]] = None,
23+
config: Optional[Union[str,dict[str,Any]]] = None,
2424
*,
25-
solver: Optional[Dict[str,str]] = None,
26-
loadstep: Optional[List[Dict[str,Any]]] = None):
25+
solver: Optional[dict[str,str]] = None,
26+
loadstep: Optional[list[dict[str,Any]]] = None):
2727
"""
2828
New grid solver load case.
2929
@@ -38,8 +38,8 @@ def __init__(self,
3838
Load step configuration.
3939
Defaults to an empty list if 'config' is not given.
4040
"""
41-
kwargs: Dict[str,Union[Dict[str,str],List[Dict[str,Any]]]] = {}
42-
default: Union[List,Dict]
41+
kwargs: dict[str,Union[dict[str,str],list[dict[str,Any]]]] = {}
42+
default: Union[list,dict]
4343
for arg,value,default in [('solver',solver,{}),('loadstep',loadstep,[])]: # type: ignore[assignment]
4444
if value is not None:
4545
kwargs[arg] = value

0 commit comments

Comments
 (0)