Comments (3)
There already is an "unknown" type in Python: object
. JavaScript - and by extension Typescript - doesn't have a universal base type by virtue of having scalar types, making a synthetic unknown type necessary.
That said, I think some type checkers already have an internal "unknown" type although that has a slightly different purpose.
from typing.
As @srittau said, the object
type serves a similar purpose in Python's type system.
Pyright implements an Unknown
type to distinguish between an explicit Any
(one that comes from an Any
type expression) and an implicit Any
(one that is generated by a type checker when a type is unspecified, a TypeVar cannot be solved, an import cannot be resolved, etc.). For details, refer to the pyright documentation.
Pyright's concept of Unknown
differs from TypeScript's unknown
in that: 1) Unknown
cannot be used in a type expression because it is always implicit and 2) assignability rules for Unknown
are the same as Any
.
Here's a sample in pyright playground
from typing.
As @srittau said, the
object
type serves a similar purpose in Python's type system.Pyright implements an
Unknown
type to distinguish between an explicitAny
(one that comes from anAny
type expression) and an implicitAny
(one that is generated by a type checker when a type is unspecified, a TypeVar cannot be solved, an import cannot be resolved, etc.). For details, refer to the pyright documentation.Pyright's concept of
Unknown
differs from TypeScript'sunknown
in that: 1)Unknown
cannot be used in a type expression because it is always implicit and 2) assignability rules forUnknown
are the same asAny
.Here's a sample in pyright playground
- Thank you. I never checked Pyright, so wasn't aware it is so much better than MyPy 🙇 - I'm going to try and move my team from MyPy to Pyright.
- I think that having the unknown type as a PEP (and thus in the reference implementation i.e. MyPy) is very valuable.
from typing.
Related Issues (20)
- pytype conformance tests crash if no `python3.11` executable is in `PATH` HOT 5
- Conformance test: make dataclass_hash.py not rely on `typing.Hashable`? HOT 1
- Proposal: Add coerced type narrowing similar to 'cast' HOT 1
- Idenity Type HOT 2
- [spec] clarify assert_type behavior as asserting type equivalence
- [spec] better clarify the difference between a runtime type object and a static type HOT 1
- [spec] a protocol type should be assignable to object? HOT 1
- [spec] define or replace the term "concrete type" HOT 1
- [spec] conceptual foundation and glossary entries for variance
- [spec] Overload processing order HOT 2
- Clarify signification of `Annotation` HOT 2
- A generic 'frame' type
- Enable Projects? HOT 5
- (🎁) `get_type_hints` should add the class to the locals HOT 4
- Conformance tests: PEP 702 HOT 1
- [spec] Clarification: Are symbols not listed in `__all__` ever considered public? HOT 1
- [spec] Formalize excluded Protocol members HOT 2
- [@overload]: What is the effect of the *implementation* type-signature? HOT 3
- [spec] Can staticmethod calls infer type parameters for the containing class? HOT 1
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 typing.