Git Product home page Git Product logo

Comments (4)

erictraut avatar erictraut commented on September 27, 2024

The type class in the builtins.pyi stub file is defined as:

class type:
     ...
    def __init__(self, name: str, bases: tuple[type, ...], dict: dict[str, Any], /, **kwds: Any) -> None: ...
     ...
    def __call__(self, *args: Any, **kwds: Any) -> Any: ...

Based on this definition, mypy is working correctly. Not surprisingly, its behavior matches the other major type checkers here.

If you think that typeshed definition is incorrect or could be improved, you could file a bug report or PR in the typeshed project.

from mypy.

KotlinIsland avatar KotlinIsland commented on September 27, 2024

if these type checkers were just following the stubs, then I would expect A("a") to behave identically to A.__call__("a") and not show an error. The truth is that currently type checkers are special casing type.__call__, but only the operator form, and not the attribute form.

from mypy.

erictraut avatar erictraut commented on September 27, 2024

The truth is that currently type checkers are special casing type.call, but only the operator form, and not the attribute form.

Yes, that's conformant with the recently accepted typing spec chapter on constructor call validation. Mypy is doing the right thing here according to the typing spec, and so are the other type checkers.

If you would like to suggest a change to the typing spec, the typing forum would be a good place to have that discussion.

from mypy.

KotlinIsland avatar KotlinIsland commented on September 27, 2024

Type checkers should mirror this runtime behavior when analyzing a constructor call.

Type checkers are not mirroring this runtime behavior correctly in this case.

That spec should be updated to be more explicit about how to mirror the runtime behavior (to match this case), the type-checkers should be updated to match the runtime behaviour, and typeshed could be updated to have the correct type.

from mypy.

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.