[Python-Dev] What's missing in PEP-484 (Type hints) (original) (raw)
Florian Bruhin me at the-compiler.org
Thu Apr 30 13:54:11 CEST 2015
- Previous message (by thread): [Python-Dev] What's missing in PEP-484 (Type hints)
- Next message (by thread): [Python-Dev] What's missing in PEP-484 (Type hints)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
- Dima Tisnek <dimaqq at gmail.com> [2015-04-30 13:41:53 +0200]:
# lambda Not mentioned in the PEP, omitted for convenience or is there a rationale? f = lambda x: None if x is None else str(x ** 2) Current syntax seems to preclude annotation of
x
due to colon. Current syntax sort of allows lamba return type annotation, but it's easy to confuse withf
.
Not sure if you'd really want to stuff type annotations into a lambda... at that point you'd IMHO be better off by using a real function.
# local variables Not mentioned in the PEP Non-trivial code could really use these.
# global variables Not mentioned in the PEP Module-level globals are part of API, annotation is welcome. What is the syntax? # comprehensions [3 * x.data for x in foo if "bar" in x.type] Arguable, perhaps annotation is only needed on
foo
here, but then how complex comprehensions, e.g. below, the intermediate comprehension could use an annotation [xx foj y in [...] if ...] # class attributes s = socket.socket(...) s.type, s.family, s.proto # int s.fileno # callable If annotations are only available for methods, it will lead to Java-style explicit getters and setters. Python language and data model prefers properties instead, thus annotations are needed on attributes. # plain data user1 = dict(id=123, # always int name="uuu", # always str ...) # other fields possible smth = [42, "xx", ...] (why not namedtuple? b/c extensible, mutable) At least one PHP IDE allows to annotate PDO. Perhaps it's just bad taste in Python? Or is there a valid use-case?
Most (all?) of this is actually mentioned in the PEP: https://www.python.org/dev/peps/pep-0484/#type-comments
Florian
-- http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP) GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc I love long mails! | http://email.is-not-s.ms/ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-dev/attachments/20150430/45ef86c4/attachment.sig>
- Previous message (by thread): [Python-Dev] What's missing in PEP-484 (Type hints)
- Next message (by thread): [Python-Dev] What's missing in PEP-484 (Type hints)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]