13 ms·
The state of type hints in Python
- RcouF1uZ4gsC 8y agoThis article talks about Python getting type hints. There as a HN post recently about Ruby getting a type checker (https://news.ycombinator.com/item?id=17217815 https://news.ycombinator.com/item?id=17217815) I think the debate is largely going in favor of static type checking. The widespread adoption of type inference in many statically typed languages (var in Java, auto in C++, let in Rust) has greatly eased the ergonomics of using a statically typed language. Unless there is a massive ecosystem that you need to take advantage of (for example javascript), in 2018 greenfield development should probably be in a statically typed language.
- brianberns 8y agoI agree, and yet dynamic languages such as Python continue to gain popularity because they are supposedly easier for newbies to pick up. I think we (experienced software developers) have to do a better job of educating newcomers about the dangers of dynamic typing. https://stackoverflow.blog/2017/09/06/incredible-growth-python/ https://stackoverflow.blog/2017/09/06/incredible-growth-pyth...
- swalladge 8y agoAt least it's safer than newbies picking up javascript or php. ;)
- stochastastic 8y agoWhy do you think static languages are easier to pick up? I have had the opposite experience. In managing people who do not aspire to be software developers, but do need to write simple programs to perform basic job functions, I’ve seen much more openness to Python than to more structured alternatives. If you have suggestions that set the bar for working code lower than we can get with Python then I would love to hear them.
- brianberns 8y agoI think Python is perceived as easy to pick up because it's a scripting language, not because it's dynamically typed. I wish I could recommend a statically-typed scripting language that's easy to pick up, but I'm not familiar with any mainstream ones (and I'm probably too far from the newbie stage myself to be a good judge).
- seanp2k2 8y agoThe more TypeScript I write, the less I like Python. In a recent project that involved pulling some data from Hive via Pandas dataframes and merging it with data from a JSON REST API, then doing some calculations and stuffing that data into a different JSON REST API (with a totally different shape to the data), I kept running into little edge cases that Python forces you to handle explicitly vs Javascript just doing what you want. It also annoys me to an irrational degree that Python has "dicts" and not objects, "lists" and not arrays, KeyError everywhere, error looking up dict keys as ints (you can only look them up by str with no implicit type conversion), can't say "dict.keyname", have to do dict['keyname'] or usually dict.get('keyname') and handle things like dicts within dicts where you're not sure if keys exist even more verbosely, etc example of something annoying that came up: foo = [1,2,3] bar = {'1': 1, '2': 2, '3': 3} for i in foo: print(bar.get(i)) What does it output? None x3. In order to get it to do the thing, I did something like this: foo = [1,2,3] bar = {'1': 1, '2': 2, '3': 3} for i in foo: str_i = str(i) # even more fun when this throws print(bar.get(str_i)) I use python because most of my coworkers understand it and it has wide library + runtime support where I work, but it's definitely not my favorite thing to work with. Dynamic typing where types still matter and where the language is picky about implicit type conversions kind of sucks. I also couldn't do: foo = [1,2,3] bar = {'1': 1, '2': 2, '3': 3} for str(i) in foo: print(bar.get(i)) Which was also eyeroll. Like, I get it, but...c'mon. Working with Pandas is also more or less learning another language, with the insanity that is df.T.whatever and df.loc[]: df.loc[df['shield'] > 6, ['max_speed']] I'm sure that someone will comment about how I'm an idiot and there's a much better way to do it, but given PEP20: There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. I guess I'm not Dutch enough.
- xapata 8y ago> I guess I'm not Dutch enough. I could write an "obvious" fix for your example, but I expect that it'd be unsatisfactory, since the real problem likely has a different solution. It looks like you might want a little utility to transform key lookups to a standard. Web frameworks do stuff like that for mapping URLs to functions, to ignore case, etc. You might be interested in learning about the ``dict.__missing__`` magic method.
- int_19h 8y agoIt's not even the dynamic typing that makes Python easy to pick up. It's readable core language, and a well-documented and reasonably thorough standard library that doesn't ignore things that are useful specifically for teaching people (like turtle graphics - I've yet to see a better way to teach loops, recursion etc than getting someone to draw stars and spirals with a turtle).
- jonreem 8y agoFor javascript you can use typescript, which brings the joy of a modern type system to es6 and allows you to migrate file by file.
- swalladge 8y agoSee also flow [1] which does the same and allows you to migrate function by function. :) [1]: https://flow.org/ https://flow.org/
- swalladge 8y agoAgreed. The majority are beginning to realize that strong type systems are actually helpful instead of a mandatory annoyance. Most programming I've done in the past has been with python (no type hinting) or languages with weak static type systems (java et al). Having to verbosely specify the types in java was always just painful, while the upfront speed and freedom of python felt much nicer. However after getting a taste of better type systems by dabbling in rust and elm, now every time I write something in python I'm thinking "was argument a string or a foo class?" or "that runtime error would not have happened if the type checker caught it". Python type hints now are a huge plus for the language. It still seems a bit "hacky" though. I'd love to see something that adds more syntax sugar and feels more built in. Maybe it's just me.
- outworlder 8y agoI would be like to be able to specify types at integration points (module level, function level, etc). Function arguments do benefit from clear inputs and outputs (is this type X? a list of X? A list of anything? Is it returning Y? List of Y? Nothing at all? An error or nothing? Something that is just like X but with an extra field?) Inside the function? Leave me alone. You are a computer, go figure out. Which seems to be the direction we are heading towards. > was argument a string or a foo class Oh, it was supposed to be a string. However, it is a string that came from the UI, so it is untrusted, so your SQL function should refuse to use it. But hey, feel free to lowercase it. The main problem is that usually type systems are not very rich, so the baby gets thrown out with the bathwater. Also, runtime errors are ok if they happen in your test cases. You do have them, right? :)
- swalladge 8y ago> Also, runtime errors are ok if they happen in your test cases. Yes, but if some errors can be caught sooner by your linter/IDE/typechecker then it speeds up development. Would you rather be notified of a type mismatch immediately after saving the file or later when you run the test suite?
- icebraining 8y agoYeah, my only experience with static typing early on was C and Java, and it turned me off the whole thing. I could understand the advantage in C for the whole close-to-the-machine thing, but Java's verbosity and poor expressiveness while allowing NPEs everywhere felt really silly. Idris is what's bringing me back to typed land.
- outworlder 8y ago> Unless there is a massive ecosystem that you need to take advantage of (for example javascript), in 2018 greenfield development should probably be in a statically typed language. I find this sort of generalizations off-putting. It is all about trade offs. Types can be very useful. There are whole categories of errors that are avoided by types. And yet, in many cases they are a productivity drain. Time is often better spend by writing testcases instead of chasing down type issues(more so if a language has a 'generics' or C++ templates concept), so that approach got favored in many fields. These will catch type errors, and static languages also need tests, so the gains are not so easily quantifiable. It is not just a matter of ergonomics, it is a matter of getting out of the way of the problem domain. Most people are paid to solve actual issues, not to craft convoluted C++ templates, custom types or deep type chains. Type inference helps, but even Haskellers will often avoid it when defining functions, so that they will be explicit. But Haskell has incredibly powerful constructs. I was amazed that you can actually tell the compiler you are writing a recursive data structure[1], which is something that most languages won't allow you to do – the most they will allow you is to define a reference to the same type of object(or 'struct'), and you have to stitch that together in runtime. Simple cases are also simple. A function that gets a list and returns an element of that list? [a] -> a, I don't care what a is, nor does the compiler. But feed it something that is not a list, and it will complain. A language should let you easily define new types, and allow these to be used without friction by standard functions. For instance: if I have an integer, is this integer describing a temperature value? If so, functions that work with speed should refuse to operate with this data. Standard mathematical functions _should not care_ and should do whatever operations we request(without any silly type casting, I told the compiler this thing is a number, use it). The compiler optimizer should also use this information to generate appropriate assembly instructions. So yes, if you have an expressive type system, types can be a joy (you'll find yourself thanking the compiler often). If instead your type is spent trying to figure out why IEnumberable<Something> cannot be converted to IEnumerable<SomethingElse>, even though they are subclasses and even though the same operations work with arrays, then types are getting into the way of solving real problems[2][3]. And even with an expressive type system, there is a non trivial cognitive cost. Sometimes you just want to write (map (lambda (x) (do-something x)) lst) and not really care what it is that you are manipulating. On the other hand, I personally do prefer using Golang to talk to AWS apis (instead of python or javascript), precisely because of their deeply nested type hierarchies. Being able to sprinkle type annotations where it is useful and have the compiler figure out as much as possible otherwise is a good compromise, which is the approach that the Python article talks about. I would read this as not favoring mandatory static type checking in 2018 but, instead, using a hybrid mechanism that benefits from both approaches. [1] http://tuttlem.github.io/2013/01/04/recursive-data-structures-in-haskell.html http://tuttlem.github.io/2013/01/04/recursive-data-structure... [2] https://blogs.msdn.microsoft.com/rmbyers/2005/02/17/generic-type-parameter-variance-in-the-clr/ https://blogs.msdn.microsoft.com/rmbyers/2005/02/17/generic-... [3] http://www.baeldung.com/java-type-erasure http://www.baeldung.com/java-type-erasure
- TTPrograms 8y agoThe lesson is rather that optional static typing is useful. The programmer should be able to choose based on what makes sense for the task. Strictly statically typed languages preclude the option of going dynamic.
- logicchains 8y ago>Strictly statically typed languages preclude the option of going dynamic. No they don't; even in C it's possible to just type everything as void*, and everything as Object in Java. Just nobody does this 'cos it introduces a bunch of unnecessary runtime errors.
- yorwba 8y agoTo call a method on a void* or a Java Object you first have to explicitly cast it to a type that has that method, which means that you need to declare a common interface and have each object explicitly implement that interface. Duck typing in dynamic languages doesn't require that level of ceremony.
- emidln 8y agoThis is the lesson I've learned in Clojure. We have varying levels of data shape specification, contracts, and static type checking available a-la-carte when you want it but not getting in your way when you don't.
- atombender 8y agoMy dream back in 2008 or so was a language with smart enough type inference and probably some kind of gradual typing that allowed you to bridge the gap from static and dynamic typing -- dynamic for the prototyping, REPL, quick scripts and very high level code, but as you go down the layers into lower-level, more performance-sensitive code you could add more and more typing and machine-specific hacks. Type inference might got one halfway there, but it would work best at the call site -- the type of variables could be inferred from return values and from literals and so on. But you'd still want to define a function as basically returning "Any". This means a caller wouldn't have a type for the return value, and so if you want to do "fileName := funcReturningAny(); openFile(fileName)" and openFile() was defined only for a string argument, the compiler would have to generate a runtime check at the call site to assert the type fileName as being a strong. This the call site is penalized for being typeless, but the statically typed code wouldn't be. I suspect this would work pretty well. You can start out with no types, and you'd be able to add types as you go, slowly tightening the screws on your program. Generics, traits and other modern abstractions would still be available, though some of those features would start to become unavailable or awkward to use with any code not sufficiently tightened with types. I don't know of any language that does anything like this, although I suppose TypeScript is pretty close.
- url00 8y agoDynamic in C# is pretty much what you describe!
- megaman22 8y agoPretty much nobody does this, but you certainly could. I'm not sure that all that DLR work that was put in gets a ton of real usage, particularly with how C# has grown language features since then.
- annywhey 8y agoBasically have already lived this dream with Haxe. However the cross-platform tooling side of Haxe has historically been the fly in the ointment since it sits above the "real runtime" of whatever you targeted, creating all sorts of bits of friction. And it doesn't cross over into "systems" stuff - it's always within a GC'd environment.
- jlarocco 8y agoOn one hand it's nice that there's a standard way to specify types in Python now, but TBH, if I'm going through the trouble of specifying types then I'm going to use a language that has them built in and fully exploits them. In particular, not using them for performance tuning seems like a big miss.
- hodgesrm 8y agoAgree. At that point it's just better to go back to Java or <insert your favorite statically typed language here>. Java has a broad solution to type safety and a standard doc format for code. Sure there are awkward corner cases around things like type erasure but I find Java for the most part just works.
- welder 8y agoDisagree, performance is a side-effect of type safety... it's main use is to prevent bugs and help devs reading code. Also we use Python for the library ecosystem, easy to read syntax etc. which Java will probably never match. For performance, use Go or Rust and get everything Java has plus an active modern community.
- thermodynthrway 8y agoPerformance and type safety are absolutely linked. The only major reason JS is still 5-10x slower than Java is looseness of types preventing optimizations. The Java community is still vibrant and much larger than Go and Rust put together. Modern stuff like RxJava, Lombok, MapStruct, streams, Guava, Gson, Retrofit, DropWizard, Vert.x, etc... Make Java a breeze these days. The learning curve is just steep. And the Java ecosystem is easily larger than Python. Python may be nearly as popular now, but Java has been in the top three for nearly two decades. A lot of shops use "vanilla Java" out of ignorance without modern libraries and it's crufty as hell. It's similar to shops still using JQuery hacking vs those that have awakened and use React and Typescript, practically a different language
- 8y ago
- abakus 8y agoI use Numpy NDArray and pandas DataFrames a lot, and often times you want to validate the shape / columns / dtype of theses objects. I have yet to find a clean and meaningful way to type hint these, and ended up just put assertions at the beginning of code.
- m_ke 8y agoI linked to some proposals in this issue https://github.com/pytorch/pytorch/issues/4164 https://github.com/pytorch/pytorch/issues/4164
- dimatura 8y agoPyContracts (https://andreacensi.github.io/contracts/ https://andreacensi.github.io/contracts/) supports NumPy arrays.
- zeth___ 8y agoI don't get what's so bad about assertions. It makes it much easier to demand that a given object has a given method than forcing the object to be of a certain class. If anything adding a list of assertions at the top of a method/function/class is much more readable than the current type hint implementation. And if you're running out of resources move the assertions to your regression tests.
- benji-york 8y ago> And if you're running out of resources move the assertions to your regression tests. Or run Python with -O, which skips assertions.
- wnoise 8y ago> It makes it much easier to demand that a given object has a given method than forcing the object to be of a certain class. You know what's even easier? Calling the method. Gives as much useful information in the case of a failure, and also only checks at runtime. I want something that can check earlier than that, in two ways: before running, and up the call stack.
- comesee 8y agoThe point of adding type hinting to Python is to create a smoother path from prototyping to production level code. Contrast with prototyping in Python then rewriting in C++. Soon typed Python code will be automatically transformable to native code. Being able to incrementally evolve a codebase from a prototype to production level quality and performance without wholesale rewrites will revolutionize development practices.
- yorwba 8y ago> Soon typed Python code will be automatically transformable to native code. Do you have a specific project in mind? I know of a few, like Cython, RPython, Nuitka etc. that already do this, but use their own type annotations that are partially incompatible with the Mypy type system. One hurdle to native code generation is that most large Python projects will contain a bit of metaprogramming that the type checker can't handle. That isn't a problem if you can check it by hand and use assertions to signal the type checker that you know what you're doing, but that code will also be impossible to compile. There are some ways to get around that (e.g. RPython allows arbitrary Python during initialization, which is executed at compile time), but they might require a complete rearchitecturing of the program.
- comesee 8y agoI've heard a rumor that the mypy team has an alpha python->c++ compiler working.
- carapace 8y agoYou can write valid useful Python code that flummoxes these type hints. Things like e.g. PySonar exist. Cython exists.
- thosakwe 8y agoI will always wish that Python weren't the lingua franca of sorts for machine learning. For me, it's always frustrating to have to guess the types of parameters in functions without appropriate documentation, especially considering that I don't know much of the language. Combined with the fact that static analyzers for Python can very easily get slow (ex. completions for Tensorflow always take multiple seconds, which IMO is unacceptable), it's just not something that makes the language seem like a reasonable choice to me. I was working on Tensorflow bindings for Dart, which is Java-level statically-typed now, and in porting functions from Python found myself absolutely lost as to what any of the code actually did. I might be the only one who dislikes Python to this degree, though.
- chewxy 8y agoThere's always Go - Gorgonia[0] aims to be a Tensorflow/PyTorch replacement. Performance is somewhat comparable (somewhat because it's always in flux as I keep updating it). Heck, it even uses hindley milner type inferences (not that it's particularly useful)[1] [0] - https://github.com/gorgonia/gorgonia https://github.com/gorgonia/gorgonia [1] - https://github.com/chewxy/hm https://github.com/chewxy/hm
- blt 8y agoI totally agree, it's kind of depressing. With deep learning we had an opportunity to pick a new language because ppl would have used whatever language was necessary to get what tf (& theano) provide. If Google had written tf in Julia, Swift, Nim, etc. our whole world could be different.
- jdonaldson 8y agoNah, I'm with you. Trying to do the same in Haxe. There's not a first class language for typed tensor ops. Type information could include dimensionality, and remove a whole bunch of stupid, time consuming errors.
- LolWolf 8y agoWhat about Julia? It’s what we’ve been teaching our Stanford ML class with and it’s fast! Also typed and JIT with multiple dispatch. Arrays here don’t have the Numpy/Scipy weirdness of matrices vs. ndarrays and linalg is truly first-class. This comes from someone who used to despise the language, but it’s truly come a long way.
- MR4D 8y agoFantastic article - well worth the read! One key takeaway I had is that python is closing in on its own “Perl 6” moment. It seems to me (and this is just my opinion), that I’m adding type hints, the complexity has gone up considerably. (Don’t this about the simple syntax, rather think about all the gotchas and edge cases that are going to cause productivity issues for developers in larger codebases. I really wonder (and have for a while - only now even more so), if Python has gone about it the wrong way. I don’t develop often anymore because it’s no longer my job, but really do love it when I get to spend time on it. And python, for many reasons, is my go to language (sorry for the pun). But now I’m starting to look at Swift and Rust, figuring if I’m going to go thru these headaches, I might as well get a more modern language that runs fast as blazes as a nice side benefit. I’d love some guidance from anyone who’s further down the road with this issue.
- oddity 8y agoI think Swift might be closer to what you want than Rust. I like both, but Rust and Swift are really for two very different groups and solve different problems. Rust is for the C/C++/assembly programmers who would never even think of using Java or Python. Swift is a modern Java. If you're coming from Python, I think Swift is closer to what you want since Rust will probably seem more complex for reasons that don't have benefit for the Python-style use case.
- Longhanks 8y agoThe only thing in which Swift relates to Java is syntax. Apart from that, they couldn't be more different. And if you start digging deeper, you get to see that Swift is a very complex language, too. It's easy to get started, probably easier than Rust, but it has its own kind of quirks.
- akvadrako 8y agoSwift does have a lot of syntax, but it's quite well designed and that contributes to the reference guide being organised in a useful manor. So that complexity is more manageable than C++ or Rust. Once they can remove lots of the ObjC compatibility parts, it should get better too.
- soulnothing 8y agoI started using python type hints when you needed to apply patches. This was years ago. At work we had a database that changed it's schema randomly every night. With type hinting in our build process we were able to determine whether we could handle the new schema. I have also been developing python for about eight years now. I can't really stand the language anymore. It feels to me that unless you have a large python code base, or a large python employee base. It's not just worth the hassle. It was game changing when it first came out. But now,outside of data science, machine learning, and devops I'm not seeing it. With projects like mypy/type hinting, and pypi. You're one step away from using a static language, that is either native or running on a VM (CLR, JVM, BEAM, etc.) Additionally almost all teams I've worked on, have encountered. Either maintainability issues. Where a static type checker would aid. I.E. changing a class or function definition, and not seeing it updated across the board. But more common is performance. Specifically the more asynchronous/parallel work stream. We have asyncio, and others. But it's more complex than some of the static languages. Since type hinting first came on the scene it has been a requisite in any project I've worked on. I've lead a number of teams, who want to move from python. To the tune of we complete each sprint developing the project in python and $LanguageOfChoice. Begging the business to move on, but no dice. Yes I speak in business language why we should move on. But the business won't let us.
- oblio 8y agoPeriods are not commas, your text is hard to follow, like a series of telegrams.
- rs86 8y agoFunny that python is discovering types. All of this is common sense to real developers that can code on haskell.
- sleavey 8y agoType hinting in Python is so ugly that I stripped it all out after a few days of using it on some personal projects. They more than double the length of function signatures and create comment clutter (is this a real comment or some MyPy flag?). I wish there was a way to fully separate the hints into separate files. Such files could act like header files in C. Or, some comment character other than # to start type hint (how about "!"?), so IDEs can hide them if the user wants.
- pjtr 8y agoIsn't that exactly what is possible with "3. Interface stub files"? https://www.bernat.tech/the-state-of-type-hints-in-python/#3interfacestubfiles https://www.bernat.tech/the-state-of-type-hints-in-python/#3...
- sleavey 8y agoThese don't support full separation [1]. Some type hints must be in the main source file. [1] https://stackoverflow.com/questions/47350570/is-it-possible-to-separate-all-type-hinting-checking-infrastructure-in-python https://stackoverflow.com/questions/47350570/is-it-possible-...
- cdancette 8y agoyou can type hint without comments a: int = 1 is valid python
- wozer 8y agoMany great arguments for static typing in this article.
- tyfon 8y ago"One of the main selling points for Python is that it is dynamically-typed." This is actually quite a surprise to me, I am using python despite this as I work as an analyst and many libraries are written for python. I've never seen any advantages of dynamic typing, in fact I tend to avoid languages with it if I can. Are there any valid reasons to have it in a language?
- zimablue 8y agoMost typesystems are limited in what they can express, and as they get more complicated in what they can express they tend to get more complicated to understand. A typesystem is a limitation you place on your code which you accept in the hope that the things which it proves true (problems it avoids) are worth the limitations that you've accepted. You can set everything to Object but the culture that develops around statically typed code tends to mean that people are really afraid to ever do this or be ostracised. From a data moving point of view there's a couple of examples I hit in production where a typesystem isn't helping me => * DataFrames tend to gain/lose columns on every operation, so to represent them in types I'd need a zillion types with code duplication or an interface for each field name. Some operations aren't even possible to type like pivot_table. So tons of my code is really not helped by typing * Everything turns into a DAG of data flows, you can do this with typing but the overhead would mean that noone woudl come up with something like mdf (I don't use mdf in prod but it's impressive for specific applications) If you want a better defense of dynamism google Rich Hickey, a point he made: There's many choices to be made for typesystems, you can have generics/not, higher kinded types, dependent typing. Maybe it's better not to enforce these choices right at the root language level and allow them to happen at a higher level (be plugged in).
- Shoue 8y ago> DataFrames tend to gain/lose columns on every operation, so to represent them in types I'd need a zillion types with code duplication or an interface for each field name. Some operations aren't even possible to type like pivot_table. Couldn't this be done with dependent types?
- hellofunk 8y agoI'm a fan of this multi-language trend of gradual and optional typing. Static typing has definite benefits, but there are also diminishing returns on productivity as a language becomes more and more statically safe. Often times, type safety is a rabbit hole that can easily turn a language into what some call a "puzzle language," where the efforts to please the compiler become non-intuitive and take long times to figure out. Some of the classes in Swift for example have to adopt a hundred protocols just to compile. Rust is an even more extreme example. You might get extra safety, but at significant development cost. Gradual typing in Python is a happy medium that lets the developer decide (to some degree) on the workflow up front. It's a nice compromise for a wide range of work. I love this explanation from a few months ago: https://blog.merovius.de/2017/09/12/diminishing-returns-of-static-typing.html https://blog.merovius.de/2017/09/12/diminishing-returns-of-s...
- aleden 8y agoType annotations more completely describe a program. This can be useful if your code-base's requirements are subject to rapid change (e.g. websites). But when your program is something which has been well thought-out from the start, and thus whose requirements don't change during the course of development, I trust a program which has been statically-typed to not develop bugs over time. case in point: /usr/bin/git
- carlmr 8y ago>Rust is an even more extreme example. You might get extra safety, but at significant development cost. I don't buy this argument. If you want your program to do what you intend you have to know the types anyway. I've never spent significant time on finding the right type, even in Rust. I have spent significant time on incorrect code, because of functions that accepted inputs with the wrong type and didn't complain, because the wrong type had the same method. I have spent significant time on looking up what a function can do, because the IDE can't figure out what my parameter is. I have spent significant time on programs that ran into runtime problems every once in a blue moon that would have been easily detected by a good type system at compile time. Articles like this just show me that every language that needs to have maintainability for large projects will turn into strongly, statically typed at some point. Whether it's type hints or TypeScript.
- bitcraft 8y agoI don’t like the added burden of importing types in order to use them. So far, I’ve relied on pycharm’s excellent static analysis and docstrings to add type hints. One huge pain point that about C++ are header files and maintaining two source files for related code. Python stub files really reduce flexibility when refactoring or building new code. If you are adding types and maintaining two source files, the rapid development advantage of using python is nearly lost, and the type info is hidden while reviewing code, unless you have both files open. Not great for code review when the editor isn’t able to report type conflicts.
- RussBaz 8y agoAs an author of enforce.py, I just want to say that working on and with type hints exhausted me. The inner implementation is so full of corner cases. And the indifferent at best attitude of python subreddit wasn't very helpful either (imho). I still don't know if anyone besides project's awesome contributors ever used it. To be honest, the biggest issue of python type hinting (from my point of view) is that it is an abstraction of a totally different typing system underneath. Type hints do not represent actual types at all. They are just for convenience sake. What started as a proof-of-concept for me, soon became a huge monster with special handlers for almost every single case. It is so messy now, that hardly anyone besides me can do any maintenance. I have been considering a rewrite (using ast modifications to avoid huge number of potential corner cases and performance issues) for more than a year now, but such endeavour is too big for me to undertake. It would be a fresh start after all. End of rant :)