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

Hypothesis is not compatible with Python 3.7.0b3's typing module. #1264

Closed
mingwandroid opened this issue May 1, 2018 · 8 comments · Fixed by #1402
Closed

Hypothesis is not compatible with Python 3.7.0b3's typing module. #1264

mingwandroid opened this issue May 1, 2018 · 8 comments · Fixed by #1402
Assignees
Labels
bug something is clearly wrong here

Comments

@mingwandroid
Copy link

mingwandroid commented May 1, 2018

In order to account for changes to the Python typing module made by python/cpython@d911e40 I am applying the following patch which may be ok, but more likely is not (the typing module is not something with which I am at all familiar):

From 27a17ef17be0e518ac06152442966e4dbb193fc5 Mon Sep 17 00:00:00 2001
From: Ray Donnelly <mingw.android@gmail.com>
Date: Tue, 1 May 2018 16:45:42 +0100
Subject: [PATCH] Fix typing _ForwardRef and TypingMeta for Python 3.7

These fixes are likely incorrect though.
---
 hypothesis-python/src/hypothesis/strategies.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/hypothesis-python/src/hypothesis/strategies.py b/hypothesis-python/src/hypothesis/strategies.py
index e324784b..82ebe842 100644
--- a/hypothesis-python/src/hypothesis/strategies.py
+++ b/hypothesis-python/src/hypothesis/strategies.py
@@ -1067,6 +1067,11 @@ def from_type(thing):
     from hypothesis.searchstrategy import types
     try:
         import typing
+        # Since https://github.com/python/cpython/commit/d911e40e788fb679723d78b6ea11cabf46caed5a
+        if hasattr(typing, '_ForwardRef'):
+            typing_ForwardRef = typing._ForwardRef
+        else:
+            typing_ForwardRef = typing.ForwardRef
         if not isinstance(thing, type):
             # At runtime, `typing.NewType` returns an identity function rather
             # than an actual type, but we can check that for a possible match
@@ -1083,7 +1088,7 @@ def from_type(thing):
                 return one_of([from_type(t) for t in args])
         # We can't resolve forward references, and under Python 3.5 (only)
         # a forward reference is an instance of type.  Hence, explicit check:
-        elif type(thing) == typing._ForwardRef:  # pragma: no cover
+        elif type(thing) == typing_ForwardRef:  # pragma: no cover
             raise ResolutionFailed(
                 'thing=%s cannot be resolved.  Upgrading to python>=3.6 may '
                 'fix this problem via improvements to the typing module.'
@@ -1112,7 +1117,11 @@ def from_type(thing):
     # subclass and instance checks.
     try:
         import typing
-        if isinstance(thing, typing.TypingMeta):
+        if hasattr(typing, 'TypingMeta'):
+            typing_TypeVar = typing.TypingMeta
+        else:
+            typing_TypeVar = typing.TypeVar
+        if isinstance(thing, typing_TypeVar):
             return types.from_typing_type(thing)
     except ImportError:  # pragma: no cover
         pass
-- 
2.17.0

Best regards.

@mingwandroid
Copy link
Author

mingwandroid commented May 1, 2018

If you need a build of Python 3.7.0b3 (and 207 python packages) against which to test hypothesis, and you are a user of the Anaconda Distribution and macOS, you can use conda create -n py27 -c c3i_test python=3.7 (other OSes to follow).

@Zac-HD Zac-HD added the bug something is clearly wrong here label May 2, 2018
@Zac-HD Zac-HD self-assigned this May 2, 2018
@Zac-HD
Copy link
Member

Zac-HD commented May 2, 2018

Thanks for reporting this! Compatibility bugs are always a high priority for us 😄

@DRMacIver / @alexwlchan, can one of you help out with #1148? typing module changes are explicitly called out there (in fact we would have caught this earlier), but my attempt to add it to CI failed 😭

I'm not keen to merge a fix before it can be tested, but with that out of the way this will be at the top of my list.

@mingwandroid
Copy link
Author

I'm not keen to merge a fix before it can be tested

Can/do you use miniconda in your CI? If so you could use c3i_test to get Python 3.7.0b3.

@mingwandroid
Copy link
Author

Is there any progress on this? Python 3.7 has been released now.

@DRMacIver
Copy link
Member

Is there any progress on this? Python 3.7 has been released now.

It has, but the release situation is frankly terrible and we're not sure what to do about it. 😢

The hard dependency on a new version of OpenSSL means that the release basically doesn't work on any of our CI infrastructure, and we're not able to fix that without making everything substantially worse or doing a bunch of build engineering to build OpenSSL ourself, which we haven't found time for yet.

@mingwandroid
Copy link
Author

Maybe try conda?, we handle all of that stuff for you.

@mingwandroid
Copy link
Author

@Zac-HD
Copy link
Member

Zac-HD commented Jul 15, 2018

Ah, thanks - I've now got a working conda environment set up and I'm starting to work through the long list of test failures. So far this is mostly just a matter of adding compatibility shims for renamed or changed objects such as "the class everything in typing inherits from" 🙄. Hopefully this is the last time...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants