Comments (4)
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.
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.
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.
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)
- Spurious assignment error in disjunt condition branches
- [good-first-issue] Incomplete Cobertura XML spec support
- Raise errors when importing from the `typing` package instead of using the built-in types. HOT 2
- RecursionError: maximum recursion depth exceeded HOT 8
- new generics should be inferred as covariant instead of invariant on frozen dataclasses
- `functools.reduce` over sets: empty set not accepted without annotation
- `functools.reduce` over sets becomes unacceptable when used in a larger expression
- Assertion Error in StubtestUnit::test_protocol with Python 3.7 Environment HOT 2
- assignment to `_` inside a function incorrectly becomes `Any`
- constrained TypeVar and star operator incompatible type
- `--untyped-calls-exclude` does not exclude some packages/libraries HOT 1
- Mypy cannot guess callable return type (`Tuple[Type[T], ...] -> T`) HOT 2
- Should mypy check existence of module attributes for unannotated modules? HOT 1
- False positive: "overloaded signature will never be matched" with Self
- module name assumed is __main__ for .pyw files on windows
- False positive when using `Self` as the return type with multiple base classes HOT 1
- torch-nn-functional-mypy-bug-when-torchvision-installed
- dmypy crashes from RecursionError for some complex expressions (fastparse) HOT 1
- PEP 695 variance inferred as simultaneously covariant and contravariant HOT 2
- False negative for invalid abstractmethod implementation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mypy.