Commits
56 56 | # returned for all subsequent 'gets'. |
57 57 | return int(user_input) |
58 58 | |
59 59 | """ |
60 60 | import collections |
61 61 | import copy |
62 62 | import inspect |
63 63 | import numbers |
64 64 | import os |
65 65 | import pprint |
66 + | from inspect import signature |
66 67 | |
67 68 | from pipeline.domain import DataType |
68 69 | |
69 70 | from . import api |
70 71 | from . import argmapper |
71 72 | from . import launcher |
72 73 | from . import logging |
73 74 | from . import task_registry |
74 75 | from . import utils |
75 76 | |
370 371 | self._initargs = kwargs.copy() |
371 372 | |
372 373 | # For ModeInputs, the scope attribute is defined by one of the classes |
373 374 | # that the ModeInputs switches between, rather than the ModeInputs |
374 375 | # constructor itself. |
375 376 | if issubclass(task_cls.Inputs, ModeInputs): |
376 377 | if 'mode' not in kwargs: |
377 378 | # user intends for the class to use the default mode. Inspect |
378 379 | # the constructor to find what that value is. |
379 380 | constructor = task_cls.Inputs.__init__ |
380 - | code = constructor.__code__ |
381 - | argcount = code.co_argcount |
382 - | argnames = code.co_varnames[:argcount] |
383 - | fn_defaults = constructor.__defaults__ or list() |
384 - | argdefs = dict(zip(argnames[-len(fn_defaults):], fn_defaults)) |
381 + | argdefs = {name: param.default for name, param in signature( |
382 + | constructor).parameters.items() if param.default is not param.empty} |
385 383 | |
386 384 | # user intends for the class to use the default mode. Inspect |
387 385 | # the constructor to find what that value is |
388 386 | if 'mode' not in argdefs: |
389 387 | raise KeyError('The mode attribute must be specified for ModeInputs constructors') |
390 388 | mode = argdefs['mode'] |
391 389 | |
392 390 | else: |
393 391 | mode = kwargs['mode'] |
394 392 | |