Skip to content

Add 'annotations' to the glossary #76950

Closed

Description

@csabella
BPO 32769
Nosy @gvanrossum, @bitdancer, @ambv, @matrixise, @ilevkivskyi, @csabella, @andresdelfino
PRs
  • bpo-32769: Write annotation entry for glossary #6657
  • [3.7] bpo-32769: Write annotation entry for glossary (GH-6657) #6821
  • bpo-32769: A new take on annotations/type hinting glossary entries #6829
  • [3.7] bpo-32769: A new take on annotations/type hinting glossary entries (GH-6829) #7127
  • [3.6] bpo-32769: A new take on annotations/type hinting glossary entries (GH-6829) #7128
  • bpo-32769: Fix typo spotted by Guido in Annotation glossary entry #7131
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-07-28.13:04:20.536>
    created_at = <Date 2018-02-04.23:13:13.525>
    labels = ['easy', '3.8', 'type-feature', '3.7', 'docs']
    title = "Add 'annotations' to the glossary"
    updated_at = <Date 2018-07-28.13:04:20.535>
    user = 'https://github.com/csabella'

    bugs.python.org fields:

    activity = <Date 2018-07-28.13:04:20.535>
    actor = 'steve.dower'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2018-07-28.13:04:20.536>
    closer = 'steve.dower'
    components = ['Documentation']
    creation = <Date 2018-02-04.23:13:13.525>
    creator = 'cheryl.sabella'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32769
    keywords = ['patch', 'easy']
    message_count = 31.0
    messages = ['311796', '311900', '311904', '311905', '311907', '315953', '316121', '316143', '316146', '316147', '316553', '316557', '316558', '316559', '316562', '316564', '316566', '316568', '316618', '316646', '316648', '316650', '316674', '316705', '316714', '316739', '316751', '316752', '317741', '317746', '317749']
    nosy_count = 8.0
    nosy_names = ['gvanrossum', 'r.david.murray', 'docs@python', 'lukasz.langa', 'matrixise', 'levkivskyi', 'cheryl.sabella', 'adelfino']
    pr_nums = ['6657', '6821', '6829', '7127', '7128', '7131']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue32769'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    Activity

    1. added
      docsDocumentation in the Doc dir
      type-featureA feature request or enhancement
      on Feb 4, 2018
    2. matrixise commented on Feb 7, 2018

      @matrixise
      Member

      There is a description of the annotation in the Glossary, but with 'function annotation'

      maybe we could rename 'function annotation' by 'annotation'

    3. ilevkivskyi commented on Feb 9, 2018

      @ilevkivskyi
      Member

      This is a rather small change, so probably it would be easier to discuss it in a PR.

    4. bitdancer commented on Feb 9, 2018

      @bitdancer
      Member

      PRs are for discussing proposed text/code. Discussion of whether or not to do this belongs here. (I have no opinion on this issue myself.)

    5. ilevkivskyi commented on Feb 9, 2018

      @ilevkivskyi
      Member

      I wanted to say implicitly that I like the idea, and that we should figure out details in a PR. But of course if someone is against this, then we should wait with a PR.

    6. gvanrossum commented on Feb 9, 2018

      @gvanrossum
      Member

      I'm all for adding a bunch of terms related to type hints/annotations to the Glossary.

    7. andresdelfino commented on Apr 30, 2018

      @andresdelfino
      Contributor

      I just made a PR to start working on the right wording.

    8. andresdelfino commented on May 3, 2018

      @andresdelfino
      Contributor

      Guido, now that we are working on this, perhaps you can list what other terms related to type hints/annotations you were thinking for addition.

    9. gvanrossum commented on May 3, 2018

      @gvanrossum
      Member

      Perhaps you can start with the more important terms from PEP-484 (and
      perhaps also PEP-483, and then PEP-526 and PEP-544). E.g. start with terms
      from the ToC of those PEPs.

    10. andresdelfino commented on May 3, 2018

      @andresdelfino
      Contributor

      Great, I'll look into them.

      It will take me some time to make a list of the new terms and write proper descriptions. Perhaps we could deliver the updates to the glossary by waves so people can make benefit of it? As in multiple PR being merged while retaining this issue open until all required terms are added.

    11. gvanrossum commented on May 3, 2018

      @gvanrossum
      Member

      I'm okay with multiple PRs, but do beware that each PR requires a core dev
      to open a browser window etc., so try to group them a bit. But no need to
      wait for the perfect list!

    12. 9 remaining items

    13. ambv commented on May 15, 2018

      @ambv
      Contributor

      Guido, do you really want to stress at this point for Python 3.8 that annotations do not have an intended purpose? That is clearly not true.

      1. PEP-526 was created purely with types in mind and was inspired by PEP-484's lack of this functionality.

      2. PEP-563 defines a future import which will become the default in a future release (currently marked as 4.0). This default stops evaluating annotations at runtime, which again was inspired by the typing use case.

      3. Dataclasses in PEP-557 are designed to leverage types in annotations. A few quotes from that PEP:

      A class decorator is provided which inspects a class definition for variables with type annotations as defined in PEP-526, "Syntax for Variable Annotations".

      One main design goal of Data Classes is to support static type checkers. The use of PEP-526 syntax is one example of this, but so is the design of the fields() function and the @DataClass decorator.

      1. PEP-560 added support for __class_getitem__ and __mro_entries__ in core purely for the purpose of generic types.

      2. For the above reasons, PEP-563 states that non-typing usage of annotations is deprecated:

      https://www.python.org/dev/peps/pep-0563/#non-typing-usage-of-annotations

    14. ilevkivskyi commented on May 15, 2018

      @ilevkivskyi
      Member

      What I think Guido might mean is that some type annotations are not strictly speaking type hints. For example, dataclasses.InitVar, is not really a type, it is just a way to indicate how constructor should be constructed. I could see similar potential features in future (like typing.Final discussed recently). Even typing.ClassVar I would say is not a type but an access qualifier.

      Also for me the two terms: annotations and hints are a bit orthogonal, first is a syntax, while second is semantics. I think Guido is right that we should say something like (approximately) annotation is a syntax to express type hints and other related metadata or similar. The current formulation seems a bit too restrictive.

    15. gvanrossum commented on May 15, 2018

      @gvanrossum
      Member

      I actually intended to say that annotations continue to be usable for
      non-typing purposes (beyond ClassVar/InitVar). It may be deprecated but the
      usage still exists. This is a glossary, not a manifesto.

      I'm fine with adding that the main use of annotations is for type hints of
      course. And I was mostly reacting to the fact that the text that was just
      committed seemed to imply that 'annotation' refers to something stored at
      runtime in __annotations__ while 'type hint' was a syntactic form (and this
      is borne out by the omission of *local* type hints from the section on
      annotations).

    16. ilevkivskyi commented on May 15, 2018

      @ilevkivskyi
      Member

      Yes, local annotations are important and should be mentioned (maybe even with an example).

    17. andresdelfino commented on May 15, 2018

      @andresdelfino
      Contributor

      Hopefully I address your comments with the last PR update.

    18. ambv commented on May 15, 2018

      @ambv
      Contributor

      It may be deprecated but the usage still exists. This is a glossary, not a manifesto.

      Agreed. However, based on the current wording users will argue that Python documentation itself is stressing the lack of an intended purpose for annotations, equaling the typing use case with all other use cases (including future ones). This isn't our intent.

      I think it would be clearer to change the current wording from:

      A metadata value associated with a variable, a class attribute or a
      function or method parameter or return value, that has no specific
      purpouse (i.e. it's up to the user to use it as they see fit).
      (...)
      Annotations can be used to specify :term:`type hints <type hint>`.

      to:

      A metadata value associated with a variable, a class attribute or a
      function or method parameter or return value, that stores a
      :term:`type hint`.
      (...)
      Annotations can be used for other purposes unrelated to typing. This
      usage is deprecated, see :pep:`563` for details.

      The type hint phrasing is already there, we just need to delete the word "global" that currently appears before "variable". Note that saying that annotations in class attributes and variables have no assigned meaning contradicts PEP-526.

    19. gvanrossum commented on May 15, 2018

      @gvanrossum
      Member

      Your phrasing still makes it sound like an annotation is a runtime concept
      -- I think of it as a syntactic construct. (Otherwise fine.)

    20. andresdelfino commented on May 15, 2018

      @andresdelfino
      Contributor

      Guido, could you point out what parts make it sound that way to you so I can change them?

    21. gvanrossum commented on May 16, 2018

      @gvanrossum
      Member

      (1) The word "stores" in this paragraph:

      A metadata value associated with a global variable, a class attribute or a
      function or method parameter or return value, that stores a type hint.

      (2) The description of how annotations are stored in __annotations__ in the
      following paragraph.

      (3) The omission of local variables from the lists of things in those
      paragraphs that can be annotated (those are the only category whose
      annotation is not stored at runtime).

    22. andresdelfino commented on May 16, 2018

      @andresdelfino
      Contributor

      I'm sorry, because of your comment, I believe you haven't read the last update on the PR. Could you take a look at it?

      #6829

    23. ilevkivskyi commented on May 26, 2018

      @ilevkivskyi
      Member

      New changeset 6e33f81 by Ivan Levkivskyi (Andrés Delfino) in branch 'master':
      bpo-32769: A new take on annotations/type hinting glossary entries (GH-6829)
      6e33f81

    24. gvanrossum commented on May 26, 2018

      @gvanrossum
      Member

      New changeset e69657d by Guido van Rossum (Andrés Delfino) in branch '3.7':
      [3.7] bpo-32769: A new take on annotations/type hinting glossary entries (GH-6829) (bpo-7127)
      e69657d

    25. ilevkivskyi commented on May 26, 2018

      @ilevkivskyi
      Member

      New changeset 717204f by Ivan Levkivskyi (Andrés Delfino) in branch '3.6':
      [3.6] bpo-32769: A new take on annotations/type hinting glossary entries (GH-6829) (GH-7128)
      717204f

    26. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of life3.8 (EOL)end of lifedocsDocumentation in the Doc direasytype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions