El jue, 11 feb 2021 a las 7:47, David Foster (<davidfstr@gmail.com>) escribió:
On 2/5/21 2:16 AM, Ran Benita via Typing-sig wrote:
 >      >      class C:
 >      >          def __init__(self, set_it: bool) -> None:
 >      >              if set_it:
 >      >                  self.attr = 10

On Sun, Feb 7, 2021 at 22:44 David Foster <davidfstr@gmail.com
 >     I believe mypy currently represents the type of `C.attr` in the above
 >     example as `int*` (vice `int`) which means "if it's defined then
 >     it's an
 >     `int`". I don't think this interpretation is standardized by any PEP
 >     I've read though. In particular not the original PEP 484 ("Type
Hints").

On 2/8/21 7:28 AM, Guido van Rossum wrote:
 > I don’t think that’s what the star in mypy,means. IIRC it has something
 > to do with whether it is an inferred type.

Ah. Then I stand corrected. I've only ever noticed the `SomeType*` form
in mypy for this specific scenario, so I made an assumption on its meaning.

I opened https://github.com/python/mypy/issues/10076 to propose removing this mypy feature since as far as I can tell it's only ever been confusing. 

Best,
--
David Foster | Seattle, WA, USA
Contributor to TypedDict support for mypy

On 2/8/21 7:28 AM, Guido van Rossum wrote:
> I don’t think that’s what the star in mypy,means. IIRC it has something
> to do with whether it is an inferred type.
>
> On Sun, Feb 7, 2021 at 22:44 David Foster <davidfstr@gmail.com
> <mailto:davidfstr@gmail.com>> wrote:
>
>     On 2/5/21 2:16 AM, Ran Benita via Typing-sig wrote:
>      > Hi David,
>      >
>      > First, I agree with Tukka that the `| Missing` (special vlaue)
>     proposal should be discussed in the "Rejected Ideas" section, as
>     it's one of the first alternatives that come to mind.
>      >
>      > I would also mention that a similar situation also can occur in
>     regular classes (unlike, say, in Java) which currently cannot be
>     represented with Python typing:
>      >
>      >      class C:
>      >          def __init__(self, set_it: bool) -> None:
>      >              if set_it:
>      >                  self.attr = 10
>      >
>      >      C(set_it=False).attr  # type checks with mypy, but crashes
>      >
>      > While this is bad code IMO, it does occur quite often in the wild
>     (especially in pre-typing code). If there is ever a Python checker
>     that aims for soundness, it would either have to reject this code
>     (like Java etc. do, "possibly uninitialized variable") or it would
>     need to represent it in the type system. And if it is to be
>     represented in the type system, a `Required[..]` wouldn't work well,
>     due to backward compatibility and obviously being the wrong default
>     in terms of boilerplate.
>
>     I believe mypy currently represents the type of `C.attr` in the above
>     example as `int*` (vice `int`) which means "if it's defined then
>     it's an
>     `int`". I don't think this interpretation is standardized by any PEP
>     I've read though. In particular not the original PEP 484 ("Type Hints").
>
>     --
>     David Foster | Seattle, WA, USA
>     Contributor to TypedDict support for mypy
>     _______________________________________________
>     Typing-sig mailing list -- typing-sig@python.org
>     <mailto:typing-sig@python.org>
>     To unsubscribe send an email to typing-sig-leave@python.org
>     <mailto:typing-sig-leave@python.org>
>     https://mail.python.org/mailman3/lists/typing-sig.python.org/
>     <https://mail.python.org/mailman3/lists/typing-sig.python.org/>
>     Member address: guido@python.org <mailto:guido@python.org>
>
> --
> --Guido (mobile)
_______________________________________________
Typing-sig mailing list -- typing-sig@python.org
To unsubscribe send an email to typing-sig-leave@python.org
https://mail.python.org/mailman3/lists/typing-sig.python.org/
Member address: jelle.zijlstra@gmail.com