Production-quality 'Min' and 'Max' objects (adapted from PEP 326)
Project description
The peak.util.extremes module provides a production-quality implementation of the Min and Max objects from PEP 326. While PEP 326 was rejected for inclusion in the language or standard library, the objects described in it are useful in a variety of applications. In PEAK, they have been used to implement generic functions (in RuleDispatch and PEAK-Rules), as well as to handle scheduling and time operations in the Trellis. Because this has led to each project copying the same code, we’ve now split the module out so it can be used independently.
Some simple usage examples:
>>> from peak.util.extremes import Min, Max >>> import sys >>> Min < -sys.maxint True >>> Min < None True >>> Min < '' True >>> Max > sys.maxint True >>> Max > 99999999999999999 True >>> type(Min) <class 'peak.util.extremes.Extreme'>
The Min object compares less than any other object but itself, while the Max object compares greater than any other object but itself. Both are instances of the Extreme type.
While the original PEP 326 implementation of these extreme values is shorter than the version used here, it contains a flaw: it does not correctly handle comparisons with classic class instances. Therefore, this version defines methods for all six rich comparison operators, to ensure correct support for classic as well as new-style classes:
>>> Max >= Min and Max > Min and Max==Max and Max!=Min True >>> Max < Min or Max <= Min or Max==Min or Max!=Max False >>> Min <= Max and Min < Max and Min==Min and Min!=Max True >>> Min > Max or Min >= Max or Min==Max or Min!=Min False >>> class X: ... """Ensure rich comparisons work correctly with classic classes""" >>> x = X() >>> Min<x<Max and Min<=x<=Max and Min!=x!=Max and Max!=x!=Min True >>> Min>x or x>Max or x<=Min or x>=Max or x==Min or Min==x False
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file Extremes-1.1.zip
.
File metadata
- Download URL: Extremes-1.1.zip
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fb1b1b237cb166ea29419a148ce7ab70e604dfe8c78fbec9899439c75be996f |
|
MD5 | 34fc2c114b09e2cc331482d6cc4e4399 |
|
BLAKE2b-256 | ee62125b1cb0af1324c060ffb24efbd94fe95a73c86603ae04466bfc8121fb26 |
File details
Details for the file Extremes-1.1-py2.5.egg
.
File metadata
- Download URL: Extremes-1.1-py2.5.egg
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83e1f5fe4926457e2f53231eeb616fa819338d80b790e41703716af6c6a4cac1 |
|
MD5 | 4015e2546295858558cca16faca5f34f |
|
BLAKE2b-256 | 70346917f1e831910d539a1e81e0e1b417fbbadb9f52ae1c961bea3aecc5a452 |
File details
Details for the file Extremes-1.1-py2.4.egg
.
File metadata
- Download URL: Extremes-1.1-py2.4.egg
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1bdcfb3fddf665d426c1c22014bf7eae724d4f243d0c63c70ef62f744692759 |
|
MD5 | bd27cd0b245ea9a136fcf354a17294b4 |
|
BLAKE2b-256 | 9aae997dad72f01e4f5afd031ed92bf9db2c6dc96a654cdea9a62a02ec6b4d00 |
File details
Details for the file Extremes-1.1-py2.3.egg
.
File metadata
- Download URL: Extremes-1.1-py2.3.egg
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9e8b30310afe06442306f31b65ddc78ea22ec2d31d056e7183efcbfdab9bb0b |
|
MD5 | b095353a977d4ba6831c601e6b919b61 |
|
BLAKE2b-256 | eeebb6a21cee9d3562f6cce9fe9d401ef9a93e367375c92fd9da71b19897f9af |