python / python/typing

Tutorial document

Open
#891 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: documentation
Dominant language
Python
Stars
1.8k
Forks
302
Avg merge
23h
Merged PRs (30d)
8

Description

Thoughts on the tutorial document.

Basic Topics

  • Set up a basic venv with a pinned mypy version. (For compatibility reasons.) Should add a note about using a current version in production.
  • Annotating variables.
  • Annotating functions and methods.
  • Unions, using | None
  • Any
  • cast() and # type: ignore
  • Using generics, variance
  • Built-in collections
  • Type aliases
  • int/float
  • NoReturn (not strictly necessary, but a fairly easy topic)
  • Installing third-party stubs

Advanced Topics

The are fairly complicated topics, but basically required when typing a non-trivial code base:

  • Callable
  • Writing generics
  • Protocols
  • type[...]
  • typing.TYPE_CHECKING and circular imports
  • TypeVar and AnyStr
  • overloads
  • Literal

What not to include

  • # type annotations (except # type: ignore)

The following topics could arguably be included, but for simplicity's sake, I'd suggest to skip them in this basic tutorial:

  • NewType
  • ClassVar
  • Final
  • Annotated
  • NamedTuple
  • TypedDict

Other Thoughts

  • We can use a newer version of Python (e.g. 3.8+) for simplicity and add a note that not all features are available in older Python versions.
  • We should probably just use from __future__ import annotations and skip the whole forward references/quoting types problem.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No tutorial file, entry point, or test is named in the issue. Start by locating the existing tutorial documentation and compare it with the proposed basic and advanced topic lists. Done means agreeing on the tutorial scope, Python version guidance, included typing topics, and exclusions, then documenting those decisions.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.