fix importing of local variables

parent 059e563d
......@@ -1385,7 +1385,30 @@ empty list."
;; Make sure to load the module in
(let* ((xl (map (lambda (nm) (exp vs nm)) nm))
(ll `(language python module ,@xl)))
(define (get-imp x)
(define (f a) `(@@ ,ll ,(exp vs a)))
(match x
((a . #f)
(f a))
((a . b)
(f a))))
(define (get-name x)
(define (f a) (exp vs a))
(match x
((a . #f)
(f a))
((a . b)
(f b))))
`(define-values ,(map get-name l)
(catch #t
(,(G 'lambda) ()
(,(G 'values)
,@(map get-imp l)))
(,(G 'lambda) x123
(raise ImportError (,(G 'quote) ,ll)))))
#;
`(,(C 'use) #t ()
(,ll
#:select
......@@ -1414,7 +1437,32 @@ empty list."
(u (reverse (list-cdr-ref (reverse (u-it u)) (length nn))))
(xl (append u (map (lambda (nm) (exp vs nm)) nm)))
(ll `(language python module ,@xl)))
(define (get-imp x)
(define (f a) `(@@ ,ll ,(exp vs a)))
(match x
((a . #f)
(f a))
((a . b)
(f a))))
(define (get-name x)
(define (f a) (exp vs a))
(match x
((a . #f)
(f a))
((a . b)
(f b))))
`(define-values ,(map get-name l)
(catch #t
(,(G 'lambda) ()
(,(G 'values)
,@(map get-imp l)))
(,(G 'lambda) x123
(raise ImportError (,(G 'quote) ,ll)))))
#;
`(,(C 'use) #t ()
(,ll
#:select
......@@ -1871,7 +1919,7 @@ empty list."
,(docer
`(,(C 'def-decor) ,decor
(,(C 'def-wrap) ,y? ,f ,ab
(,(C 'not-inline)
(,(O 'object-method)
(,(C 'NR) (,(G 'quote) ,f) ,N ,M
(,(D 'lam) ,aa
(,(C 'with-return) ,r
......@@ -1882,7 +1930,7 @@ empty list."
`(set! ,f
,(docer
`(,(C 'def-decor) ,decor
(,(C 'not-inline)
(,(O 'object-method)
(,(C 'NR) (,(G 'quote) ,f) ,N ,M
(,(D 'lam) ,aa
(,(C 'with-return) ,r
......@@ -1895,7 +1943,7 @@ empty list."
,(docer
`(,(C 'def-decor) ,decor
(,(C 'def-wrap) ,y? (,(G 'quote) ,f) ,ab
(,(C 'not-inline)
(,(O 'object-method)
(,(C 'NR) (,(G 'quote) ,f) ,N ,M
(,(D 'lam) ,aa
(,(C 'with-return) ,r
......@@ -1905,7 +1953,7 @@ empty list."
`(set! ,f
,(docer
`(,(C 'def-decor) ,decor
(,(C 'not-inline)
(,(O 'object-method)
(,(C 'NR) (,(G 'quote) ,f) ,N ,M
(,(D 'lam) ,aa
(,(C 'with-return) ,r
......@@ -2302,7 +2350,7 @@ empty list."
#:use-module ((guile) #:select
(@ @@ pk let* lambda call-with-values case-lambda
set! = * + - < <= > >= / pair? fluid-set!
fluid-ref ,@elsel
fluid-ref ,@elsel define-values
syntax-rules let-syntax abort-to-prompt))
#:use-module (language python module python)
#:use-module ((language python compile) #:select (pks))
......
......@@ -76,6 +76,7 @@ class _EnumDict(dict):
Single underscore (sunder) names are reserved.
"""
if _is_sunder(key):
if key not in (
'_order_', '_create_pseudo_member_',
......
......@@ -28,7 +28,6 @@ __author__ = ('Ka-Ping Yee <[email protected]>',
import abc
import collections.abc
import enum
import importlib.machinery
import itertools
import linecache
import os
......@@ -260,7 +259,7 @@ def isbuiltin(object):
__doc__ documentation string
__name__ original name of this function or method
__self__ instance to which a method is bound, or None"""
return isinstance(object, types.BuiltinFunctionType)
return False
def isroutine(object):
"""Return true if the object is any kind of function or method."""
......@@ -642,7 +641,7 @@ def getmodulename(path):
fname = os.path.basename(path)
# Check for paths that look like an actual module file
suffixes = [(-len(suffix), suffix)
for suffix in importlib.machinery.all_suffixes()]
for suffix in ['py']]
suffixes.sort() # try longest suffixes first, in case they overlap
for neglen, suffix in suffixes:
if fname.endswith(suffix):
......@@ -653,23 +652,7 @@ def getsourcefile(object):
"""Return the filename that can be used to locate an object's source.
Return None if no way can be identified to get the source.
"""
filename = getfile(object)
all_bytecode_suffixes = importlib.machinery.DEBUG_BYTECODE_SUFFIXES[:]
all_bytecode_suffixes += importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES[:]
if any(filename.endswith(s) for s in all_bytecode_suffixes):
filename = (os.path.splitext(filename)[0] +
importlib.machinery.SOURCE_SUFFIXES[0])
elif any(filename.endswith(s) for s in
importlib.machinery.EXTENSION_SUFFIXES):
return None
if os.path.exists(filename):
return filename
# only return a non-existent filename if the module has a PEP 302 loader
if getattr(getmodule(object, filename), '__loader__', None) is not None:
return filename
# or it is in the linecache
if filename in linecache.cache:
return filename
raise Exception('getsourcefile is not implemented')
def getabsfile(object, _filename=None):
"""Return an absolute path to the source or compiled file for an object.
......@@ -3019,7 +3002,6 @@ def signature(obj, *, follow_wrapped=True):
def _main():
""" Logic for inspecting an object given at command line """
import argparse
import importlib
parser = argparse.ArgumentParser()
parser.add_argument(
......@@ -3035,7 +3017,7 @@ def _main():
target = args.object
mod_name, has_attrs, attrs = target.partition(":")
try:
obj = module = importlib.import_module(mod_name)
obj = module = __import__(mod_name)
except Exception as exc:
msg = "Failed to import {} ({}: {})".format(mod_name,
type(exc).__name__,
......@@ -4637,7 +4619,6 @@ def signature(obj, *, follow_wrapped=True):
def _main():
""" Logic for inspecting an object given at command line """
import argparse
import importlib
parser = argparse.ArgumentParser()
parser.add_argument(
......@@ -4653,7 +4634,7 @@ def _main():
target = args.object
mod_name, has_attrs, attrs = target.partition(":")
try:
obj = module = importlib.import_module(mod_name)
obj = module = __module__(mod_name)
except Exception as exc:
msg = "Failed to import {} ({}: {})".format(mod_name,
type(exc).__name__,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment