Any possible type alias that can also set a default value for a function arg?

Chris Angelico rosuav at gmail.com
Thu Oct 19 05:02:08 EDT 2023


On Thu, 19 Oct 2023 at 19:34, Karsten Hilbert <Karsten.Hilbert at gmx.net> wrote:
>
> > > As per my recent foray into abusing existence-checking for Singleton assurance
> > > along such lines as
> > >
> > > >>> try: self.initialized
> > > >>> except AttributeError: print('first instantiation'); self.initialized = True
> > >
> > > and then changing that to
> > >
> > > >>> try: self.initialized:bool
> >
> > But that's not equivalent code.
>
> I learned as much (RHS vs LHS).
>
> But it did not _intuitively_ resonate with the sentiment
> "type annotation does not change the running of code".

Unfortunately, that simply means that your intuition was wrong. It
doesn't change my prior statement.

ChrisA


More information about the Python-list mailing list