What variable type is returned from Open()?

Chris Angelico rosuav at gmail.com
Wed Apr 15 20:40:38 EDT 2020


On Thu, Apr 16, 2020 at 9:51 AM <dcwhatthe at gmail.com> wrote:
>
> On Wednesday, April 15, 2020 at 5:28:55 PM UTC-4, Random832 wrote:
> > On Wed, Apr 15, 2020, at 12:11, dcwhatthe wrote:
> > > So you're saying this is a type _io.TextIOWrapper?  This type doesn't
> > > show up, on the hint listbox (I'm using Wing IDE).  So if I type
> > > var_file : _io, it doesn't show anything.
> >
> > While others have pointed out that you shouldn't need a type hint here at all since it can be inferred, the correct type hint to use would be typing.TextIO.
>
> Hi Random832,
>
> I understand the advice, and don't want to get into a debate about it.  But I decided years ago, before looking at Python relatively recently, that I want to put as much structural & semantic information in my the code as possible.
>
> The primary reason is artificial intelligence.  When intelligent software is ready to take over programming, I want to leave it as much information as possible.
>

Uhhh..... okay. Let's start right here.

1) Intelligent software ALREADY writes our code for us. We call them
"optimizing compilers" and stuff like that. A person still has to tell
the software what sort of code to write, and the instructions that
specify the required goal are what constitute a high level programming
language.

2) If you really think that it's going to be one of those
Hollywood-style "computer becomes smart enough to program itself"
situations, why do you think it would care about your preexisting
code? It's able to write its own code anyway.

3) Even if it cares about your code, what would the type hints give
it? It's already capable of running the code without the type hints.

Type hints are a tool for YOU, the human. They're not any sort of
assistance to the computer. People periodically talk about using type
hints to improve performance, and it never works.

> So in the case of Python, whenever the type information is available, I want to make it explicit rather than inferred.  Whether the A.I. is running a simulation of the software in an IDE, or analyzing them as text documents, they should be able to glean as much as possible.  They should also be able to infer the type, via a Hungarian syntax variation.
>

Type hints can be explicitly wrong:
x:float = 1
x += 0.5

Type inference can't:
x = 1
x += 0.5

When the AI is running a simulation of your software - which, by the
way, you can already see happen with tools like pythontutor - it can
manage *just fine* with no type hints. In fact, the best thing to do
is ignore them and follow the well-defined semantics of the rest of
Python.

> Yeah, I know it's a minority opinion, and a little kooky.
>

A little misdirected, perhaps. It's like hearing those
"tick-tick-tick" things at pedestrian crossings and thinking that
they're there for the benefit of seeing eye dogs. :)

ChrisA


More information about the Python-list mailing list