GithubHelp home page GithubHelp logo

devopsengineerdan / daniel_mypy-type-checking-examples Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 6 KB

Demonstrating Python type annotations and static type checking using MyPy, in common situations - e.g. defining and using functions and classes.

daniel_mypy-type-checking-examples's Introduction

Static Type Checking in Python - Examples using MyPy

This purpose of this project is to demonstrate Python type annotations and static type checking, using MyPy, in common sitautions - e.g. defining and using functions and classes. It consists of a Python 3 package with 3 modules, each of which demonstrates type annotation for a specific situation:

  • function definition and usage;
  • class definition and usage; and,
  • named tuple definition and usage.

Extensive commentary has been included in the docstrings for each function as the aim is to read the code of a Python module that passes a static type check.

Running MyPy

Analagous to a linter or a unit testing framwork, MyPy can be run from the command line as follows,

pipenv run python -m mypy examples/*.py

MyPy Configuration

MyPy options for this project are kept in the mypy.ini file that MyPy will look for by default. For more information on the fulls set of options, see the mypy documentation.

Project Dependencies

This project uses pipenv for managing dependencies (i.e. installing mypy) and Python environments (i.e. virtual environments).

Installing Pipenv

To get started with Pipenv, first of all download it - assuming that there is a global version of Python available on your system and on the PATH, then this can be achieved by running the following command,

pip3 install pipenv

For more information, including advanced configuration options, see the official pipenv documentation.

Installing this Projects' Dependencies

Make sure that you're in the project's root directory (the same one in which Pipfile resides), and then run,

pipenv install --dev

This will install all of the direct project dependencies as well as the development dependencies (the latter a consequence of the --dev flag).

daniel_mypy-type-checking-examples's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.