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

Adding Python 3 support and fixed Python 2.6 bug. #4

Merged
merged 3 commits into from
Jan 27, 2016
Merged

Adding Python 3 support and fixed Python 2.6 bug. #4

merged 3 commits into from
Jan 27, 2016

Conversation

bworrell
Copy link

@bworrell bworrell commented Dec 1, 2015

Hello,

I ran across some issues when using weakrefmethod on different versions of Python and took a shot at fixing them.

When running unit2 on Python 2.6, I got the following error:

======================================================================
FAIL: test_equality (test_weakmethod.WeakMethodTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\dev\weakrefmethod\test_weakmethod.py", line 122, in test_equality
    _eq(a, b)
  File "C:\dev\weakrefmethod\test_weakmethod.py", line 111, in _eq
    self.assertFalse(a != b)
AssertionError: True is not false

----------------------------------------------------------------------

I think this is due to a weakref.ref behavior on Python 2.6. It seems the __ne__ method returns a NotImplementedType object, which evaluates to True when used in a boolean expression.

Example:

>>> import weakref
>>> def foo():
...     pass
...
>>>
>>> r1 = weakref.ref(foo)
>>> r2 = weakref.ref(foo)
>>>
>>> r1 == r2
True
>>>
>>> r1 != r2
False
>>>
>>> r1.__ne__(r2)
NotImplemented
>>>
>>> result = r1.__ne__(r2)
>>> bool(result)
True

On Python 3, the weakrefmethod/__init__.py imports fail because of the relative import syntax. I updated it to use explicit relative imports which works on Python 2.6+. After altering the imports and running the tests, weakrefmethod appears to work on Python 3.2 and 3.3.

I also added the tox.ini file that I used for testing across different Python versions.

Thanks for considering this pull request and thank you for providing weakrefmethod to the Python community!

@sjlongland
Copy link
Contributor

Just noticed this package fails on Python 3.3: https://travis-ci.org/mriehl/fysom/jobs/104516422
I'll have to check and see if this pull request fixes it.

@bworrell
Copy link
Author

@sjlongland, the PR should fix the issue you are seeing in Travis. The problem is that weakrefmethod uses implicit relative imports, which are not supported in in Python 3.

twang817 added a commit that referenced this pull request Jan 27, 2016
Adding Python 3 support and fixed Python 2.6 bug.
@twang817 twang817 merged commit d99db0f into twang817:master Jan 27, 2016
@twang817
Copy link
Owner

I'll update pypi a bit later tonight.

@sjlongland
Copy link
Contributor

Excellent news, I'll be giving it a try shortly to see how it all goes. Many thanks. :-)

@bworrell
Copy link
Author

Awesome! Thanks @twang817! Hope it works for you @sjlongland :)

@sjlongland
Copy link
Contributor

For the record, I was waiting for the new package to arrive on pypi. In the meantime I decided to add a .travis.yml file (since I don't have Python 3.2/3.3 handy) and give it a shot there.

https://travis-ci.org/vrtsystems/weakrefmethod/jobs/105810978 ← Seems Python 3.2 isn't happy.

@sjlongland
Copy link
Contributor

Okay, seems the .travis.yml file I grabbed (I nicked it from another repository) tries to use latest versions of modules like pip, and the latest pip does not like Python 3.2.

Still, it's worth knowing about 3.2 support because Debian Wheezy ships with it, and we have a lot of kit out in the field with Debian Wheezy.

https://travis-ci.org/vrtsystems/weakrefmethod shows all passing.

Once in pypi, I should be able to trigger a re-test of fysom and get mriehl/fysom#29 squared away.

@sjlongland
Copy link
Contributor

Hi,

Silly question, what's the status of this package these days on pypi? Seems at this present time, any package tested on Python 3.0-3.3 inclusive fails still due to this issue when the package depends on this module.

I haven't been able to get mriehl/fysom#23 resolved as it presently still breaks on Python 3.3 due to incompatibilities in weakrefmethod-1.0.2.

I don't mean to sound impatient, but it has been a while now.

Regards,
Stuart Longland

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

Successfully merging this pull request may close these issues.

3 participants