Utility Classes :: IsNoneOf
Overview
The IsNoneOf class is used when specifying what you want is harder than stating what you don't want.
The IsNoneOf() constructor must be passed at least one type, user-defined class or registered extension class. For example:
IsNoneOf(IsCallable())
Where IsCallable is the IsCallable utility class.
This signature will accept any object that IsCallable() rejects.
Similarly, if multiple conditions are provided, each of them must reject the object being checked.
In the next example, an object will match the signature if it is neither callable nor has a foo attribute:
IsNoneOf(IsCallable(), HasAttr(['foo']))
Read about the HasAttr utility class at its manual page.
Details
-
If the object being checked by the
IsNoneOfinstance matches any one of the provided conditions, a_TC_TypeErrorwill be raised; therightattribute will be theIsNoneOfinstance, and thewrongattribute will be the type of the object.This exception is to be caught and converted to a
TypeCheckErrorbefore it reaches the level of the user. -
IsNoneOfobjects will only compare equal (i.e.,==) if all the conditions in the left-hand side are found in the right-hand side, and vice versa [5].All
IsNoneOfinstances that compare equal with==will produce the same value when run through the built-inhash()function [6]. -
IsNoneOfhas been given some limited intelligence. For example:IsNoneOf(int, int, float, float)
will be simplified to
IsNoneOf(int, float)
These two will compare and hash as equals.
-
The order in which the
IsNoneOfinstance's conditions will be checked is undefined.