This PEP is one of three related to type hinting. This PEP gives aliterature overview of related work. The main spec isPEP 484.
(This section is a stub, sincemypy is essentially what we’reproposing.)
Reticulated Python by Michael Vitousek is an example ofa slightly different approach to gradual typing for Python. It isdescribed in an actualacademic paper written byVitousek with Jeremy Siek and Jim Baker (the latter of Jython fame).
PyCharm by JetBrains has been providing a way to specify and checktypes for about four years. The type system suggested byPyCharmgrew from simple class types to tuple types, generic types,function types, etc. based on feedback of many users who shared theirexperience of using type hints in their code.
TBD: Add sections onpyflakes,pylint,numpy,Argument Clinic,pytypedecl,numba,obiwan.
ActionScript is a class-based, single inheritance,object-oriented superset of ECMAScript. It supports interfaces andstrong runtime-checked static typing. Compilation supports a “strictdialect” where type mismatches are reported at compile-time.
Example code with types:
package{importflash.events.Event;publicclassBounceEventextendsEvent{publicstaticconstBOUNCE:String="bounce";privatevar_side:String="none";publicfunctiongetside():String{return_side;}publicfunctionBounceEvent(type:String,side:String){super(type,true);_side=side;}publicoverridefunctionclone():Event{returnnewBounceEvent(type,_side);}}}
Dart is a class-based, single inheritance, object-orientedlanguage with C-style syntax. It supports interfaces, abstract classes,reified generics, and optional typing.
Types are inferred when possible. The runtime differentiates between twomodes of execution:checked mode aimed for development (catching typeerrors at runtime) andproduction mode recommended for speed execution(ignoring types and asserts).
Example code with types:
classPoint{finalnumx,y;Point(this.x,this.y);numdistanceTo(Pointother){vardx=x-other.x;vardy=y-other.y;returnmath.sqrt(dx*dx+dy*dy);}}
Hack is a programming language that interoperates seamlesslywith PHP. It provides opt-in static type checking, type aliasing,generics, nullable types, and lambdas.
Example code with types:
<?hhclass MyClass { private ?string $x = null; public function alpha(): int { return 1; } public function beta(): string { return 'hi test'; }}function f(MyClass $my_inst): string { // Will generate a hh_client error return $my_inst->alpha();}TypeScript is a typed superset of JavaScript that addsinterfaces, classes, mixins and modules to the language.
Type checks are duck typed. Multiple valid function signatures arespecified by supplying overloaded function declarations. Functions andclasses can use generics as type parameterization. Interfaces can haveoptional 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 areinferred.
Example code with types:
interfaceDrivable{start():void;drive(distance:number):boolean;getPosition():number;}classCarimplementsDrivable{private_isRunning:boolean;private_distanceFromStart:number;constructor(){this._isRunning=false;this._distanceFromStart=0;}publicstart(){this._isRunning=true;}publicdrive(distance:number):boolean{if(this._isRunning){this._distanceFromStart+=distance;returntrue;}returnfalse;}publicgetPosition():number{returnthis._distanceFromStart;}}
This document has been placed in the public domain.
Source:https://github.com/python/peps/blob/main/peps/pep-0482.rst
Last modified:2025-02-01 08:59:27 GMT