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

Install typing package only for Python < 3.5 #10821

Merged
merged 2 commits into from
Mar 10, 2020

Conversation

cghawthorne
Copy link
Contributor

Prevents conflicts with built-in typing library. Follows advice in python/typing#573

Modifies change introduced in #9915. @chadrik @robertwb


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

Post-Commit Tests Status (on master branch)

Lang SDK Apex Dataflow Flink Gearpump Samza Spark
Go Build Status --- --- Build Status --- --- Build Status
Java Build Status Build Status Build Status Build Status
Build Status
Build Status
Build Status Build Status Build Status
Build Status
Build Status
Python Build Status
Build Status
Build Status
Build Status
--- Build Status
Build Status
Build Status
Build Status
--- --- Build Status
XLang --- --- --- Build Status --- --- ---

Pre-Commit Tests Status (on master branch)

--- Java Python Go Website
Non-portable Build Status Build Status
Build Status
Build Status Build Status
Portable --- Build Status --- ---

See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.

@chadrik
Copy link
Contributor

chadrik commented Feb 10, 2020

Seems reasonable to me.

@cghawthorne
Copy link
Contributor Author

Just for completeness, here's an example where the current setup was causing a problem: https://travis-ci.org/tensorflow/magenta/builds/647132754

@robertwb
Copy link
Contributor

Has the builtin typing package evolved since 3.5 in ways that the external library has backported (and that we use)?

@iemejia iemejia added the python label Feb 12, 2020
@cghawthorne
Copy link
Contributor Author

My understanding from the bug linked above is that the typing external library is intended only to be used with versions of python (<3.5) that don't already have it built in and that it causes problems when it overrides built-in versions (python >3.5).

@chadrik
Copy link
Contributor

chadrik commented Feb 13, 2020

I had a chance to look at the linked issues a bit more, and I take back my original assessment for the moment.

Has the builtin typing package evolved since 3.5 in ways that the external library has backported (and that we use)?

It has changed a lot, and I'd say it's highly likely that we're relying on features from newer typing libraries. And if we were to change to using the stdlib for typing it would be incredibly easy for a developer to use a feature in a later version of typing without knowing it (which may or may not be caught by tests). You would basically have to keep a copy of the 3.5 version of typing around and constantly refer back to it.

Here's a diff (search for src/typing.py):

python/typing@3.5.3.0...3.7.4.1

Just for completeness, here's an example where the current setup was causing a problem: https://travis-ci.org/tensorflow/magenta/builds/647132754

What I'm confused about is that you're testing in python 3.7.1, and beam's minimum version of typing is 3.7.0 and the max version on pypi is 3.7.4.1. So in the range 3.7.0 .. 3.7.4.1. I checked the diffs between that range and almost nothing changed about the typing library in that release range (added SupportsIndex), which seems to indicate that the version of typing pulled in by beam should be identical (or nearly) to the stdlib for 3.7.1. Is there a chance you're picking up an older version of typing from another library? IIRC, pip does a shit job with transitive dependencies.

@cghawthorne
Copy link
Contributor Author

The Travis log includes the full installation history, so I'm pretty sure we're picking up typing-3.7.4.1 and typing-extensions-3.7.4.1.

The thing that triggered the problem for us was the beam 2.19.0 release. Maybe that started referring to a new set of types that caused problems? For now, we're just avoiding that release, which stopped the error from occurring (magenta/magenta@6ff823d).

@chadrik
Copy link
Contributor

chadrik commented Feb 13, 2020

Do you have a log indicating which version of typing gets picked up with 2.18.0? I assume it's the same version. I think you're right that

Maybe that started referring to a new set of types that caused problems?

The exception is not coming from Beam, so it's unclear how using a feature of the typing module in Beam could be causing this issue, especially considering the typing module doesn't do much.

I'm not saying the problem isn't caused by Beam, but the evidence has left me pretty perplexed.

@aaltay
Copy link
Member

aaltay commented Feb 15, 2020

