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

2023-10-19 Thread Chris Angelico via Python-list
On Thu, 19 Oct 2023 at 19:34, Karsten Hilbert 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 > > >

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

2023-10-19 Thread Karsten Hilbert via Python-list
> > 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:

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

2023-10-19 Thread Chris Angelico via Python-list
On Thu, 19 Oct 2023 at 18:25, Karsten Hilbert wrote: > > > > > Fundamentally no, at least not without some shenanigans. Type hints do > > > > not affect the regular running of the code, > > > > > > Except when they do ;-) > > > > > > ... depending on what counts as (valid) code ... > > > > > > In

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

2023-10-19 Thread Karsten Hilbert via Python-list
> > > Fundamentally no, at least not without some shenanigans. Type hints do > > > not affect the regular running of the code, > > > > Except when they do ;-) > > > > ... depending on what counts as (valid) code ... > > > > In Python a distinction can be made between "runnable" and "valid" :-D > >

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

2023-10-19 Thread Chris Angelico via Python-list
On Thu, 19 Oct 2023 at 18:04, Karsten Hilbert wrote: > > > > or something like that. Basically, any way to avoid writing `= None` over > > > and over again. > > > > Fundamentally no, at least not without some shenanigans. Type hints do > > not affect the regular running of the code, > > Except

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

2023-10-19 Thread Karsten Hilbert via Python-list
> > or something like that. Basically, any way to avoid writing `= None` over > > and over again. > > Fundamentally no, at least not without some shenanigans. Type hints do > not affect the regular running of the code, Except when they do ;-) ... depending on what counts as (valid) code ... In

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

2023-10-18 Thread Chris Angelico via Python-list
On Thu, 19 Oct 2023 at 10:11, Matthew Carruth via Python-list wrote: > > We have the `Optional[T]` type as a short-hand for Union[T | None] and > telling us that said argument may not be present. > > However, I find that a majority of the time, we also want to set a default > value of None on