Domain: mypy-lang.org
Stories and comments across the archive that link to mypy-lang.org.
Comments · 11
-
Re:Questions and observations
Python has longstanding performance issues
Fair enough. It's much slower than even Java, let alone languages like C. (But it can use libraries written in compiled languages like C and Fortran so it can be extremely fast in specific domains.)
that the project governance has declined to address
You say that as if the Python devs are refusing to do something that would be easy. The latest versions of Python are faster and more memory-efficient than earlier versions of Python. The design of the language makes it hard to really optimize so there aren't easy performance gains just waiting for someone to make them.
The fastest Python is PyPy, and that's fast because it has a JIT that compiles your code's hot spots into native code. It isn't that fast until the JIT kicks in.
And the mandatory whitespace is just idiotic, sorry but it is.
You're entitled to your opinion, but please don't give your opinion as if it were a fact. Some people, such as me, like the fact that if code looks like it's part of a block, it actually is part of a block. I don't think that's "just idiotic". You're free to hate it and I won't try to convince you.
Plus scoping is crappy
I have no idea what you are complaining about here.
if you want to do static typing, sorry you just can't.
Actually, you can. Python 3.x supports "type annotations" which let you document the types that various values should be, and there are static checkers that make sure your programs conform to the annotations.
The static checking is not built-in to Python itself, so you could say that Python "enables" static type checking without "providing" it. But to say that "you just can't" do it is a mistake.
By the way, the history of type annotations is IMHO interesting. Guido van Rossum found out that multiple large organizations (Google, Microsoft, etc.) were making their own ad-hoc static type annotations, requiring standardized comments that documented the types. He applied the principle that "there should be one, and preferably only one, obvious way to do it" and added type annotations to the language spec.
The static type checker still works in Python 2.x if you use appropriate comments.
-
Re:Static typeing and APIs
VBA has static typing which Python does not.
(a) Python has strong typing, just dynamic rather than static. Most Python developers would tell you, and I would agree, that you should be testing your code with unit tests and assertions, and catching type errors at runtime is acceptable.
(b) Some Python developers, including the "Benevolent Dictator for Life" Guido van Rossum, feel that Python should have optional static typing, and it is now available. If you think it would help you, you can simply start using it.
Because it's optional, it's not built into the language compiler; it's a separate tool you run. You can automate running the tool if you like.
Python 3 supports "annotations" that are saved with your code; they do nothing by themselves. But a static analysis tool can use those annotations to do a static type check and give you a type error even before you try running your code.
The tool is called "mypy":
P.S. One of the reasons that Guido van Rossum decided Python needed optional static typing is that large companies such as Google and Microsoft were using their own hand-rolled static checking solutions; they would declare functions with special comments and then write checking tools that would parse the special comments. By building the type annotations into the language, Python has standardized on one particular way of doing the annotations. Now IDEs support it and people can share code. As the Zen of Python says: "There should be one, and preferably only one, obvious way to do it."
-
Re:Of course strongly typed reduces bugs
Type hints are not enforced at runtime. You need to use a static type checker like mypy.
I know that.
If this doesn't make sense to you, remember that C++ doesn't check type at runtime either. Static type checking is most useful before you run the program.
I know this too. And it makes sense to me. I am a big fan of static analysis tools of various kinds.
My point (poorly expressed, it seems) was that type hints are not required to be enforced (neither at runtime, nor at compile time) and therefore probably won't be (due to laziness, or other reasons). The fact that you can use some external tool is almost moot.
With C++ you have to work to avoid the type checking, with Python you have to work to enable it. -
Re:Of course strongly typed reduces bugs
Type hints are not enforced at runtime. You need to use a static type checker like mypy.
If this doesn't make sense to you, remember that C++ doesn't check type at runtime either. Static type checking is most useful before you run the program. -
Re:Of course strongly typed reduces bugs
At least the part where you gradually specify the types in your program manually and optionally enforce the types statically can be done in Python today, see mypy.
-
Re:No
Others who agree with you wrote mypy which is basically a lint-style checker for type.
Cool. I'll have to check that out.
However, I think my biases incline me in the opposite direction. Rather than dynamic typing with static type-linting, I prefer strong static typing with ubiquitous type inference. The code ends up looking much the same, I think, but I think the latter is always likely to be more thorough. Plus, it eliminates the need for most run-time typechecking. That's a minor to trivial issue in practice, but I hate systematically wasting cycles.
-
Re:"Native" C# Developer
Note that you two are not discussing the same kind of "type" here, even though they share a word. Dynamic type systems can be regarded as static type systems where all values have a single type. However, Python has been gaining optional static typing capabilities . See mypy, PEP 483, PEP 484 and also the typing and typeshed) modules.
-
Re:No
Others who agree with you wrote mypy which is basically a lint-style checker for type. While I do get the occasional bug when a function supports more than one type - len() on strings and lists, for instance - for the most part the strong typing catches most mistakes, so I don't bother with the added clutter of static typing everything.
-
Re:Python will continue to do fine - it's readable
"Biggest weakness - the lack of compile time checks due to strong but dynamic typing continues to be an Achilles heel for any large project. Python (and other scripting languages) just aren't suited for that and we don't use it for that. Use something with static compile-time checking like C# or C++ - yes, after all my kvetching about readability we still use C++ for some things because nothing else fills its niche."
I had thought the annotated variables and mypy resolved this.
-
mypy static type checker
At least in VB6 you have the _possibility_ of declaring a variable type.
The same is true of mypy, a static type checker for Python.
-
Re:What's the point?
There is currently an enormous discussion going on at python-ideas (see various large threads towards the bottom). Guido himself seems to be in favor of including something like MyPy into Python's standard library, which is allows for optional specification of arguments and return types using function annotation. The main use would be for static/offline code analysis/linting.