drive by comment, this also seems related to the issue in (conda-forge/apache-beam-feedstock#21).

Do we know, if we are actually depending on the newer features from the typing libraries?

@chadrik
Copy link
Contributor

chadrik commented Feb 23, 2020

Do we know, if we are actually depending on the newer features from the typing libraries?

The typing features added since 3.5.3 are:

  • ContextManager
  • SupportsBytes
  • SupportsComplex
  • SupportsIndex
  • Counter
  • Deque
  • NoReturn

I'm pretty sure I did not use any of these.

There were significant runtime changes to the typing module, but the impact of these is impossible to predict from looking at the diff, and some of them may be beneficial while others are detrimental (hence this PR).

@cghawthorne can you remove the change to typing_extensions, its absence is causing test failures. This module is required for Protocol, which did not get added to typing until later versions (3.7.something).

@chadrik
Copy link
Contributor

chadrik commented Feb 24, 2020

Back with some more info.

I'm increasingly of the opinion that this PR is the right way to go, but merging it should be contingent upon dropping support for python versions less than 3.5.3.

Here's why

  1. pip install typing does not necessarily override the stdlib typing, because site-packages comes after the stdlib directories on sys.path.

  2. There were substantial changes made to typing from 3.5.0 to 3.5.3. Here's what was added (the list in my previous comment was for after 3.5.3):

    • ClassVar
    • Type
    • DefaultDict
    • FrozenSet
    • NewType
    • Text
    • TYPE_CHECKING

    We're using most of these, so the code as it stands right now will fail for python 3.5.0 or 3.5.1. I think it's untenable to remove the use of these features, so we must choose a minimum point release to support.

  3. Our tests are running against python 3.5.2, and I just ran into a bug with the typing module in 3.5.2 that was fixed in 3.5.3:

    https://scans.gradle.com/s/m7i4h44oi4cru/console-log?task=:sdks:python:test-suites:tox:py35:testPy35Cython

  4. python 3.5.3 has the most up-to-date version of typing until python 3.6.1

Therefore, I think we'll be in pretty good shape if we update our test runners to use python 3.5.3 and then merge this PR.

@aaltay
Copy link
Member

aaltay commented Feb 24, 2020

Thank you @chadrik. This is great information. I agree with your conclusion.

/cc @tvalentyn

@tvalentyn
Copy link
Contributor

tvalentyn commented Feb 24, 2020

Thanks. The main problem with setting 3.5.3 as minimal required version is that Beam Jenkins workers are stuck with 3.5.2 right now, but we have an AI to address that: https://issues.apache.org/jira/browse/BEAM-8152. cc: @mwalenia @kamilwu @yifanzou .

We can skip tests failing on 3.5.2 if Python 3.5 version is less than 3.5.3 in the meantime. Do we have a lot of tests that are affected?

@chadrik
Copy link
Contributor

chadrik commented Feb 24, 2020

We can skip tests failing on 3.5.2 if Python 3.5 version is less than 3.5.3 in the meantime. Do we have a lot of tests that are affected?

Not yet. I was about to introduce one on another PR, but if the switch to 3.5.3 is going to be awhile I can work around it. Is there Jira issue that I can reference in the code?

@tvalentyn
Copy link
Contributor

@cghawthorne
Copy link
Contributor Author

Anything I can help with here? I'm not completely following what all the blocking items are at this point.

@tvalentyn
Copy link
Contributor

retest this please

@tvalentyn
Copy link
Contributor

tvalentyn commented Mar 9, 2020

Rerunning the tests to see which tests failed on this PR. Requiring 3.5.3 is blocked on BEAM-8152. Would

    'typing>=3.7.0,<3.8.0; python_version < "3.5.3"',
    'typing-extensions>=3.7.0,<3.8.0; python_version < "3.5.3"',

be a possible workaround?

@tvalentyn
Copy link
Contributor

So the tests fail because typing_extensions.Protocol is used in fn_api_runner.py, so we would need to make change there; from the discussion above @chadrik was thinking this through. @chadrik - do you have any suggestions how to reconcile dropping typing backports and using typing_extensions.Protocol ? Is there a concurrent change you are working on?

@chadrik
Copy link
Contributor

chadrik commented Mar 9, 2020

typing_extensions is always required. I think the requirements should look like this:

    'typing>=3.7.0,<3.8.0; python_version < "3.5.3"',
    'typing-extensions>=3.7.0,<3.8.0

@chadrik
Copy link
Contributor

chadrik commented Mar 9, 2020

typing_extensions is always required.

I guess I should say, it's always required until such a time as Protocol and Literal are both included in typing and we drop versions of python3 that don't include a new enough version of typing.

@tvalentyn
Copy link
Contributor

typing_extensions is always required. I think the requirements should look like this:

    'typing>=3.7.0,<3.8.0; python_version < "3.5.3"',
    'typing-extensions>=3.7.0,<3.8.0

SGTM; @cghawthorne - could you please give it a try? Let's see if tests are passing.

Prevents conflicts with built-in typing library. Follows advice in python/typing#573
@cghawthorne
Copy link
Contributor Author

Updated!

@tvalentyn
Copy link
Contributor

retest this please

@tvalentyn
Copy link
Contributor

Sigh, Jenkins is not paying heed again.

@tvalentyn
Copy link
Contributor

retest this please

@tvalentyn
Copy link
Contributor

@cghawthorne Thanks for the changes, we can merge once we have a green test signal.

@tvalentyn
Copy link
Contributor

Pinged https://issues.apache.org/jira/browse/INFRA-19836 and reached out to asfinfra via Slack regarding next steps there.

@tvalentyn
Copy link
Contributor

Run Python PreCommit

1 similar comment
@tvalentyn
Copy link
Contributor

Run Python PreCommit

@tvalentyn
Copy link
Contributor

ok, triggered now..

@tvalentyn
Copy link
Contributor

Run Python 3.6 PostCommit

@tvalentyn
Copy link
Contributor

Run Python 3.7 PostCommit

@tvalentyn
Copy link
Contributor

Run Python 3.5 PostCommit

@kamilwu
Copy link
Contributor

kamilwu commented Mar 10, 2020

Run Python PreCommit

@kamilwu
Copy link
Contributor

kamilwu commented Mar 10, 2020

Run Python 3.7 PostCommit

@tvalentyn
Copy link
Contributor

@tvalentyn tvalentyn merged commit 02cb8d8 into apache:master Mar 10, 2020
magenta-copybara pushed a commit to magenta/magenta that referenced this pull request Apr 20, 2020
PiperOrigin-RevId: 307461594
Change-Id: Icf93fbb0279cb2dc2933fde7800cc4c82a2a5233
kanggeonnim pushed a commit to kanggeonnim/magenta that referenced this pull request Apr 27, 2024
PiperOrigin-RevId: 307461594
Change-Id: Icf93fbb0279cb2dc2933fde7800cc4c82a2a5233
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants