Shoobx / mypy-zope

Plugin for mypy to support zope.interface
MIT License
39 stars 13 forks source link

Attempt to make the test suite pass under mypy 1.0.0 #89

Closed DMRobertson closed 1 year ago

DMRobertson commented 1 year ago

For your consideration: an attempt to update this plugin to work with the recent mypy 1.0.0 release.

https://github.com/Shoobx/mypy-zope/pull/85 was an attempt to establish compatibility with mypy 0.991. It was partially successful, but ultimately blocked on https://github.com/python/mypy/issues/14106

I wanted to take a look to see if could make any progress. I think I was able to workaround the linked mypy issue with a dirty, brittle and naughty hack (see https://github.com/Shoobx/mypy-zope/pull/89/commits/da1d0fb4ef97f1d574cf0b458297def76c45ef5c). It might be too brittle to include upstream; let me know what you think.

On my machine, all but one test passes. I am not sure how to handle the failure:

``` $ pytest -vv --lf =================================================================================================================================== test session starts ==================================================================================================================================== platform linux -- Python 3.10.9, pytest-7.1.3, pluggy-1.0.0 -- /home/dmr/workspace/mypy-zope/ve/bin/python3 cachedir: .pytest_cache rootdir: /home/dmr/workspace/mypy-zope plugins: cov-3.0.0 collected 1 item run-last-failure: rerun previous 1 failure (skipped 1 file) tests/test_samples.py::test_samples[interface_meta] FAILED [100%] ========================================================================================================================================= FAILURES ========================================================================================================================================= _______________________________________________________________________________________________________________________________ test_samples[interface_meta] _______________________________________________________________________________________________________________________________ samplefile = '/home/dmr/workspace/mypy-zope/tests/samples/interface_meta.py', mypy_cache_dir = '/tmp/pytest-of-dmr/pytest-75/.mypy_cahe0' def test_samples(samplefile, mypy_cache_dir): opts = options.Options() opts.cache_dir = mypy_cache_dir opts.show_traceback = True opts.namespace_packages = True opts.hide_error_codes = True opts.plugins = ['mypy_zope:plugin'] # Config file is needed to load plugins, it doesn't not exist and is not # supposed to. opts.config_file = ' not_existing_config.ini' try: base_dir = os.path.dirname(samplefile) source = BuildSource(samplefile, module=None, text=None, base_dir=base_dir) res = build.build( sources=[source], options=opts) except CompileError as e: assert False, e normalized = normalize_errors(res.errors, samplefile) actual = '\n'.join(normalized) expected = find_expected_output(samplefile) > assert actual == expected E assert ('interface_meta.py:13: error: Missing positional argument "object" in call to '\n '"providedBy" of "ISpecification"\n'\n 'interface_meta.py:13: error: Argument 1 to "providedBy" of "ISpecification" '\n 'has incompatible type "Type[T]"; expected "ISpecification"\n'\n 'interface_meta.py:19: note: Revealed type is "__main__.IBookmark"') == 'interface_meta.py:19: note: Revealed type is "__main__.IBookmark"' E + interface_meta.py:13: error: Missing positional argument "object" in call to "providedBy" of "ISpecification" E + interface_meta.py:13: error: Argument 1 to "providedBy" of "ISpecification" has incompatible type "Type[T]"; expected "ISpecification" E interface_meta.py:19: note: Revealed type is "__main__.IBookmark" tests/test_samples.py:49: AssertionError ---------------------------------------------------------------------------------------------------------------------------------- Captured stdout setup ----------------------------------------------------------------------------------------------------------------------------------- Setup cache /tmp/pytest-of-dmr/pytest-75/.mypy_cahe0 ================================================================================================================================= short test summary info ================================================================================================================================== FAILED tests/test_samples.py::test_samples[interface_meta] - assert ('interface_meta.py:13: error: Missing positional argument "object" in call to '\n '"providedBy" of "ISpecification"\n'\n 'interface_meta.py:13: error: Argument 1 to "providedBy" of "ISpecification" '\n 'has incom... ==================================================================================================================================== 1 failed in 3.92s ===================================================================================================================================== ```

Fixes #82 (I think?) Closes #85

DMRobertson commented 1 year ago

Take it out of WIP whenever you're ready to merge this.

I've just done so. (I wanted to run this PR + mypy 1.0 against https://github.com/matrix-org/synapse/. There weren't any new errors related to the plugin AFACIS, other than those covered by #88.)

And thanks for digging into it!

My pleasure. I just hope the hack doesn't come back to bite us in the future!

kedder commented 1 year ago

I just hope the hack doesn't come back to bite us in the future!

I'm sure it will eventually, but we'll deal with it when it happens :)

kedder commented 1 year ago

Released in mypy-zope-0.9.0