summaryrefslogtreecommitdiff
path: root/modules/language/python/module/python.scm
diff options
context:
space:
mode:
authorStefan Israelsson Tampe <stefan.itampe@gmail.com>2017-10-19 00:11:39 +0200
committerStefan Israelsson Tampe <stefan.itampe@gmail.com>2017-10-19 00:11:39 +0200
commitb412d749dc52ac0e20469188ab430215d3c71dc6 (patch)
treed7e04990aa8b8fb6bf578b2fb9d4ef8997201ae5 /modules/language/python/module/python.scm
parentdc858effda1385c56577380a8a3e76444bc6daf9 (diff)
class system refactoring to enable metaclasses
Diffstat (limited to 'modules/language/python/module/python.scm')
-rw-r--r--modules/language/python/module/python.scm23
1 files changed, 15 insertions, 8 deletions
diff --git a/modules/language/python/module/python.scm b/modules/language/python/module/python.scm
index 296a304..2c08f55 100644
--- a/modules/language/python/module/python.scm
+++ b/modules/language/python/module/python.scm
@@ -42,7 +42,7 @@
set all any bin callable reversed
chr classmethod staticmethod
divmod enumerate filter format
- getattr hasattr hex isinstance
+ getattr hasattr hex isinstance issubclass
iter map sum id input oct ord pow super
sorted zip))
@@ -108,13 +108,20 @@
(define (hasattr a b)
(let ((r (refq a (symbol->string b) miss)))
(not (eq? r miss))))
-
-(define (isinstance o cl)
- (if (pair? cl)
- (or
- (isinstance o (car cl))
- (isinstance o (cdr cl)))
- (is-a? o cl)))
+
+(define-method (issubclass (sub <p>) (cls <p>))
+ (aif it (ref cl '__subclasscheck__)
+ (it sub)
+ (is-a? (ref sub '__goops__) (ref cls '__goops__))))
+
+(define-method (isinstance (o <p>) (cl <p>))
+ (aif it (ref cl '__instancecheck__)
+ (it o)
+ (if (pair? cl)
+ (or
+ (isinstance o (car cl))
+ (isinstance o (cdr cl)))
+ (is-a? (ref (ref o '__class__) '__goops__) cl)))
(define iter
(case-lambda