Skip to content

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

Closed

Description

@mingwandroid

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 <[email protected]>
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.

Activity

  1. mingwandroid commented on May 1, 2018

    @mingwandroid
    Author

    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).

  2. added
    bugsomething is clearly wrong here
    on May 2, 2018
  3. self-assigned this
    on May 2, 2018
  4. Zac-HD commented on May 2, 2018

    @Zac-HD
    Member

    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.

  5. mingwandroid commented on May 2, 2018

    @mingwandroid
    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.

  6. mingwandroid commented on Jun 29, 2018

    @mingwandroid
    Author

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

  7. DRMacIver commented on Jun 29, 2018

    @DRMacIver
    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.

  8. mingwandroid commented on Jul 15, 2018

    @mingwandroid
    Author

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

  9. Zac-HD commented on Jul 15, 2018

    @Zac-HD
    Member

    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

Metadata

Metadata

Assignees

Labels

bugsomething is clearly wrong here

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions