This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Getting Started

The first snippet below checks that an object is a list of tuples, each tuple with an int and a string. The second snippet shows how to decorate a function

activate_checktype() # by default, checktype is deactivated

o = [(1, 'hello'), (2, 'world')
checktype(o, '[(int, str)..]')


@check('str, {str:int} -> [int..]')
def myfunction(a1, a2):
    return [1,2,3]

myfunction("say", {"hello":1})

Introduction

Python is strongly, dynamically typed. This is fine, but at times when objects get too complicated, it can be a good thing to check for types.

Checktype allows simple checking of Python object formats. It has a very intuitive type system that mimics the way you define your own Python objects.

It can be particularily helpful when refactoring programs. Its performance has not been optimized and it is intended as a development-time type checking utility (disabled by default, and should probably be activated in tests only).

Installation

You can install checktype with pip:

pip install checktype

Usage examples:

from checktype import checktype, activate_checktype, check

# 'activates' checktype. You need to explicitly call this,
# else it will do nothing (by default, to save cpu time).
# It is common to specify it in tests
activate_checktype()

# checktype only provides a single function, that takes two arguments.
# the first one is the python object you want to test;
# the second one is an 'object specification' (spec), that mimics the way
# objects are represented in Python. This spec is a string representation of
# a python object. For example, to check that 12 is an int or 'hello' is a str:
checktype(12, 'int')
checktype('hello', 'str')

# A list of exactly 3 floats is specified as [float,float,float]
checktype([1.0,2.0,3.0], '[float,float,float]')

# To match a variable-length list of ints, use [int..]
checktype([1,2,3], '[int..]')

# To only check that it is a list (but not its content), use []
checktype([1, "deux"], '[]')

# And so on for tuples,
checktype((1,2,3), '(int,int,int)')
checktype((1,2,3), '(int..)')
checktype((1, "deux"), '()')
# dictionnaries,
checktype({11:2, 12: 3},  '{int:int}')
checktype({11:2, 12: 3},  '{}')
# and sets.
checktype({11, 2},  '{int}')

# Use the ? wildcard if you don't want to check for a specific part
checktype({11:2, 12: "a", 13:(3,4)},  '{int:?}')

# Further examples
checktype({11: (2,3), 12: (4,"5")}, '{ int: (int,?)}')
checktype([(2, "asdf"),(-12, "asfwe"),(1,"")], "[(int,str)..]")
checktype([(1, 'hello', 2.0)], "[(int, str, float)]")

# Decorator examples
@check("str.. -> int")
def fn_1(a1, a2):
    return 1

fn_1("say", "hello")


@check("str, {str:int} -> [int..]")
def fn_3(a1, a2):
    return [1,2,3]

fn_3("say", {"hello":1})
Release History

Release History

1.1.4

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
checktype-1.1.4.tar.gz (4.6 kB) Copy SHA256 Checksum SHA256 Source Dec 16, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting