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

Fix TypeError when importing pytest on Python 3.5.0 and 3.5.1 #5752

Merged
merged 6 commits into from Aug 20, 2019

Conversation

bluetech
Copy link
Member

@bluetech bluetech commented Aug 16, 2019

The typing module on these versions have these issues:

  • typing.Pattern cannot appear in a Union since it is not considered a
    class.

  • @overload is not supported in runtime. (On the other hand, mypy
    doesn't support putting it under if False, so we need some runtime
    hack).

Fix #5751
Fix #5770

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

Awesome @bluetech, thanks a lot for the quick fix.

In the future, I suggest you add "Fix ###" instead of "Refs: ###" as this will close the issue automatically when merged. 😉

changelog/5751.bugfix.rst Outdated Show resolved Hide resolved
src/_pytest/_code/code.py Outdated Show resolved Hide resolved
src/_pytest/python_api.py Outdated Show resolved Hide resolved
@bluetech
Copy link
Member Author

Thanks for the review @nicoddemus.

The reason I didn't close the issue is that I thought it'd be best to fix this regression quickly for 5.1.x, and then use the issue to discuss how to proceed. The options as I see them are:

  1. Keep Python 3.5.{0,1} support - in this case we should probably add it to CI (or change the 3.5 job to use it), move the hacks to _compat.py and also update flake8-typing-imports to detect these edge cases. Otherwise it is bound to regress again.

  2. Drop support for Python 3.5.{0,1} - would make typing easier since it's missing a lot of things.

For selfish reasons, my preference is obviously 2 :)

src/_pytest/_code/code.py Outdated Show resolved Hide resolved
The typing module on these versions have these issues:

- `typing.Pattern` cannot appear in a Union since it is not considered a
  class.

- `@overload` is not supported in runtime. (On the other hand, mypy
  doesn't support putting it under `if False`, so we need some runtime
  hack).

Refs pytest-dev#5751.
@bluetech
Copy link
Member Author

Updated per comments, except for moving to compat, as explained above.

@asottile
Copy link
Member

Updated per comments, except for moving to compat, as explained above.

looks like the comment about compat didn't make it through -- I assume it's because mypy won't understand it

@nicoddemus
Copy link
Member

looks like the comment about compat didn't make it through -- I assume it's because mypy won't understand it

Even for overload?

Also @bluetech, would it be possible to add 3.5.0 to CI?

@nicoddemus
Copy link
Member

Here's how trio does it:

https://github.com/python-trio/trio/blob/4512ae3ca199f0a99d02f6ff2a6f8e94dd08f1ef/.travis.yml#L17-L18

I think we can only add it to Travis as well, skipping Azure. 👍

@asottile
Copy link
Member

I should probably also make flake8-typing-imports smarter about this -- we should really be able to figure most of this out statically 🤔

blueyed added a commit to blueyed/pytest that referenced this pull request Aug 17, 2019
@blueyed
Copy link
Contributor

blueyed commented Aug 17, 2019

I am not a fan of supporting 3.5.0 etc.
It turns out to even be non-trivial to test this on CI: #5757

I can see that Python 3.5 is still supported in general (until September 2020), but would vote for dropping support of it soon in pytest, especially given that we can benefit a lot from type annotations, and py35 make this much more unpleasant.

@asottile
Copy link
Member

I don't think we can drop py35 quite yet, maybe 3.5.0 / 3.5.1 though -- but in order to do that, we need to have a latest release that works correctly with those versions and then we can exclude them with python_requires -- so either way we need to fix this

that said, I think if I fixed flake8-typing-imports to recognize these cases then we can ~reasonably rely on that without having to actually test 3.5.0 / 3.5.1

@blueyed
Copy link
Contributor

blueyed commented Aug 17, 2019

@asottile
Would that also cover #5751 then?

@asottile
Copy link
Member

yes that would be the goal

@blueyed
Copy link
Contributor

blueyed commented Aug 17, 2019

Pulled in the testing with 3.5.0 on Travis.

src/_pytest/python_api.py Outdated Show resolved Hide resolved
Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

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

@blueyed
Copy link
Contributor

blueyed commented Aug 19, 2019

TestRaises.test_raises_cyclic_reference[with] fails on 3.5.0: https://travis-ci.org/pytest-dev/pytest/jobs/573541272#L5590

@@ -43,7 +43,8 @@ jobs:
python: 'pypy3'

