(original) (raw)



On Thu, Nov 2, 2017 at 7:39 PM, Jukka Lehtosalo <jlehtosalo@gmail.com> wrote:

As type checking has become the main use case for annotations, using annotations without a type checker is fast becoming a marginal use case. Type checkers can easily and reliably validate that names in annotations aren't misspelled.

Another common use case is dependency injection / IoC:

Examples include:

- Injector (https://github.com/alecthomas/injector):

>>> class Outer:
... @inject
... def \_\_init\_\_(self, inner: Inner):
... self.inner = inner


- Flsk-Injector (ok it's the same underlying injector):

# Route with injection
@app.route("/foo")
def foo(db: sqlite3.Connection):
users = db.execute('SELECT \* FROM users').all()
return render("foo.html")

- Apistar components (https://github.com/encode/apistar#components ):

def say\_hello(user: User):
return {'hello': user.username}

=> In each of the examples, the type annotation are used at runtime by the IoC container to inject an object of the appropriate type, based on some specifications.

They may or may not be used by a typechecker too, but that's secondary.

S.

--
Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier - http://linkedin.com/in/sfermigier
Founder & CEO, Abilian - Enterprise Social Software - http://www.abilian.com/
Chairman, Free&OSS Group / Systematic Cluster - http://www.gt-logiciel-libre.org/
Co-Chairman, National Council for Free & Open Source Software (CNLL) - http://cnll.fr/
Founder & Organiser, PyData Paris - http://pydata.fr/
---
“You never change things by fighting the existing reality. To change something, build a new model that makes the existing model obsolete.” — R. Buckminster Fuller