Giter Club home page Giter Club logo

Comments (11)

kedder avatar kedder commented on May 28, 2024 1

@arnimarj, the fix is in #29. I think it should solve this issue.

from mypy-zope.

arnimarj avatar arnimarj commented on May 28, 2024

I modified get_metaclass_hook to be:

    def get_metaclass_hook(
        self, fullname: str
    ) -> Optional[Callable[[ClassDefContext], None]]:
        def analyze_metaclass(ctx: ClassDefContext) -> None:
            metaclass = cast(NameExpr, ctx.cls.metaclass)

            if isinstance(metaclass.node, Var):
                return

            info = cast(TypeInfo, metaclass.node)
            expected = "zope.interface.interface.InterfaceClass"
            if info and any(node.fullname == expected for node in info.mro):
                self.log(f"Found zope interface: {ctx.cls.fullname}")
                md = self._get_metadata(ctx.cls.info)
                md["is_interface"] = True

        return analyze_metaclass

...after looking at analyze_metaclass in MyPy. There is a short-circuit along the lines of:

            if isinstance(sym.node, Var) and isinstance(get_proper_type(sym.node.type), AnyType):
                # 'Any' metaclass -- just ignore it.
                #
                # TODO: A better approach would be to record this information
                #       and assume that the type object supports arbitrary
                #       attributes, similar to an 'Any' base class.
                return

That made the error go away

from mypy-zope.

kedder avatar kedder commented on May 28, 2024

Yeah, these casts in front of analyze_metaclass are not right. I'll try a more correct approach there, let me make a branch to test it.

from mypy-zope.

arnimarj avatar arnimarj commented on May 28, 2024

I've got a small test-case:

from i.dont.exist import MetaKlass


class Leg(metaclass=MetaKlass):
	pass

I believe mypy gives you a Var node when the metaclass has not been resolved

from mypy-zope.

kedder avatar kedder commented on May 28, 2024

Oh, thanks, I can add a test too then!

from mypy-zope.

arnimarj avatar arnimarj commented on May 28, 2024

my mypy.ini:

[mypy]
scripts_are_modules = True
show_traceback = True
disallow_any_generics = True
warn_no_return = True
no_implicit_optional = True
ignore_missing_imports = True
namespace_packages = True
plugins = mypy_zope:plugin

And the run:

$ PYTHONPATH=$(pwd) mypy --show-traceback --show-error-codes --config mypy.ini z.py 
z.py:4: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.800
Traceback (most recent call last):
  File "mypy/semanal.py", line 4835, in accept
  File "mypy/nodes.py", line 950, in accept
  File "mypy/semanal.py", line 1048, in visit_class_def
  File "mypy/semanal.py", line 1125, in analyze_class
  File "mypy/semanal.py", line 1134, in analyze_class_body_common
  File "mypy/semanal.py", line 1187, in apply_class_plugin_hooks
  File "/home/arni/.config/dohop/tools_venv3/lib/python3.8/site-packages/mypy_zope/plugin.py", line 270, in analyze_metaclass
    if info and any(node.fullname == expected for node in info.mro):
AttributeError: 'Var' object has no attribute 'mro'
z.py:4: : note: use --pdb to drop into pdb

from mypy-zope.

arnimarj avatar arnimarj commented on May 28, 2024

@arnimarj, the fix is in #29. I think it should solve this issue.

The issue seems to be gone. Thanks for the great turnaround speed.

from mypy-zope.

kedder avatar kedder commented on May 28, 2024

Do you want a new release with this fix?

from mypy-zope.

arnimarj avatar arnimarj commented on May 28, 2024

Do you want a new release with this fix?

Yes please :)

from mypy-zope.

kedder avatar kedder commented on May 28, 2024

0.2.10 is released

from mypy-zope.

arnimarj avatar arnimarj commented on May 28, 2024

0.2.10 is released

Thanks. We hit this bug in our regression tests, so a new release helps.

from mypy-zope.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.