Thanks to visit codestin.com
Credit goes to github.com

Skip to content

📝 Simplify intro to Python Types, all currently supported Python versions include type hints 🎉#2085

Merged
tiangolo merged 2 commits into
fastapi:masterfrom
ninjaaron:patch-1
Nov 5, 2020
Merged

📝 Simplify intro to Python Types, all currently supported Python versions include type hints 🎉#2085
tiangolo merged 2 commits into
fastapi:masterfrom
ninjaaron:patch-1

Conversation

@ninjaaron

Copy link
Copy Markdown
Contributor

Function annotation syntax was proposed in pep 3107 in 2006 and was a feature of Python 3.0. Type annotations were already a proposed usecase at this time. Mypy supports Python 3.2 and newer. A standard vocabulary for type hints (and the typing module itself) based on conventions used in Mypy and other sources was added in 3.5 with pep 484.

The only thing new for type hints in 3.6 is variable annotations, which allows types to be specified outside of function signatures. pep 526

Function annotation syntax was proposed in [pep 3107](https://www.python.org/dev/peps/pep-3107/) in 2006 and was a feature of Python 3.0. Type annotations were already a proposed usecase at this time. Mypy supports Python 3.2 and newer. A standard vocabulary for type hints (and the typing module itself) based on conventions used in Mypy and other sources was added in 3.5 with [pep 484](https://www.python.org/dev/peps/pep-0484/).

The only thing new for type hints in 3.6 is _variable annotations_, which allows types to be specified outside of function signatures. [pep 526](https://www.python.org/dev/peps/pep-0526/)
@codecov

codecov Bot commented Sep 23, 2020

Copy link
Copy Markdown

Codecov Report

Merging #2085 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #2085   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          239       239           
  Lines         7079      7079           
=========================================
  Hits          7079      7079           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e77ea63...a9589a0. Read the comment docs.

@github-actions

Copy link
Copy Markdown
Contributor

📝 Docs preview for commit 0f205e8 at: https://5f6b11a64e63eafd3e61ad2e--fastapi.netlify.app

@ArcLightSlavik

Copy link
Copy Markdown
Contributor

I think this proposal is technically correct but I find some drawbacks.

  1. Typing module was provisional in 3.5. It become stable in either 3.6.4 or 3.7.
  2. Pydantic uses 3.6 in it's documentation and it has way more weight in on types.
  3. Some people might read it as 'fastapi can run on python 3.5' which might be possible but is not suggested at all.

@ninjaaron

Copy link
Copy Markdown
Contributor Author

Is it possible to rephrase this in such a way that it is both technically correct and doesn't give people the wrong idea? (a possible option would be to omit details about when type annotations were introduced altogether)

@ArcLightSlavik

Copy link
Copy Markdown
Contributor

Considering 3.5 reached end of life this month, completely removing the version sounds the best.

@github-actions

Copy link
Copy Markdown
Contributor

📝 Docs preview for commit a9589a0 at: https://5f6ce1c73b57e61ca550f17c--fastapi.netlify.app

@tiangolo tiangolo changed the title function annotation syntax was introduced in 3.0 📝 Simplify intro to Python Types, all currently supported Python versions include type hints 🎉 Nov 5, 2020
@tiangolo tiangolo merged commit 13d9de4 into fastapi:master Nov 5, 2020
@tiangolo

tiangolo commented Nov 5, 2020

Copy link
Copy Markdown
Member

Awesome, thanks! It's so nice that type hints are now "mainstream" and standard in all the Python versions supported! 🎉

Thanks for your contribution! 🚀 🎉

And thanks @ArcLightSlavik for those points ✔️ 🔍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants