Can Python work like this:
If there are type annotations found in python code, type inference takes effect.
If there is not type annotation, old style dynamic type takes effect.
In type inference python code, the compiler knows variable or function types and does optimization for the code at compile time.
# example 1: parameter annotation
def f1(num: int):
# example 2: return annotation
def f2(num) -> bool:
# example 3: variable annotation
animal: str = 'snake'
var animal2: str = 'elephant' # new keyword var like Swift's
@ljh. I think, you should change the post-tag as IDEAS to get some feedback and comments about your idea.
Yup, just like
@sandraC said, your topic fits better to the # category, so it can be considered as a proposal to the Python language, and you can get better feedbacks ideas
I was going to change the category to ideas, but this was already mostly addressed in
@ljh 's other thread:
Can Mypy run the scripts after they have been checked? I do not know a better way to use Mypy, so I call Mypy and python3 separately to check and run the scripts.
Mypy re-checks scripts which have been checked already. Can makefile be applied to avoid the re-checks?
Is there a way for CPython to know that a script has been checked by Mypy? Can CPython utilize the static typing info provided by Mypy and compile scripts statically and speedup running scripts finally?
In my te…
and the core devs and typing people have been very clear that making the core Python language statically rather than dynamically typed is not realistically going to happen anytime soon, and there are many great existing tools to do this already with Python code, e.g. Cython and mypyc.