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

Python 3 issue that isn't handled by 2to3: type of stderr #221

Closed
jean opened this issue Sep 9, 2017 · 2 comments
Closed

Python 3 issue that isn't handled by 2to3: type of stderr #221

jean opened this issue Sep 9, 2017 · 2 comments
Assignees
Labels
Milestone

Comments

@jean
Copy link
Contributor

jean commented Sep 9, 2017

I got this:

$ ./generate-bash-completion
Traceback (most recent call last):
  File "git-hub", line 2156, in <module>
    main()
  File "git-hub", line 2121, in main
    config = Config()
  File "git-hub", line 316, in __init__
    self.username = git_config('username', getpass.getuser())
  File "git-hub", line 272, in git_config
    return git(*cmd)
  File "git-hub", line 218, in git
    raise GitError(proc.returncode, args, stderr.rstrip('\n'))
TypeError: a bytes-like object is required, not 'str'

At that point, stderr is b''.

To fix it, I could do this:

@@ -215,7 +215,7 @@ def git(*args, **kwargs):
     proc = subprocess.Popen(args, **kwargs)
     (stdout, stderr) = proc.communicate()
     if proc.returncode != 0:
-        raise GitError(proc.returncode, args, stderr.rstrip('\n'))
+        raise GitError(proc.returncode, args, str(stderr).rstrip('\n'))
     return stdout.rstrip('\n')

If my fix is correct, maybe worth adding to the README?

@jean jean changed the title Python 3 issue that isn't handled by 2to3 Python 3 issue that isn't handled by 2to3: type of stderr Sep 10, 2017
@leandro-lucarella-sociomantic
Copy link
Contributor

String handling is a mess unfortunately. This really needs to use a lot of from __future__ import ... to be more python3 compatible. At this point I'm not sure if it's worth adding little hacks, but OTOH if this small fix makes it work for you with 2to3, it can be applied, str(stderr) shouldn't change anything in py2.

@jean
Copy link
Contributor Author

jean commented Sep 12, 2017

This one I "fixed" (avoided) by simply %s/$PYTHON/python2 in the Makefile 😬
I agree that this is better addressed in a proper port.

@jean jean closed this as completed Sep 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants