From c636a8b20170c6422bbee2fdde92c432d4de55c7 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 8 Jan 2015 11:10:25 -0800 Subject: [PATCH] Add PEP 482, 483, 484 -- type hints. The latter two are stubs. --- pep-0482.txt | 222 +++++++++++++++++++++++++++++++++++++++++++++++++++ pep-0483.txt | 28 +++++++ pep-0484.txt | 28 +++++++ 3 files changed, 278 insertions(+) create mode 100644 pep-0482.txt create mode 100644 pep-0483.txt create mode 100644 pep-0484.txt diff --git a/pep-0482.txt b/pep-0482.txt new file mode 100644 index 000000000..44f722781 --- /dev/null +++ b/pep-0482.txt @@ -0,0 +1,222 @@ +PEP: 482 +Title: Literature Overview for Type Hinting +Version: $Revision$ +Last-Modified: $Date$ +Author: Łukasz Langa +Discussions-To: Python-Ideas +Status: Draft +Type: Informational +Content-Type: text/x-rst +Created: 08-Jan-2015 +Post-History: +Resolution: + +Abstract +======== + +This PEP is one of three related to type hinting. This PEP gives a +literature overview of related work. + + +Existing Approaches in Other Languages +====================================== + +mypy +---- + +(This section is a stub, since mypy [mypy]_ is essentially what we're +proposing.) + +ActionScript +------------ + +ActionScript [actionscript]_ is a class-based, single inheritance, +object-oriented superset of ECMAScript. It supports inferfaces and +strong runtime-checked static typing. Compilation supports a “strict +dialect” where type mismatches are reported at compile-time. + +Example code with types:: + + package { + import flash.events.Event; + + public class BounceEvent extends Event { + public static const BOUNCE:String = "bounce"; + private var _side:String = "none"; + + public function get side():String { + return _side; + } + + public function BounceEvent(type:String, side:String){ + super(type, true); + _side = side; + } + + public override function clone():Event { + return new BounceEvent(type, _side); + } + } + } + +Dart +---- + +Dart [dart]_ is a class-based, single inheritance, object-oriented +language with C-style syntax. It supports interfaces, abstract classes, +reified generics, and optional typing. + +Types are inferred when possible. The runtime differentiates between two +modes of execution: *checked mode* aimed for development (catching type +errors at runtime) and *production mode* recommended for speed execution +(ignoring types and asserts). + +Example code with types:: + + class Point { + final num x, y; + + Point(this.x, this.y); + + num distanceTo(Point other) { + var dx = x - other.x; + var dy = y - other.y; + return math.sqrt(dx * dx + dy * dy); + } + } + +Hack +---- + +Hack [hack]_ is a programming language that interoperates seamlessly +with PHP. It provides opt-in static type checking, type aliasing, +generics, nullable types, and lambdas. + +Example code with types:: + + alpha(); + } + +TypeScript +---------- + +TypeScript [typescript]_ is a typed superset of JavaScript that adds +interfaces, classes, mixins and modules to the language. + +Type checks are duck typed. Multiple valid function signatures are +specified by supplying overloaded function declarations. Functions and +classes can use generics as type parametrization. Interfaces can have +optional fields. Interfaces can specify array and dictionary types. +Classes can have constructors that implicitly add arguments as fields. +Classes can have static fields. Classes can have private fields. +Classes can have getters/setters for fields (like property). Types are +inferred. + +Example code with types:: + + interface Drivable { + start(): void; + drive(distance: number): boolean; + getPosition(): number; + } + + class Car implements Drivable { + private _isRunning: boolean; + private _distanceFromStart: number; + + constructor() { + this._isRunning = false; + this._distanceFromStart = 0; + } + + public start() { + this._isRunning = true; + } + + public drive(distance: number): boolean { + if (this._isRunning) { + this._distanceFromStart += distance; + return true; + } + return false; + } + + public getPosition(): number { + return this._distanceFromStart; + } + } + + +References +========== + +.. [pep-3107] + http://www.python.org/dev/peps/pep-3107/ + +.. [mypy] + http://mypy-lang.org + +.. [obiwan] + http://pypi.python.org/pypi/obiwan + +.. [numba] + http://numba.pydata.org + +.. [pytypedecl] + https://github.com/google/pytypedecl + +.. [argumentclinic] + https://docs.python.org/3/howto/clinic.html + +.. [numpy] + http://www.numpy.org + +.. [typescript] + http://www.typescriptlang.org + +.. [hack] + http://hacklang.org + +.. [dart] + https://www.dartlang.org + +.. [actionscript] + http://livedocs.adobe.com/specs/actionscript/3/ + +.. [pyflakes] + https://github.com/pyflakes/pyflakes/ + +.. [pylint] + http://www.pylint.org + + +Copyright +========= + +This document has been placed in the public domain. + + + +.. + Local Variables: + mode: indented-text + indent-tabs-mode: nil + sentence-end-double-space: t + fill-column: 70 + coding: utf-8 + End: diff --git a/pep-0483.txt b/pep-0483.txt new file mode 100644 index 000000000..ba66224e5 --- /dev/null +++ b/pep-0483.txt @@ -0,0 +1,28 @@ +PEP: 483 +Title: The Theory of Type Hinting +Version: $Revision$ +Last-Modified: $Date$ +Author: Guido van Rossum +Discussions-To: Python-Ideas +Status: Draft +Type: Informational +Content-Type: text/x-rst +Created: 08-Jan-2015 +Post-History: +Resolution: + +Abstract +======== + +This PEP is currently a stub. The content should be copied from +https://quip.com/r69HA9GhGa7J and reformatted. + + +.. + Local Variables: + mode: indented-text + indent-tabs-mode: nil + sentence-end-double-space: t + fill-column: 70 + coding: utf-8 + End: diff --git a/pep-0484.txt b/pep-0484.txt new file mode 100644 index 000000000..3774d7364 --- /dev/null +++ b/pep-0484.txt @@ -0,0 +1,28 @@ +PEP: 484 +Title: Type Hints +Version: $Revision$ +Last-Modified: $Date$ +Author: Guido van Rossum , Jukka Lehtosalo , Łukasz Langa +Discussions-To: Python-Ideas +Status: Draft +Type: Standards Track +Content-Type: text/x-rst +Created: 08-Jan-2015 +Post-History: +Resolution: + +Abstract +======== + +This PEP is currently a stub. The content should be copied from +https://github.com/ambv/typehinting (but omitting the literature overview, which is PEP 482) and reformatted. + + +.. + Local Variables: + mode: indented-text + indent-tabs-mode: nil + sentence-end-double-space: t + fill-column: 70 + coding: utf-8 + End: