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

Upgrade to mypy-0.991 #85

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ packages =
zope-stubs
package_dir = =src
install_requires =
mypy==0.981
mypy==0.991
zope.interface
zope.schema
include_package_data = True
Expand Down
6 changes: 5 additions & 1 deletion src/mypy_zope/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)
from mypy.checker import TypeChecker, is_false_literal
from mypy.options import Options
from mypy.nodes import TypeInfo
from mypy.nodes import TypeInfo, IS_ABSTRACT
from mypy.plugin import (
CheckerPluginInterface,
SemanticAnalyzerPluginInterface,
Expand Down Expand Up @@ -520,6 +520,10 @@ def _adjust_interface_function(
func_def.arg_kinds.insert(0, ARG_POS)
func_def.arguments.insert(0, selfarg)

# All interface methods are abstract by definition. This
# suppresses "empty-body" errors.
func_def.abstract_status = IS_ABSTRACT
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you try

# Implicitly abstract: used for functions with trivial bodies defined in Protocols
743 | IMPLICITLY_ABSTRACT: Final = 2

Maybe it works a little better since an Interface is kind of a typing.Protocol.

Copy link
Contributor

Choose a reason for hiding this comment

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

Trying that against mypy 1.0 yields a new class of errors, e.g.:

______________________________________________________ test_samples[adaptation] ______________________________________________________

samplefile = '/home/dmr/workspace/mypy-zope/tests/samples/adaptation.py', mypy_cache_dir = '/tmp/pytest-of-dmr/pytest-7/.mypy_cahe1'

    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 'adaptation.p...xpected "str"' == 'adaptation.p...xpected "str"'
E           adaptation.py:11: error: 'AbstractSomething' is missing following 'ISomething' interface members: hello.
E         + adaptation.py:26: error: Cannot instantiate abstract class "ISomething" with abstract attribute "hello"
E         + adaptation.py:26: note: "hello" is implicitly abstract because it has an empty function body. If it is not meant to be abstract, explicitly `return` or `return None`.
E           adaptation.py:27: error: Argument 2 to "hello" of "ISomething" has incompatible type "int"; expected "str"

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, actually I think this just means that a note gets added.


return func_def

def _adjust_interface_overload(
Expand Down