0

Colloquially, type hint and annotations are used interchangeably in Python. After reading PEP 484, I was unable to disambiguate the terms "type hint" vs "type annotations" from the text. Are they synonyms? Otherwise, do "type hint" refer to the typing system and "type annotations" refer to the written text itself (e.g., functional annotations)?

2
  • I found this sentence: "Type aliases may be as complex as type hints in annotations" which clearly implies that hints and annotations are two distinct things. Jul 18 at 23:34
  • 1
    Those terms are defined in the next section of the document: peps.python.org/pep-0484/#acceptable-type-hints Type hints may be built-in classes (including those defined in standard library or third-party extension modules), abstract base classes, types available in the types module, and user-defined classes (including those defined in the standard library or third-party modules). (...) Annotations must be valid expressions that evaluate without raising exceptions at the time the function is defined Jul 19 at 6:18

1 Answer 1

2

Type hints is a broader category than type annotations.

While annotations are normally the best format for type hints, there are times when it is more appropriate to represent them by a special comment, or in a separately distributed stub file. (See below for examples.)

It then has short sections describing type comments and stub files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.