File tree Expand file tree Collapse file tree
autofit/mapper/prior_model
test_autofit/mapper/model Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import builtins
2+ import collections .abc
23import copy
34import inspect
45import logging
6+ import typing
57
68from autoconf .class_path import get_class_path
79from autoconf .exc import ConfigException
@@ -164,7 +166,20 @@ def __init__(
164166 elif hasattr (spec , "__args__" ) and type (None ) in spec .__args__ :
165167 setattr (self , arg , None )
166168 else :
167- setattr (self , arg , Model (annotations [arg ]))
169+ annotation = annotations [arg ]
170+
171+ if (
172+ hasattr (annotation , "__origin__" )
173+ and issubclass (
174+ annotation .__origin__ , collections .abc .Collection
175+ )
176+ ) or isinstance (annotation , collections .abc .Collection ):
177+ from autofit .mapper .prior_model .collection import Collection
178+
179+ value = Collection ()
180+ else :
181+ value = Model (annotation )
182+ setattr (self , arg , value )
168183 else :
169184 prior = self .make_prior (arg )
170185 if (
Original file line number Diff line number Diff line change 1+ from typing import List
2+
13import pytest
24
35import autofit as af
@@ -157,3 +159,13 @@ def test_instance_from_vector(model_with_assertion):
157159
158160def test_random_instance (model_with_assertion ):
159161 model_with_assertion .random_instance (ignore_prior_limits = True )
162+
163+
164+ class TestModel :
165+ def __init__ (self , items : List [float ]):
166+ self .items = items
167+
168+
169+ def test_typing_annotations ():
170+ model = af .Model (TestModel )
171+ assert model .items == af .Collection ()
You can’t perform that action at this time.
0 commit comments