picos.compat

Python 2/3 compatibility helpers.

Outline

Classes

ABC

Base class for abstract classes.

MappingProxyType

Undocumented.

MutableSet

A mutable set is a finite, iterable container.

long

int([x]) -> integer

Functions

abstractmethod

A decorator indicating abstract methods.

assert_import_exists

Error if the given package or module name is not available for import.

import_exists

Check if a package or module name is available for import.

lru_cache

Least-recently-used cache decorator.

Classes

ABC

class picos.compat.ABC[source]

Bases: object

Base class for abstract classes.

MappingProxyType

picos.compat.MappingProxyType

alias of builtins.mappingproxy

MutableSet

class picos.compat.MutableSet

Bases: collections.abc.Set

A mutable set is a finite, iterable container.

This class provides concrete generic implementations of all methods except for __contains__, __iter__, __len__, add(), and discard().

To override the comparisons (presumably for speed, as the semantics are fixed), all you have to do is redefine __le__ and then the other operations will automatically follow suit.

abstract add(value)

Add an element.

clear()

This is slow (creates N new iterators!) but effective.

abstract discard(value)

Remove an element. Do not raise an exception if absent.

pop()

Return the popped value. Raise KeyError if empty.

remove(value)

Remove an element. If not a member, raise a KeyError.

long

picos.compat.long

alias of builtins.int

Functions

abstractmethod

picos.compat.abstractmethod(funcobj)[source]

A decorator indicating abstract methods.

assert_import_exists

picos.compat.assert_import_exists(importName)[source]

Error if the given package or module name is not available for import.

Raises

ModuleNotFoundError or ImportError – If no module with the given name is available for import, denpending on the Python version.

import_exists

picos.compat.import_exists(importName)[source]

Check if a package or module name is available for import.

lru_cache

picos.compat.lru_cache(maxsize=128, typed=False)[source]

Least-recently-used cache decorator.

If maxsize is set to None, the LRU features are disabled and the cache can grow without bound.

If typed is True, arguments of different types will be cached separately. For example, f(3.0) and f(3) will be treated as distinct calls with distinct results.

Arguments to the cached function must be hashable.

View the cache statistics named tuple (hits, misses, maxsize, currsize) with f.cache_info(). Clear the cache and statistics with f.cache_clear(). Access the underlying function with f.__wrapped__.

See: http://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)

Data

picos.compat.MAJOR

Major Python version.

picos.compat.MINOR

Minor Python version.

picos.compat.VERSION

The same as sys.version_info.