- env: TOXENV=py35-xdist
python: '3.5'
dist: trusty
python: '3.5.0'
Copy link
Member

@Zac-HD Zac-HD Aug 20, 2019

Choose a reason for hiding this comment

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

Based on my experience with Hypothesis, we need tests to ensure that Pytest's typing-related things don't regress on 3.5.0 or 3.5.x, meaning an additional environment rather than pinning to .0.

It's kinda annoying, but there we are - it's stuff like this that makes me worried about the exotic proposals for CPython release cadence and sympathetic to the "batteries are leaking" argument.

Copy link
Contributor

Choose a reason for hiding this comment

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

We have 3.5.x in Azure, no?
btw: Django only supports the latest patch releases of Python versions.

@bluetech bluetech dismissed nicoddemus’s stale review August 20, 2019 09:28

Comments were addressed.

@bluetech
Copy link
Member Author

I added a workaround for the TestRaises.test_raises_cyclic_reference[with] test. CI looks happy now. I think we can merge it now.

@RonnyPfannschmidt
Copy link
Member

i just catched up on prs, it looks like this one also sorts out #5770 as i

@bluetech
Copy link
Member Author

@RonnyPfannschmidt yes, since flake8-typing-imports was updated to catch the overload thing, and the flake8-typing-imports dependency wasn't pinned, it started to fail. This PR pins it and also fixes the lint.

@RonnyPfannschmidt
Copy link
Member

@bluetech thanks for the update, great job

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

LGTM! Please consider my suggestions for improved coverage. 👍

src/_pytest/compat.py Outdated Show resolved Hide resolved
testing/python/raises.py Show resolved Hide resolved
@bluetech
Copy link
Member Author

@nicoddemus Updated, but the coverage check failed again. It is quite inscrutable, do you have any other ideas how to please it?

@nicoddemus
Copy link
Member

Thanks @bluetech, again excellent work!

It is quite inscrutable, do you have any other ideas how to please it?

I never seen it myself, but I wouldn't worry about it given that patch is covered. 👍

@blueyed might have a suggestion here.

Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

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

@asottile asottile merged commit daff906 into pytest-dev:master Aug 20, 2019
@blueyed
Copy link
Contributor

blueyed commented Aug 20, 2019

pragma: no cover

I recommend just being honest and not excluding this.
After all it is not covered, and makes it easy to find dead (uncovered) code
etc later.

I agree that we do not have to run coverage for 3.5.0 though - which then
should also have made it covered. In my humble opinion a better workaround than
adding the comment (but with more overhead).

@asottile
Animated gifs are distracting when you are writing a comment.

@asottile
Copy link
Member

@asottile
Animated gifs are distracting when you are writing a comment.

I'm sorry you hate fun :P, consider blocking them

@nicoddemus
Copy link
Member

I recommend just being honest and not excluding this.
After all it is not covered, and makes it easy to find dead (uncovered) code
etc later.

I see it differently: a "pragma no cover", to me, is clear a indication on code about this shared agreement:

I agree that we do not have to run coverage for 3.5.0

This way people in the future don't have to worry about covering those lines if we ever do a "let's get to 100% coverage" movement or such.

But other than that I don't feel too strongly about it either way. 😁

@blueyed
Copy link
Contributor

blueyed commented Aug 20, 2019

@asottile

I'm sorry you hate fun :P,

That's not my kind of fun.. ;)

consider blocking them

How? Using an ad block for their URL?
Everything from https://camo.githubusercontent.com/ then? (feels a bit exaggerated)
Unfortunately you cannot just stop them using escape like e.g. in Firefox (IIRC) in qutebrowser (https://github.com/qutebrowser/qutebrowser/issues?q=is%3Aissue+animated+gifs+is%3Aclosed).

@nicoddemus

This way people in the future don't have to worry about covering those lines if we ever do a "let's get to 100% coverage" movement or such.

If that ever would be a goal then we should just run the coverage for 3.5.0 also.

I do not feel too strong about it myself, but not adding the comment there would have been the easier (and slightly clearer) way. Just ignore the "hint" from codecov then.

@asottile
Copy link
Member

probably something like

##img[canonical-src*=".gif"]

@blueyed blueyed mentioned this pull request Aug 20, 2019
@bluetech bluetech deleted the typing-py350-fix branch February 28, 2020 12:09
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.

flake8 failure for overload latest pytest crashes on import on python 3.5.0
6 participants