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

[WIP] fix from_type under Python 3.7 #1402

Merged
merged 3 commits into from
Jul 23, 2018
Merged

Conversation

Zac-HD
Copy link
Member

@Zac-HD Zac-HD commented Jul 17, 2018

Closes #1264, closes #1148.

  • Fixes two new deprecation errors in our tests (related to asyncio and collections.abc), and a test failure related to the new UTF-8 mode (by accepting the escape code or the character itself)
  • Cleans up after the from_type puppy again; given that the typing module is still provisional I expect to do this again for 3.8 😭. This means adding TypeVar support because bare generics now have explicit typevars as their contents at runtime (ugh), and adding yet another set of compatibility shims and conditional logic. It's not pretty but it does all work.
  • dataclasses already work via the existing annotation-based machinery - it's a miracle of unusually restrained design, but there you are.

@Zac-HD Zac-HD force-pushed the typing-37 branch 5 times, most recently from be0396c to d8e81b5 Compare July 20, 2018 20:30
@DRMacIver DRMacIver closed this Jul 21, 2018
@DRMacIver DRMacIver reopened this Jul 21, 2018
@DRMacIver
Copy link
Member

Whoops. sorry, I fucked that up! Wrong window open when I clicked the close and comment button.

@Zac-HD
Copy link
Member Author

Zac-HD commented Jul 22, 2018

CC @DRMacIver for review.

Copy link
Member

@DRMacIver DRMacIver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm feeling a bit 🤷‍♂️ on how to review code on this feature TBH. The workarounds required to make it work seems to be getting increasingly involved and hacky, and I'm not very happy about that, but I'm not really sure what to suggest doing about it (other than maybe dropping the feature until the typing API stabilises, which would be sad).

Anyway, tests pass, which is an improvement on what we had before, so I'm going to rubber stamp it. I've commented on two things that I'd like addressed (one might be just me misunderstanding the code) but I don't need to re-review afterwards.

RELEASE_TYPE: patch

:func:`~hypothesis.strategies.from_type` now works on Python 3.7,
despite *another* set of internal changes to the :mod:`python:typing`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we should maybe try to contain our understandable exasperation with the CPython core team in our release notes.

@@ -296,8 +316,6 @@ def get_type_hints(thing):
except TypeError:
return {}
else:
import typing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like typing is guaranteed to be in scope here? The above import might have failed and been caught.

@Zac-HD
Copy link
Member Author

Zac-HD commented Jul 23, 2018

The workarounds required to make this feature work seem to be getting increasingly involved and hacky, and I'm not very happy about that, but I'm not really sure what to suggest doing about it (other than maybe dropping the feature until the typing API stabilises, which would be sad).

I'm also pretty unhappy about it, but agree that there's not much to be done. Basically there's just a lot of churn in the runtime behavior of the typing module, so we end up with a lot of fiddly special cases for odd objects under specific versions. Dropping support for from_type(some_generic_type) under 3.5 and 3.6 would probably each buy about a 25% reduction in the total amount of code - I'd rather not do that when it's all working, but it wouldn't be hard to talk me into dropping 3.5 as it barely works anyway.

I'll merge this as an improvement on the status quo, but agree that this isn't great either 😕

@Zac-HD Zac-HD merged commit 80d740a into HypothesisWorks:master Jul 23, 2018
@Zac-HD Zac-HD deleted the typing-37 branch July 23, 2018 01:42
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.

Hypothesis is not compatible with Python 3.7.0b3's typing module. We should test against Python 3.7
2 participants