question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Py2 vs. Py3 incompatibility: TypeError

See original GitHub issue

Situation

I’m confused by the statement in the Readme that seems to say 2.10.0 does still support Python 2.7. That’s not what I’m seeing. I have a project that uses this package and runs in Py2, and as soon as it started using the 2.10 release, I started getting errors like this which look to me like what you’d get from a Py2 vs. Py3 incompatibility:

TypeError("Expected str or VersionInfo instance, but got <type 'unicode'>"

When I pin the dependency to <2.10, the error goes away.

_Originally posted by @eli-darkly in https://github.com/python-semver/python-semver/issues/161#issuecomment-654455352_

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
tomschrcommented, Jul 6, 2020

Thanks Eli! Actually I found an example:

$ python2
>>> import semver
>>> semver.compare("1.1.0", u"1.2.2")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "semver.py", line 100, in wrapper
    return func(*args, **kwargs)
  File "semver.py", line 779, in compare
    return v1.compare(ver2)
  File "semver.py", line 427, in compare
    cls.__name__, type(other)
TypeError: Expected str or VersionInfo instance, but got <type 'unicode'>

This is a bug, of course, and shouldn’t happen.

0reactions
tomschrcommented, Jul 23, 2020

Thanks @gsakkis for your ideas. 👍

to be honest I’d either drop python 2 support

That was also my thought at first. However, I think it would make sense to have this fix in semver2 too.

or use six as a dependency instead of copy-pasting parts of it.

I was thinking about six, but I would like to avoid introducing another dependency. Especially if this development line (semver2) will be deprecated soon and we will switch to semver3.

The parts that are coming from six are really very small. All in all it’s ~23 lines of code. It’s probably easy to remove them once we release semver3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The key differences between Python 2.7.x and Python 3.x with ...
Comparing unorderable types #. Another nice change in Python 3 is that a TypeError is raised as warning if we try to compare...
Read more >
Exceptions - The Conservative Python 3 Porting Guide
ExceptionType can be a tuple, as in, for example, except (TypeError, ValueError): .
Read more >
Common migration problems — Supporting Python 3
Under Python 2 the bytes literal and bytes type are just aliases for str so the objects will not behave exactly the same...
Read more >
1 - Stack Overflow
with works fine with Python 3.2 but not with 2.6. Then based on this topic: TypeError: super() takes at least 1 argument (0...
Read more >
Standard library incompatibilities - Python-Future
Python 3:: >>> array.array(b'b') TypeError: must be a unicode character, not bytes ... You can use the following code on both Python 3...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found