summaryrefslogtreecommitdiff
path: root/modules/language/python
diff options
context:
space:
mode:
authorStefan Israelsson Tampe <stefan.itampe@gmail.com>2018-05-07 20:23:49 +0200
committerStefan Israelsson Tampe <stefan.itampe@gmail.com>2018-05-07 20:23:49 +0200
commit876d5d0fca204adce5335c5486bf6fb3d2188f22 (patch)
tree64c84b490c28c278b42a65370ccbeb23365b6cbd /modules/language/python
parent1753734c420edd4a5a641ad8e9c7250534dff136 (diff)
enum.py works
Diffstat (limited to 'modules/language/python')
-rw-r--r--modules/language/python/dir.scm77
-rw-r--r--modules/language/python/module/enum.py10
-rw-r--r--modules/language/python/module/types.scm3
-rw-r--r--modules/language/python/property.scm6
4 files changed, 41 insertions, 55 deletions
diff --git a/modules/language/python/dir.scm b/modules/language/python/dir.scm
index fe7edae..b74ca94 100644
--- a/modules/language/python/dir.scm
+++ b/modules/language/python/dir.scm
@@ -15,53 +15,48 @@
(define-method (dir) (pylist))
-(define (chash-for-each f c)
+(define (p x) (if (symbol? x) (symbol->string x) x))
+(define (chash-for-each t c)
(let ((h (slot-ref c 'h)))
(if (is-a? c <pf>)
- (let ((hh (make-hash-table)))
- (vhash-fold
- (lambda (k v s)
- (when (not (hash-ref hh k))
- (hash-set! hh k #t)
- (f k v))
- s) #f h))
- (hash-for-each f h))))
+ (vhash-fold
+ (lambda (k v s)
+ (hash-set! t (p k) #t))
+ #f h)
+ (hash-for-each
+ (lambda (k v)
+ (hash-set! t (p k) #t))
+ h))))
-(define (get-from-class c f)
- (let lp ((pl (ref c '__mro__)))
- (if (pair? pl)
+(define (find-in o h c)
+ (chash-for-each h c)
+ (aif it (and o (find-in-class c '__dir__ #f))
+ (for ((k : (it o))) ()
+ (hash-set! h (p k) #t))
+ #f))
+
+(define (find-in-mro o h l)
+ (let lp ((l l))
+ (if (pair? l)
(begin
- (chash-for-each f (car pl))
- (lp (cdr pl))))))
+ (find-in o h (car l))
+ (lp (cdr l))))))
+
(define-method (dir (o <p>))
- (if (not (pyclass? o))
- (aif it (ref o '__dir__)
- (it)
- (begin
- (let ((l1 (aif it (ref o '__dict__)
- (let ((l (pylist)))
- (for ((k v : it)) ()
- (pylist-append! l k))
- (pylist-sort! l)
- l)
- (pylist))))
- (let* ((h (make-hash-table))
- (c (ref o '__class__))
- (l '())
- (f (lambda (k v) (set! l (cons k l)))))
- (chash-for-each f o)
- (get-from-class c f)
- (hash-for-each (lambda (k v) (pylist-append! l k)) h)
- (+ (pylist (map symbol->string (sort l <))) l1)))))
- (let* ((h (make-hash-table))
- (c o)
- (l '())
- (f (lambda (k v) (hash-set! h k #t))))
- (get-from-class c f)
- (hash-for-each (lambda (k v) (set! l (cons k l))) h)
- (to-pylist (map symbol->string (sort l <))))))
-
+ (let ((h (make-hash-table)))
+ (find-in-mro #f h (find-in-class o '__mro__ (list o)))
+ (aif cl (find-in-class o '__class__ #f)
+ (find-in-mro o h (find-in-class cl '__mro__ (list cl)))
+ #f)
+ (let ((l (py-list)))
+ (hash-for-each
+ (lambda (k v)
+ (pylist-append! l k))
+ h)
+ (pylist-sort! l)
+ l)))
+
(define-method (dir (o <py-list>))
(let ((l1 (pk (pylist-listing))))
(if (is-a? o <p>)
diff --git a/modules/language/python/module/enum.py b/modules/language/python/module/enum.py
index e657af3..34e19b6 100644
--- a/modules/language/python/module/enum.py
+++ b/modules/language/python/module/enum.py
@@ -108,7 +108,6 @@ class _EnumDict(dict):
# This is also why there are checks in EnumMeta like `if Enum is not None`
Enum = None
-pk('EnumMeta')
class EnumMeta(type):
"""Metaclass for Enum"""
@classmethod
@@ -129,7 +128,6 @@ class EnumMeta(type):
# cannot be mixed with other types (int, float, etc.) if it has an
# inherited __new__ unless a new __new__ is defined (or the resulting
# class will fail).
- pk('new',metacls,cls)
member_type, first_enum = metacls._get_mixins_(bases)
new, save_new, use_args = metacls._find_new_(classdict, member_type,
@@ -351,7 +349,7 @@ class EnumMeta(type):
"""
return MappingProxyType(cls._member_map_)
-
+
def __repr__(cls):
return "<enum %r>" % cls.__name__
@@ -522,7 +520,6 @@ class EnumMeta(type):
return __new__, save_new, use_args
-pk('enum')
class Enum(metaclass=EnumMeta):
"""Generic enumeration.
@@ -654,7 +651,6 @@ class Enum(metaclass=EnumMeta):
module_globals[name] = cls
return cls
-pk('intenum')
class IntEnum(int, Enum):
"""Enum where members are also (and must be) ints"""
@@ -663,7 +659,6 @@ class IntEnum(int, Enum):
def _reduce_ex_by_name(self, proto):
return self.name
-pk('flag')
class Flag(Enum):
"""Support for flags"""
@@ -772,7 +767,6 @@ class Flag(Enum):
inverted = reduce(_or_, inverted_members, self.__class__(0))
return self.__class__(inverted)
-pk('intflag')
class IntFlag(int, Flag):
"""Support for integer-based Flags"""
@@ -837,8 +831,6 @@ class IntFlag(int, Flag):
result = self.__class__(~self._value_)
return result
-pk('rest')
-
def _high_bit(value):
"""returns index of highest bit, or -1 if value is zero or negative"""
return value.bit_length() - 1
diff --git a/modules/language/python/module/types.scm b/modules/language/python/module/types.scm
index a148426..4448b6a 100644
--- a/modules/language/python/module/types.scm
+++ b/modules/language/python/module/types.scm
@@ -4,6 +4,7 @@
#:use-module (language python exceptions)
#:use-module (language python def)
#:use-module (language python bool)
+ #:use-module (language python dict)
#:use-module ((language python module python)
#:select (getattr type))
#:export (MappingProxyType DynamicClassAttribute Functiontype LambdaType))
@@ -11,7 +12,7 @@
"""
Define names for built-in types that aren't directly accessible as a builtin.
"""
-(define MappingProxyType <hashtable>)
+(define MappingProxyType dict)
(define FunctionType <procedure>)
(define LambdaType <procedure>)
diff --git a/modules/language/python/property.scm b/modules/language/python/property.scm
index 78f6f32..132de35 100644
--- a/modules/language/python/property.scm
+++ b/modules/language/python/property.scm
@@ -24,10 +24,8 @@
o))
(define __get__
- (lambda (obj class)
- (if (eq? obj class)
- obj
- ((slot-ref obj 'get) obj))))
+ (lambda (self obj class)
+ ((slot-ref self 'get) obj)))
(define setter
(lambda (self f)