Skip to content

Incompatibility with Python 3.1 #882

Closed

Description

@Arfrever

requests/models.py and tests/test_requests.py recently started using callable(), which is not available in Python 3.1.

$ python3.1 tests/test_requests.py -v
...
======================================================================
ERROR: test_allow_list_of_hooks_to_register_hook (__main__.RequestsTestSuite)
Issue 785: https://github.com/kennethreitz/requests/issues/785
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/test_requests.py", line 776, in test_allow_list_of_hooks_to_register_hook
    assert_hooks_are_callable(r.hooks)
  File "tests/test_requests.py", line 771, in assert_hooks_are_callable
    assert callable(h) is True
NameError: global name 'callable' is not defined

----------------------------------------------------------------------
Ran 76 tests in 64.134s

FAILED (errors=1)

Activity

  1. piotr-dobrogost commented on Oct 6, 2012

    @piotr-dobrogost

    callable() is back starting from Python 3.2 so just move forward :)

  2. kennethreitz commented on Oct 6, 2012

    @kennethreitz
    Contributor

    Wow, they removed callable?

  3. sigmavirus24 commented on Oct 6, 2012

    @sigmavirus24
    Contributor

    Yeah, seems they did. This is just ridiculous. Is there a better way to test this?

  4. Arfrever commented on Oct 6, 2012

    @Arfrever
    Author

    When callable() does not exist, then you can use hasattr(x, "__call__") or isinstance(x, collections.Callable). (The second way is better.)

  5. kennethreitz commented on Oct 6, 2012

    @kennethreitz
    Contributor

    +1 for collections.Callable

  6. sigmavirus24 commented on Oct 6, 2012

    @sigmavirus24
    Contributor

    That's guaranteed across all versions of python that requests supports, right?

  7. Arfrever commented on Oct 6, 2012

    @Arfrever
    Author

    You can use:

    import collections
    try:
        callable = callable
    except NameError:
        def callable(x):
            return isinstance(x, collections.Callable)
    
  8. sigmavirus24 commented on Oct 6, 2012

    @sigmavirus24
    Contributor

    Meh, it would be easier to just use the isinstance pattern everywhere.

  9. kennethreitz commented on Oct 7, 2012

    @kennethreitz
    Contributor

    Yeah, I see no need to split.

  10. sigmavirus24 commented on Oct 7, 2012

    @sigmavirus24
    Contributor

    I see no need to split.

    I don't quite catch what you mean @kennethreitz

  11. Lukasa commented on Nov 24, 2012

    @Lukasa
    Member

    @kennethreitz: Do we want to fix this, or just stop claiming that we support Python 3.1, seeing as we don't test on it anyway?

  12. kennethreitz commented on Nov 24, 2012

    @kennethreitz
    Contributor

    I want to officially support 3.3 and up. Anything else is nice-to-have :)

  13. Lukasa commented on Nov 24, 2012

    @Lukasa
    Member

    Right. In that case, I'll run the tests on my box in Python 3.1 and see how much work is required to get them passing again.

  14. sigmavirus24 commented on Nov 27, 2012

    @sigmavirus24
    Contributor

    There's no way as far as I can tell to make Travis test 3.1 at the moment. http://about.travis-ci.org/docs/user/ci-environment/#Python-versions Also they still don't have support for 3.3 (unless their docs are wildly out of date).

  15. kennethreitz commented on Nov 27, 2012

    @kennethreitz
    Contributor

    It's undocumented, but exists if you specify it. They are working to remove it though.

    We had a big argument about it this week :)

  16. sigmavirus24 commented on Nov 27, 2012

    @sigmavirus24
    Contributor

    Well in that case, perhaps removing the guarantee of 3.1 compatibility is the way to go. It would seem @Lukasa nipped this in #955 though, so this should be fixed. @Arfrever care to confirm?

  17. kennethreitz commented on Nov 27, 2012

    @kennethreitz
    Contributor

    I agree.

  18. Arfrever commented on Nov 27, 2012

    @Arfrever
    Author

    I think that the set of supported versions of Python should not be restricted by what is supported by Travis.

  19. sigmavirus24 commented on Nov 27, 2012

    @sigmavirus24
    Contributor

    @Arfrever there's this from Kenneth:

    I want to officially support 3.3 and up. Anything else is nice-to-have :)

    But the other issue is that automating (regression) tests for python 3.1 is a pain. If someone wants to volunteer a server, they can use any of the GitHub API wrappers to verify the tests work on 3.1 and post as much.

  20. kennethreitz commented on Nov 27, 2012

    @kennethreitz
    Contributor

    Travis is just a nice excuse to not support it.

    I came up with the idea for the unicode literals PEP, actually, and it was for Requests. I have full intentions to use it.

  21. Arfrever commented on Nov 27, 2012

    @Arfrever
    Author

    There might be software projects, which use Requests, but do not yet work with Python 3.3, so please do not remove support for Python 3.2.

    AFAIK the only feature present in Python 2.6, 2.7 and 3.2, but not in 3.1, is callable(), which can be easily defined for Python 3.1 as shown in comment 9202340.

  22. Lukasa commented on Nov 27, 2012

    @Lukasa
    Member

    @Arfrever: Such a project can continue to use Requests 0.14.2 (or whatever version we get to where we finally break 3.2) with no ill effects.

    Regarding supported versions, if Travis doesn't test 3.1 for us then we have to assume that anyone raising a PR has not tested on 3.1 either. This requires Kenneth (or another contributor) to patch a copy of Requests with the PR and test it themselves, which is boring and time-inefficient. It's for this reason that bugs like this one crop up in the library: we simply do not have time to catch regressions.

    If I thought supporting 3.1 and 3.2 was a long-term priority I'd try to use a local box to run these tests automatically, but the reality is we're simply going to stop supporting these versions. To be clear, we aren't going to break these right now: I'm not going to raise a PR tomorrow that puts unicode literals on every string, for instance. 3.1 and 3.2 will likely continue to function until 1.0, when Kenneth finishes his Transport Adapters stuff.

    In the meantime, the original issue is fixed, so I'm closing it. Thanks for the bug report, please keep them coming! =)

  23. sigmavirus24 commented on Nov 27, 2012

    @sigmavirus24
    Contributor

    @Lukasa well explained. Thank you.

  24. locked as resolved and limited conversation to collaborators on Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions