Comments (3)
I think type checkers can implement the semantics of NotImplemented
without actually requiring it in the types. Specifically, given a + b
,
- if
type(a).__add__(b)
type checks, i.e.type(a)
has an overload expectingb
, -- use that, - otherwise fall back
type(b).__radd__(a)
.
Note also that
Literal[NotImplemented]
is not permitted becauseNotImplemented
is not an enum nor a literal syntactically;NotImplementedType
could be used to describe instances ofNotImplemented
, but it is not currently available from pure python AFAICT;- Alternatively, we could handle
NotImplemented
similarly toNone
in thatNotImplemented
in a type annotation meansNotImplementedType
.
from typing.
Those are not the exact rules. Sometimes __radd__
is called first (the rule is so complicated I don't recall offhand if that can be determined statically or not). And when both return NotImplemented
, the interpreter issues the exception.
Anyway, we might still consider this, given that the convention in typeshed appears to be not to show NotImplemented
. (This would only be a problem for direct callers of these overloads, which must be very rare.)
I am aware of the issues around Literal[NotImplemented]
, I just used as a shorthand (if it did work, it would be ideal :-).
from typing.
NotImplemented is generally just ignored by the type system; in typeshed we treat it as being a subclass of Any
I think to move forward here we'd need:
- A survey of what type checkers currently do
- Some thinking about how we could make the behavior more useful. Are there plausible user mistakes that type checkers currently can't catch, but that could be caught if we came up with a better set of rules? Conversely, are there patterns that work at runtime that type checkers currently do not allow?
from typing.
Related Issues (20)
- Conformance tests: Align automated and manual scoring HOT 1
- Introduce a `Language` type to provide consistent language information of strings. HOT 5
- Spec: Version and platform checking underspecified HOT 6
- Support list comprehension for `TypeVarTuple` HOT 2
- Clarify the float/int/complex special case HOT 5
- Clarify the implications of subclassing Any HOT 1
- Allow multiple `TypeVarTuple` in Generic Classes when they are wrapped. HOT 5
- 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
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.