[Python-Dev] Confusing naming of Optional type should be changed

2022-06-30 Thread nverich07
I am aware this is clarified in the Python documentation for the typing module 
but I and others have thought the naming of Optional is still quite confusing 
by itself. 

"Note that this is not the same concept as an optional argument, which is one 
that has a default. An optional argument with a default does not require the 
Optional qualifier on its type annotation just because it is optional." - 
typing.Optional docs

Google defines optional as this, "available to be chosen but not obligatory."

Pretend we have a function like this:
def test_func(param: Optional[str]) -> None:
...

The argument param is typed as Optional[str] meaning Union[str, None] or str | 
None. Optional here if we follow the definition above, basically means it can 
be str but not required or obligated to be that type. See the problem with the 
naming? This is a function where param can be None or str, not just it can be 
str but not obligated. Some interpretations may think optional means left to 
one's choice as well. The docs even have to clarify the use of Optional with 
typing because of this confusion. 

I believe this has been proposed before (not sure) but something like Nullable 
or Noneable (not sure about naming) would make much more sense in the context 
of typing. 
def test_func(param: Noneable[str]) -> None:
...

It also would work and still make sense if there is a default value for the 
argument:
def test_func(param: Noneable[str] = None) -> None:
...

def test_func(param: Noneable[str] = "hello world") -> None:
...
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/QT7RJSDMWKTGB6PNVMGZ2NY2D4PT75Y7/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Confusing naming of Optional type should be changed

2022-06-30 Thread Paul Bryan
Given that it's now presumably preferred spelling is `str | None` in
Python 3.10, why would we not seek to deprecate `Optional[str]` instead
of inventing a replacement?

On Thu, 2022-06-30 at 17:15 +, nveric...@gmail.com wrote:
> I am aware this is clarified in the Python documentation for the
> typing module but I and others have thought the naming of Optional is
> still quite confusing by itself. 
> 
> "Note that this is not the same concept as an optional argument,
> which is one that has a default. An optional argument with a default
> does not require the Optional qualifier on its type annotation just
> because it is optional." - typing.Optional docs
> 
> Google defines optional as this, "available to be chosen but not
> obligatory."
> 
> Pretend we have a function like this:
> def test_func(param: Optional[str]) -> None:
>     ...
> 
> The argument param is typed as Optional[str] meaning Union[str, None]
> or str | None. Optional here if we follow the definition above,
> basically means it can be str but not required or obligated to be
> that type. See the problem with the naming? This is a function where
> param can be None or str, not just it can be str but not obligated.
> Some interpretations may think optional means left to one's choice as
> well. The docs even have to clarify the use of Optional with typing
> because of this confusion. 
> 
> I believe this has been proposed before (not sure) but something like
> Nullable or Noneable (not sure about naming) would make much more
> sense in the context of typing. 
> def test_func(param: Noneable[str]) -> None:
>     ...
> 
> It also would work and still make sense if there is a default value
> for the argument:
> def test_func(param: Noneable[str] = None) -> None:
>     ...
> 
> def test_func(param: Noneable[str] = "hello world") -> None:
>     ...
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/QT7RJSDMWKTGB6PNVMGZ2NY2D4PT75Y7/
> Code of Conduct: http://python.org/psf/codeofconduct/

___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/CQQ6O4HBDA46ASYEG2M7BF3ZE26KSB5N/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Confusing naming of Optional type should be changed

2022-06-30 Thread nverich07
Ah, to be honest, I completely forgot about deprecation for some reason :) 
Yes, that would definitely be a much better idea to phase out Optional and 
probably Union in the future actually. Thanks for bringing it up!
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/OGHCYNZ7UFE4FOCEUTZTTA43KRJU6CGA/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Structural pattern matching and mangling private names

2022-06-30 Thread Guido van Rossum
If you want any kind of traction on this I recommend filing an opinionated
issue on this (explaining why the current behavior is wrong).

On Wed, Jun 15, 2022 at 1:25 PM  wrote:

> Daniel Moisset wrote:
> > I might expect that in a "case D(something=__y)" you get the mangling for
> > __y, but I'm not sure what the implementation does now and I'm writing
> from
> > my phone
>
> Yes - that case does what you'd expect.
>
> Thanks for the reply.
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/3BALIBTV3ATAEC6G5ZJKAFBASZG4B5AP/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*

___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/BX2QX3GUOGMBL5TGSSN7EQFJQHA6UQJM/
Code of Conduct: http://python.org/psf/codeofconduct/