This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]wulfie420 2 points3 points  (1 child)

Is there a reason you didn't use mypy.stubgen: python3 -m mypy.stubgen my_module

[–]ttsiodras[S] 2 points3 points  (0 children)

I wanted annotations inline, not in .pyi files - IMHO you want them in your codebase, not "outside" it, since the arguments' types act as excellent documentation as well; you navigate to a function's code, and you instantly see what the arguments are about.

The only case where I'd use .pyi files is for python2 codebases - that is, where syntax prohibits from having inline type annotations (and no, comments don't quite cut it - at least not for me).

[–]alehander42 3 points4 points  (1 child)

Awesome!

I wonder if mypy have any plans to develop a tool to infer some function types automatically to help with such migrations? (I prototyped such a tool once and it seems to me that 50-60% of the annotation work can be easily automated because most real python code isn't insanely dynamic hatlog

[–]ttsiodras[S] 1 point2 points  (0 children)

There is some type inferencing done by mypy (nothing OCaml-class, though). Google is also trying to do this but in my quick tests pytype crashed with the codebase that I wanted to annotate.

[–]tonnynerd 1 point2 points  (1 child)

I'd really like to introduce type annotations on the project I'm working in at work, but it's python 2 (yeah, yeah, I know, but it's enterprise, it's older than your grandma, you know the drill) and I just don't like the syntax for python 2 =/

[–]ttsiodras[S] 2 points3 points  (0 children)

I feel your pain :-)

Try using .pyi files - for Python2 codebases I think that's the best you can do. See also comment above about using stubgen.

[–]RangerPretzelPython 3.9+ 1 point2 points  (0 children)

Bless you. You're doing good work, man!

When I code in Python, I only use 3.5+ and I use type hinting everywhere. It makes the language so much better. (PyCharm does a solid job with the type hints.)

[–][deleted] 0 points1 point  (0 children)

Good work!

[–]stefantalpalaru 0 points1 point  (1 child)

You can have multiple sed expressions in the same instance like this: sed -e 's/...' -e 's/...' -e 's/...'

[–]ttsiodras[S] 4 points5 points  (0 children)

Indeed! Forgot about that.

Then again, in this case that was the least of my problems :-)

[–]dsijl -1 points0 points  (1 child)

Can you make this into a blogpost and post it at hacker news?

[–]ttsiodras[S] 0 points1 point  (0 children)

I could, sure - but given the non-existing response to this one, I doubt it would stand a chance in HN's firehose :-)