Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation to exec_ does not match implementation #16

Closed
benjaminp opened this issue Jan 8, 2013 · 7 comments
Closed

Documentation to exec_ does not match implementation #16

benjaminp opened this issue Jan 8, 2013 · 7 comments

Comments

@benjaminp
Copy link
Owner

Originally reported by: Bernhard Gschaider (Bitbucket: bgschaid, GitHub: bgschaid)


In the documentation it says

#!python

six.exec_(code, globals=None, locals=None)

but the implementation is

#!python

def exec_(code, globs=None, locs=None):
        """Execute code in a namespace."""

for the Python 2.x-branch


@benjaminp
Copy link
Owner Author

I assume the difference you're referring to is the argument names?

@benjaminp
Copy link
Owner Author

Original comment by Bernhard Gschaider (Bitbucket: bgschaid, GitHub: bgschaid):


Yes. I ported a piece of code that used them as named parameters and it blew up

@benjaminp
Copy link
Owner Author

You shouldn't rely on it, though because

#!pycon
Python 3.4.0a0 (default:ce99559efa46+, Jan  8 2013, 11:43:31) 
[GCC 4.5.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
x>>> exec("x", globals={})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: exec() takes no keyword arguments

@benjaminp
Copy link
Owner Author

Original comment by Bernhard Gschaider (Bitbucket: bgschaid, GitHub: bgschaid):


Right. So exec_ behaves differently on Python2 and Python3 and the point of six is to hide these differences. So what I'd propose is either

  1. Write for Python3 a function that wraps exec and accepts keywords

  2. Rewrite the Python2 implementation to something like (just a sketch)

#!python

def exec_(code,*args):
     globs,locs=None,None
     if len(args)>0:
        globs=args[0]
     if len(args)>1:
        locs=args[1]
     if len(args)>2:
        raise TypeError("exec expected at most 3 arguments, got 4")
    # After that the current implementation

@benjaminp
Copy link
Owner Author

rename python 2's exec_ arguments to avoid accidently calling with keywords (fixes #16)

@benjaminp
Copy link
Owner Author

I hope that's good enough for you.

@benjaminp
Copy link
Owner Author

Original comment by Bernhard Gschaider (Bitbucket: bgschaid, GitHub: bgschaid):


That's fine with me. The thing was I saw the docu when porting and thought "Ah. Keyword arguments. That is self-documenting. Lets use it". And I didn't test that particular path on python3 so I didn't see the error of my ways

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant