|
4 | 4 | import warnings |
5 | 5 | from abc import ABC, ABCMeta, abstractmethod |
6 | 6 | from enum import Enum |
| 7 | +from functools import wraps |
7 | 8 |
|
8 | 9 | from nme import REGISTER, class_to_str |
9 | 10 | from pydantic import BaseModel as PydanticBaseModel |
@@ -416,7 +417,29 @@ def get_default(cls): |
416 | 417 | return cls(name=name, values=cls[name].get_default_values()) |
417 | 418 |
|
418 | 419 |
|
419 | | -class ROIExtractionProfile(BaseModel): |
| 420 | +class ROIExtractionProfileMeta(ModelMetaclass): |
| 421 | + def __new__(cls, name, bases, attrs, **kwargs): |
| 422 | + cls2 = super().__new__(cls, name, bases, attrs, **kwargs) |
| 423 | + |
| 424 | + def allow_positional_args(func): |
| 425 | + @wraps(func) |
| 426 | + def _wraps(self, *args, **kwargs): |
| 427 | + if len(args) > 0: |
| 428 | + warnings.warn( |
| 429 | + "Positional arguments are deprecated, use keyword arguments instead", |
| 430 | + FutureWarning, |
| 431 | + stacklevel=2, |
| 432 | + ) |
| 433 | + kwargs.update(dict(zip(self.__fields__, args))) |
| 434 | + return func(self, **kwargs) |
| 435 | + |
| 436 | + return _wraps |
| 437 | + |
| 438 | + cls2.__init__ = allow_positional_args(cls2.__init__) |
| 439 | + return cls2 |
| 440 | + |
| 441 | + |
| 442 | +class ROIExtractionProfile(BaseModel, metaclass=ROIExtractionProfileMeta): # pylint: disable=E1139 |
420 | 443 | """ |
421 | 444 | :ivar str ~.name: name for segmentation profile |
422 | 445 | :ivar str ~.algorithm: Name of algorithm |
|
0 commit comments