Changeset 60f03de in sasmodels


Ignore:
Timestamp:
Apr 13, 2016 12:49:03 PM (9 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
a5b8477
Parents:
04dc697
Message:

still more type hinting

Location:
sasmodels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/modelinfo.py

    r04dc697 r60f03de  
    7171def parse_parameter(name, units='', default=np.NaN, 
    7272                    user_limits=None, ptype='', description=''): 
    73     # type: (str, str, float, Limits, str, str) -> Parameter 
     73    # type: (str, str, float, Sequence[Any], str, str) -> Parameter 
    7474    """ 
    7575    Parse an individual parameter from the parameter definition block. 
  • sasmodels/sasview_model.py

    r04dc697 r60f03de  
    3131 
    3232try: 
    33     from typing import Dict, Mapping, Any, Sequence, Tuple, NamedTuple, List, Optional, Union 
     33    from typing import Dict, Mapping, Any, Sequence, Tuple, NamedTuple, List, Optional, Union, Callable 
    3434    from .modelinfo import ModelInfo, Parameter 
    3535    from .kernel import KernelModel 
     
    3838        [("number", int), ("control", str), ("choices", List[str]), 
    3939         ("x_axis_label", str)]) 
     40    SasviewModelType = Callable[[int], "SasviewModel"] 
    4041except ImportError: 
    4142    pass 
     
    5051# TODO: figure out how to say that the return type is a subclass 
    5152def load_standard_models(): 
    52     # type: () -> List[type] 
     53    # type: () -> List[SasviewModelType] 
    5354    """ 
    5455    Load and return the list of predefined models. 
     
    6768 
    6869def load_custom_model(path): 
    69     # type: (str) -> type 
     70    # type: (str) -> SasviewModelType 
    7071    """ 
    7172    Load a custom model given the model path. 
     
    7778 
    7879def _make_standard_model(name): 
    79     # type: (str) -> type 
     80    # type: (str) -> SasviewModelType 
    8081    """ 
    8182    Load the sasview model defined by *name*. 
     
    9192 
    9293def _make_model_from_info(model_info): 
    93     # type: (ModelInfo) -> type 
     94    # type: (ModelInfo) -> SasviewModelType 
    9495    """ 
    9596    Convert *model_info* into a SasView model wrapper. 
     
    99100    attrs = _generate_model_attributes(model_info) 
    100101    attrs['__init__'] = __init__ 
    101     ConstructedModel = type(model_info.name, (SasviewModel,), attrs) 
     102    ConstructedModel = type(model_info.name, (SasviewModel,), attrs) # type: SasviewModelType 
    102103    return ConstructedModel 
    103104 
     
    220221    dispersion = None  # type: Dict[str, Any] 
    221222    #: units and limits for each parameter 
    222     details = None     # type: Mapping[str, Tuple[str, float, float]] 
     223    details = None     # type: Dict[str, Sequence[Any]] 
     224    #                  # actual type is Dict[str, List[str, float, float]] 
    223225    #: multiplicity value, or None if no multiplicity on the model 
    224226    multiplicity = None     # type: Optional[int] 
     
    311313                beta is a list of the corresponding SLD values 
    312314        """ 
    313         args = [] 
     315        args = [] # type: List[Union[float, np.ndarray]] 
    314316        for p in self._model_info.parameters.kernel_parameters: 
    315317            if p.id == self.multiplicity_info.control: 
    316                 args.append(self.multiplicity) 
     318                args.append(float(self.multiplicity)) 
    317319            elif p.length == 1: 
    318320                args.append(self.params.get(p.id, np.NaN)) 
     
    415417            # pylint: disable=unpacking-non-sequence 
    416418            q, phi = x 
    417             return self.calculate_Iq([q * math.cos(phi)], 
    418                                      [q * math.sin(phi)])[0] 
    419         else: 
    420             return self.calculate_Iq([float(x)])[0] 
     419            return self.calculate_Iq([q*math.cos(phi)], [q*math.sin(phi)])[0] 
     420        else: 
     421            return self.calculate_Iq([x])[0] 
    421422 
    422423 
     
    433434        """ 
    434435        if isinstance(x, (list, tuple)): 
    435             return self.calculate_Iq([float(x[0])], [float(x[1])])[0] 
    436         else: 
    437             return self.calculate_Iq([float(x)])[0] 
     436            return self.calculate_Iq([x[0]], [x[1]])[0] 
     437        else: 
     438            return self.calculate_Iq([x])[0] 
    438439 
    439440    def evalDistribution(self, qdist): 
Note: See TracChangeset for help on using the changeset viewer.