Skip to content

Commit

Permalink
Updated genutils.typetools imports
Browse files Browse the repository at this point in the history
  • Loading branch information
timbernat committed Apr 19, 2024
1 parent b048c45 commit b900df2
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion polymerist/analysis/mdtrajutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from openmm.unit import nanometer, nanosecond, dimensionless

from ..unitutils.dimensions import hasunits
from ..genutils.typetools import T, Args, KWArgs
from ..genutils.typetools.parametric import T, Args, KWArgs
from ..genutils.decorators.signatures import modify_param_annotation_by_index


Expand Down
2 changes: 1 addition & 1 deletion polymerist/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from datetime import timedelta
from openmm.unit import Quantity, microsecond, millisecond, second, minute, hour, day, year # TODO : remove dependence on OpenMM for Unit support

from polymerist.genutils.typetools import _union_member_factory
from .genutils.typetools.categorical import _union_member_factory


# TIME CONVERSION CONSTANTS
Expand Down
2 changes: 1 addition & 1 deletion polymerist/genutils/decorators/classmod.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'''Decorators for modifying classes'''

from typing import Callable, Iterable, Optional, TypeVar
from ..typetools import C
C = TypeVar('C')


def generate_repr(cls : Optional[C]=None, disp_attrs : Optional[Iterable[str]]=None, lookup_attr : Optional[str]=None):
Expand Down
6 changes: 3 additions & 3 deletions polymerist/genutils/decorators/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

from .meta import extend_to_methods
from . import signatures
from ..typetools import O, T, Args, KWArgs
from ..typetools.parametric import T, Args, KWArgs
from ..fileutils.pathutils import aspath, asstrpath


@extend_to_methods
def optional_in_place(funct : Callable[[O, Args, KWArgs], None]) -> Callable[[O, Args, bool, KWArgs], Optional[O]]:
def optional_in_place(funct : Callable[[object, Args, KWArgs], None]) -> Callable[[object, Args, bool, KWArgs], Optional[object]]:
'''Decorator function for allowing in-place (writeable) functions which modify object attributes
to be not performed in-place (i.e. read-only), specified by a boolean flag'''
# TODO : add assertion that the wrapped function has at least one arg AND that the first arg is of the desired (limited) type
old_sig = inspect.signature(funct)

@wraps(funct) # for preserving docstring and type annotations / signatures
def in_place_wrapper(obj : O, *args : Args, in_place : bool=False, **kwargs : KWArgs) -> Optional[O]: # read-only by default
def in_place_wrapper(obj : object, *args : Args, in_place : bool=False, **kwargs : KWArgs) -> Optional[object]: # read-only by default
'''If not in-place, create a clone on which the method is executed''' # NOTE : old_sig.bind screws up arg passing
if in_place:
funct(obj, *args, **kwargs) # default call to writeable method - implicitly returns None
Expand Down
2 changes: 1 addition & 1 deletion polymerist/genutils/decorators/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Concatenate, Callable, ParamSpec, TypeAlias, TypeVar
from functools import update_wrapper

from ..typetools import C, O, P, R, Args, KWArgs
from ..typetools.parametric import C, O, P, R, Args, KWArgs
Decorator : TypeAlias = Callable[[Callable[P, R]], Callable[P, R]]


Expand Down
2 changes: 1 addition & 1 deletion polymerist/genutils/iteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from itertools import islice, combinations, product as cartesian_product
from collections import deque

from .typetools import Args, KWArgs
from .typetools.parametric import Args, KWArgs
from .decorators.functional import optional_in_place


Expand Down
2 changes: 1 addition & 1 deletion polymerist/maths/lattices.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
from itertools import product as cartesian_product

from ..genutils.typetools import Shape, N
from ..genutils.typetools.numpytypes import Shape, N


def generate_int_lattice(*dims : Iterable[int]) -> np.ndarray[Shape[N, 3], int]:
Expand Down
2 changes: 1 addition & 1 deletion polymerist/maths/linearalg/decomposition.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'''Tools for matrix decomposition'''

import numpy as np
from ...genutils.typetools import Shape, DType, N, M
from ...genutils.typetools.numpytypes import Shape, DType, N, M


def diagonalize(matrix : np.ndarray) -> tuple[np.ndarray]:
Expand Down
2 changes: 1 addition & 1 deletion polymerist/openmmtools/reporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from openmm.app import PDBReporter, PDBxReporter, DCDReporter
from openmm.app import StateDataReporter, CheckpointReporter

from ..genutils.typetools import Args, KWArgs
from ..genutils.typetools.parametric import Args, KWArgs
from ..genutils.fileutils.pathutils import assemble_path
from ..genutils.fileutils.jsonio.jsonify import make_jsonifiable
from ..genutils.fileutils.jsonio.serialize import PathSerializer
Expand Down
2 changes: 1 addition & 1 deletion polymerist/rdutils/labeling/bondwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ..rdtypes import RDMol, RDBond
from .molwise import atom_ids_by_map_nums

from ...genutils.typetools import Args, KWArgs
from ...genutils.typetools.parametric import Args, KWArgs
from ...genutils.iteration import sliding_window
from ...genutils.decorators.functional import optional_in_place

Expand Down
2 changes: 1 addition & 1 deletion polymerist/rdutils/rdtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any, TypeAlias, Union
from rdkit import Chem

from ..genutils.typetools import _union_member_factory
from ..genutils.typetools.categorical import _union_member_factory

# DEFINING RDKit TYPES
RDMol = Chem.rdchem.Mol
Expand Down

0 comments on commit b900df2

Please sign in to comment.