[Python-Dev] Please reject or postpone PEP 526 (original) (raw)
Steven D'Aprano steve at pearwood.info
Fri Sep 2 14:04:07 EDT 2016
- Previous message (by thread): [Python-Dev] Please reject or postpone PEP 526
- Next message (by thread): [Python-Dev] Please reject or postpone PEP 526
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Sep 02, 2016 at 08:10:24PM +0300, Koos Zevenhoven wrote:
A good checker should be able to infer that x is a union type at the point that it's passed to spam, even without the type annotation. For example:
def eggs(cond:bool): if cond: x = 1 else: x = 1.5 spam(x) # a good type checker infers that x is of type Union[int, float]
Oh I really hope not. I wouldn't call that a good type checker. I would call that a type checker that is overly permissive.
Maybe you think that it's okay because ints and floats are somewhat compatible. But suppose I wrote:
if cond:
x = HTTPServer(*args)
else:
x = 1.5
Would you want the checker to infer Union[HTTPServer, float]? I
wouldn't. I would want the checker to complain that the two branches of
the if
result in different types for x. If I really mean it, then I
can give a type-hint.
In any case, this PEP isn't about specifying when to declare variable types, it is for picking syntax. Do you have a better idea for variable syntax?
-- Steve
- Previous message (by thread): [Python-Dev] Please reject or postpone PEP 526
- Next message (by thread): [Python-Dev] Please reject or postpone PEP 526
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]