ソースを参照

Checking type of model argument (without importing Model)

The check is done on the __class__.__name__ attr of model argument (maybe not a good solution ?)
Yann Weber 9年前
コミット
d2f6509397
1個のファイルの変更4行の追加2行の削除
  1. 4
    2
      EditorialModel/components.py

+ 4
- 2
EditorialModel/components.py ファイルの表示

@@ -28,8 +28,10 @@ class EmComponent(object):
28 28
     def __init__(self, model, uid, name, string = None, help_text = None, date_update = None, date_create = None, rank = None):
29 29
         if type(self) == EmComponent:
30 30
            raise NotImplementedError('Abstract class')
31
- 
32
-        self.model = model # AHAH cannot check type without importing Model ? 
31
+        if model.__class__.__name__ != 'Model':
32
+            raise TypeError("Excepted type for 'model' arg is <class 'Model'> but got {} instead".format(type(model)))
33
+
34
+        self.model = model
33 35
 
34 36
         self.uid = uid
35 37
         self.check_type('uid', int)

読み込み中…
キャンセル
保存