News for hackers. Stuff that matters.
Re:Python’s “type hints” are a bit of a disappointment to me by rwmj on Friday April 22, 2022 @11:29AM (#31122831)
I was actually looking at urllib3 yesterday trying to work out the return value from HTTPConnection.connect which calls this _new_conn function internally:

    def _new_conn(self):
        """Establish a socket connection and set nodelay settings on it.

        :return: New socket connection.
        """
  ...
        try:
            conn = connection.create_connection(
                (self._dns_host, self.port), self.timeout, **extra_kw
            )
  ...
        return conn
(I've chopped it down a bit to emphasise the important bits)

What's the type of "conn"? It certainly wasn't clear to me that it's a socket.

But just now I looked at upstream and I notice they've added type annotations, which do greatly improve things:

https://github.com/urllib3/urllib3/blob/e16beb210c03c6f5ce4e...

    def _new_conn(self) -> socket.socket:
  ...
So a small victory for type annotations there.
Re:Python’s “type hints” are a bit of a disappointment to me by CraigJPerry on Friday April 22, 2022 @04:13PM (#31127443)
When i hover over connection.create_connection i get a docstring that says it returns a socket.

That docstring isn’t enough for the problem you had though, e.g. I wasn’t clear from that if they meant a socket.socket or maybe some special socket derivative type so i hit go to definition and create_connection is a short method - i can see it is indeed a socket.socket being created, configured and returned.

I’m guessing you’re not using any developer tooling, maybe a straight text editor i guess?

This kind of tooling has been around for a long time, i remember using rope and jedi in vim back around the late 2000’s i think. It’s gotten a LOT better since PyCharm appeared mid 2010’s i think - first i recall using it must have been around 2014-ish. These days, it’s even better. I would really strongly encourage adopting some kind of tooling that lets you navigate and has some basic refactoring - rename is usually 80%+ of the value there so it doesn’t need to be complex. A few ergonomics like having the ability to jump to test and call from repl with a keystroke - you’ll turbo charge your comfort and productivity.

That has to be our difference i think because it took one mouse move and one key chord to completely bottom out.