Skip to content

fix contextlib GeneratorContextManager name for py>=3.2#3083

Merged
ilevkivskyi merged 1 commit intopython:masterfrom
RafiB:fix-contextlib
Jul 2, 2019
Merged

fix contextlib GeneratorContextManager name for py>=3.2#3083
ilevkivskyi merged 1 commit intopython:masterfrom
RafiB:fix-contextlib

Conversation

@RafiB
Copy link
Contributor

@RafiB RafiB commented Jun 22, 2019

The change to contextlib.pyi is correct but breaking. Since py3.2 the contextlib member has been prefixed by the _ (compare https://github.com/python/cpython/blob/ccc4ffe7a1e2ae151959446722bf1b58834f5e9f/Lib/contextlib.py#L9 to https://github.com/python/cpython/blob/076ca6c3c8df3030307e548d9be792ce3c1c6eea/Lib/contextlib.py#L33). An existing mypy test expects the broken behaviour: https://github.com/python/mypy/blob/2e098a2ee1fec57e46b21f49b673cdfe01f8dc21/test-data/unit/pythoneval.test#L1033
This results in a local test failure when running mypy tests:

================================================================ FAILURES =================================================================
___________________________________________________________ testContextManager ____________________________________________________________
[gw0] darwin -- Python 3.6.1 /Users/rafblecher/mypy-dev/mypy/typeshed/.venv3/bin/python3
data: /private/var/folders/c0/z0xdn8fn0_zb3d15r_t0ljqdh3w3np/T/tmp0bvghzmq/mypy/test-data/unit/pythoneval.test:1014:
../tmp0bvghzmq/mypy/mypy/test/testpythoneval.py:44: in run_case
    test_python_evaluation(testcase, os.path.join(self.cache_dir.name, '.mypy_cache'))
../tmp0bvghzmq/mypy/mypy/test/testpythoneval.py:104: in test_python_evaluation
    testcase.file, testcase.line))
../tmp0bvghzmq/mypy/mypy/test/helpers.py:114: in assert_string_arrays_equal
    raise AssertionError(msg)
E   AssertionError: Invalid output (/private/var/folders/c0/z0xdn8fn0_zb3d15r_t0ljqdh3w3np/T/tmp0bvghzmq/mypy/test-data/unit/pythoneval.test, line 1014)
---------------------------------------------------------- Captured stderr call -----------------------------------------------------------
Expected:
  _testContextManager.py:13: error: Revealed type is 'def (x: builtins.int) -> contextlib.GeneratorContextManager[builtins.str*]' (diff)
  _testContextManager.py:14: error: Revealed type is 'def (*x: builtins.str) -> contextlib.GeneratorContextManager[builtins.int*]' (diff)
  _testContextManager.py:16: error: Argument 1 to "f" has incompatible type "...
  _testContextManager.py:17: error: Revealed type is 'builtins.str*'
Actual:
  _testContextManager.py:13: error: Revealed type is 'def (x: builtins.int) -> contextlib._GeneratorContextManager[builtins.str*]' (diff)
  _testContextManager.py:14: error: Revealed type is 'def (*x: builtins.str) -> contextlib._GeneratorContextManager[builtins.int*]' (diff)
  _testContextManager.py:16: error: Argument 1 to "f" has incompatible type "...
  _testContextManager.py:17: error: Revealed type is 'builtins.str*'

Alignment of first line difference:
  E: ...builtins.int) -> contextlib.GeneratorContextManager[builtins.str*]'
  A: ...builtins.int) -> contextlib._GeneratorContextManager[builtins.str*]'
                                    ^

Fix for the mypy tests python/mypy#6958 -- I will need help from the core dev team to sync the changes.

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

OK, I am going to merge this now and sync mypy.

@ilevkivskyi ilevkivskyi merged commit 668d050 into python:master Jul 2, 2019
ilevkivskyi pushed a commit to python/mypy that referenced this pull request Jul 2, 2019
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.

2 participants