Aug SEP Oct
27
2023 2024 2025
success
fail

About this capture

COLLECTED BY

Collection: Save Page Now Outlinks

TIMESTAMPS

The Wayback Machine - http://web.archive.org/web/20240927103612/https://github.com/python/mypy
 

Skip to content  

Navigation Menu

 






Sign in  











Actions
 Automate any workflow  



Packages
 Host and manage packages  



Security
 Find and fix vulnerabilities  



Codespaces
 Instant dev environments  



GitHub Copilot
 Write better code with AI  



Code review
 Manage code changes  



Issues
 Plan and track work  



Discussions
 Collaborate outside of code  



Explore  

All features  

Documentation  

GitHub Skills  

Blog  







By size  

Enterprise  

Teams  

Startups  



By industry  

Healthcare  

Financial services  

Manufacturing  



By use case  

CI/CD & Automation  

DevOps  

DevSecOps  







Topics  

AI

DevOps  

Security  

Software Development  

View all  



Explore  

Learning Pathways  

White papers, Ebooks, Webinars  

Customer Stories  

Partners  











GitHub Sponsors
 Fund open source developers  







The ReadME Project
 GitHub community articles  



Repositories  

Topics  

Trending  

Collections  











Enterprise platform
 AI-powered developer platform  



Available add-ons  



Advanced Security
 Enterprise-grade security features  



GitHub Copilot
 Enterprise-grade AI features  



Premium Support
 Enterprise-grade 24/7 support  





Pricing
 



Search or jump to...  

Search code, repositories, users, issues, pull requests...




Clear

Search syntax tips  










Provide feedback  







We read every piece of feedback, and take your input very seriously.


 
 


Saved searches  

Use saved searches to filter your results more quickly

 






To see all available qualifiers, see our documentation.






 
 

Sign in  
/;ref_cta:Sign up;ref_loc:header logged out"}">  Sign up    




You signed in with another tab or window. Reload to refresh your session.  You signed out in another tab or window. Reload to refresh your session.  You switched accounts on another tab or window. Reload to refresh your session.  Dismiss alert  







{{ message }}
 








/   mypy   Public  





Notifications  You must be signed in to change notification settings  

Fork  2.8k  


Star  18.3k
 






Optional static typing for Python  

www.mypy-lang.org/  

License


View license  

18.3k  stars   2.8k  forks   Branches   Tags   Activity  



Star
 

Notifications  You must be signed in to change notification settings  




Code  

Issues  2.7k  

Pull requests  251  

Actions  

Projects    

Wiki  

Security  

Insights  


Additional navigation options  




Code  

Issues  

Pull requests  

Actions  

Projects  

Wiki  

Security  

Insights  




python/mypy






This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
 





 master
BranchesTags


Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11,998 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


README
Code of conduct
License
Security

mypy logo

Mypy: Static Typing for Python


Stable VersionDownloadsBuild StatusDocumentation StatusChat at https://gitter.im/python/typingChecked with mypyCode style: blackLinting: Ruff

Got a question?


We are always happy to answer questions! Here are some good places to ask them:


for anything you're curious about, try gitter chat

for general questions about Python typing, try typing discussions


If you're just getting started, the documentation and type hints cheat sheet can also help answer questions.

If you think you've found a bug:


check our common issues page

search our issue tracker to see if it's already been reported

consider asking on gitter chat


To report a bug or request an enhancement:


report at our issue tracker

if the issue is with a specific library or function, consider reporting it at typeshed tracker or the issue tracker for that library


To discuss a new type system feature:


discuss at discuss.python.org

there is also some historical discussion at the typing-sig mailing list and the python/typing repo


What is mypy?


Mypy is a static type checker for Python.

Type checkers help ensure that you're using variables and functions in your code correctly. With mypy, add type hints (PEP 484) to your Python programs, and mypy will warn you when you use those types incorrectly.

Python is a dynamic language, so usually you'll only see errors in your code when you attempt to run it. Mypy is a static checker, so it finds bugs in your programs without even running them!

