Skip to main content

Package for creating integer types.

Project description

This package provides utilities for creating custom integer types.

Integer

Inheriting directly from int type results in custom integer types where the results of operations are instances of int type.

>>> class X(int): pass
...
>>> a = X(1)
>>> x = a + 1
>>> x
2
>>> x.__class__
<type 'int'>

Integer can be used as a base class for custom integer types that preserve the type when performing operations.

>>> from integer import Integer
>>> class X(Integer): pass
...
>>> a = X(1)
>>> x = a + 1
>>> x
2
>>> x.__class__
<class '__main__.X'>

Subclasses can override the finalize_values method in order to affect the final return value of operations whenever the int operations returns an int.

enum

enum can be used to declare an enumeration, which defines the enumeration type and its enumeration values in the global scope of the calling module.

>>> from integer.enum import enum
>>> enum('RGB', RED=1, GREEN=2, BLUE=3, ALPHA=4)
>>> RGB
<class 'integer.enum.RGB'>
>>> RED
RED
>>> int(RED)
1
>>> RGB(1)
RED
>>> RGB(1) is RED
True
>>> RED, GREEN, BLUE, ALPHA, RGB(5)
(RED, GREEN, BLUE, ALPHA, RGB(5))

The type defined by enum does not restrict the values that it can represent, it just provides a helpful string representation for the named values.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

integer-1.0.3.tar.gz (15.6 kB view details)

Uploaded Source

File details

Details for the file integer-1.0.3.tar.gz.

File metadata

  • Download URL: integer-1.0.3.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for integer-1.0.3.tar.gz
Algorithm Hash digest
SHA256 9f6e9c7215f7ce9505cfd810468642e3f683e215741e1026b9aa67a8be515d58
MD5 fa3c66f1dc94d762ca1b8a836ad4013f
BLAKE2b-256 ea7eaeb17646f2dcb725c151cc0f728e4ca6e5add7a735fd830273f5297d1329

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page