Here is a small example to whet your appetite:

number = input("What is your favourite number?")
print("It is", number + 1)  # error: Unsupported operand types for + ("str" and "int")


Adding type hints for mypy does not interfere with the way your program would otherwise run. Think of type hints as similar to comments! You can always use the Python interpreter to run your code, even if mypy reports errors.

Mypy is designed with gradual typing in mind. This means you can add type hints to your code base slowly and that you can always fall back to dynamic typing when static typing is not convenient.

Mypy has a powerful and easy-to-use type system, supporting features such as type inference, generics, callable types, tuple types, union types, structural subtyping and more. Using mypy will make your programs easier to understand, debug, and maintain.

See the documentation for more examples and information.

In particular, see:


type hints cheat sheet

getting started

list of error codes


Quick start


Mypy can be installed using pip:

python3 -m pip install -U mypy


If you want to run the latest version of the code, you can install from the repo directly:

python3 -m pip install -U git+https://github.com/python/mypy.git
# or if you don't have 'git' installed
python3 -m pip install -U https://github.com/python/mypy/zipball/master


Now you can type-check the statically typed parts of a program like this:

mypy PROGRAM


You can always use the Python interpreter to run your statically typed programs, even if mypy reports type errors:

python3 PROGRAM


You can also try mypy in an online playground (developed by Yusuke Miyazaki). If you are working with large code bases, you can run mypy in daemon mode, that will give much faster (often sub-second) incremental updates:

dmypy run -- PROGRAM


Integrations


Mypy can be integrated into popular IDEs:


Vim:

Using Syntastic: in ~/.vimrc add let g:syntastic_python_checkers=['mypy']

Using ALE: should be enabled by default when mypy is installed, or can be explicitly enabled by adding let b:ale_linters = ['mypy']in~/vim/ftplugin/python.vim



Emacs: using Flycheck

Sublime Text: SublimeLinter-contrib-mypy

Atom: linter-mypy

PyCharm: mypy plugin (PyCharm integrates its own implementationofPEP 484)

VS Code: provides basic integration with mypy.

pre-commit: use pre-commit mirrors-mypy.


Web site and documentation


Additional information is available at the web site:

https://www.mypy-lang.org/

Jump straight to the documentation:

https://mypy.readthedocs.io/

Follow along our changelog at:

https://mypy-lang.blogspot.com/

Contributing


Help in testing, development, documentation and other tasks is highly appreciated and useful to the project. There are tasks for contributors of all experience levels.

To get started with developing mypy, see CONTRIBUTING.md.

If you need help getting started, don't hesitate to ask on gitter.

Mypyc and compiled version of mypy


Mypyc uses Python type hints to compile Python modules to faster C extensions. Mypy is itself compiled using mypyc: this makes mypy approximately 4 times faster than if interpreted!

To install an interpreted mypy instead, use:

python3 -m pip install --no-binary mypy -U mypy


To use a compiled version of a development version of mypy, directly install a binary from https://github.com/mypyc/mypy_mypyc-wheels/releases/latest.

To contribute to the mypyc project, check out https://github.com/mypyc/mypyc
 





About


Optional static typing for Python  

www.mypy-lang.org/  

Topics



python   typechecker   types   linter  typing  

Resources


Readme  

License


View license  

Code of conduct


Code of conduct  

Security policy


Security policy  

Activity  

Custom properties  

Stars


18.3k  stars  

Watchers


239  watching  

Forks


2.8k  forks  

Report repository  





Releases

  94 tags  



Sponsor this project

 



 
 



https://www.python.org/psf/donations/python-dev/  


Learn more about GitHub Sponsors  




Used by 248k  











+ 247,590  



Contributors  698


















+ 684 contributors
 



Languages


 


Python  95.5%  

C 3.2%  

C++  1.1%  

XSLT  0.1%  

Shell  0.1%  

CSS  0.0%  









Footer



© 2024 GitHub, Inc.  


Terms  

Privacy  

Security  

Status  

Docs  

Contact  






You cant perform that action at this time.