API Reference
BaseTypeContracts is intentionally small: loading it registers the Base contracts, and a couple of helpers let you query them. The full checking, testing and introspection toolkit lives in TypeContracts.
Module
BaseTypeContracts.BaseTypeContracts Module
BaseTypeContractsReady-made TypeContracts contracts for Julia Base types — analogous to BaseInterfaces.jl for Interfaces.jl.
Loading this package registers structural contracts and behavioral invariants for the core Base abstract types so you don't have to write them yourself:
| Contract target | Protocol |
|---|---|
AbstractArray | indexing |
AbstractDict | associative |
AbstractSet | set |
AbstractString | string |
Number | arithmetic |
Real | ordering |
AbstractFloat | IEEE 754 laws |
Integer | bitwise ops |
AbstractChar | code point |
IO | byte I/O |
AbstractChannel | messaging |
AbstractRange | stepped sequence |
Base.AbstractLock | mutual exclusion |
Logging.AbstractLogger | log sink |
AbstractDisplay | display sink |
Base.AbstractPattern | text matching |
Exception | error reporting (invariants only) |
Random.AbstractRNG | random streams (invariants only) |
Iterable (marker) | iteration |
Access pattern
Every TypeContracts tool works directly against a concrete instantiation like Vector{Int} — the registry key is the bare AbstractArray UnionAll, and TypeContracts resolves a parameterized concrete type back to it automatically:
using TypeContracts, BaseTypeContracts
implements(Vector{Int}, AbstractArray) # true
implements(Dict{String,Int}, AbstractDict) # true
implements(Vector{Int}, Iterable) # iteration marker
@verify Vector{Int} for_contract=AbstractArray # seals verified_trait(AbstractArray, Vector{Int})check/all_implements are convenience wrappers scoped to exactly the curated Base types this package covers: instead of naming one contract at a time, check(T) returns every applicable one in a single Dict, and all_implements(T) summarizes that dict as a Bool:
BaseTypeContracts.check(Vector{Int}) # Dict(AbstractArray => (satisfied=true, ...))
BaseTypeContracts.all_implements(Vector{Int}) # true if all applicable contracts passThe iteration marker
BaseTypeContracts.Iterable Type
IterableMarker type carrying the Base iteration contract. No type is <: Iterable; query it explicitly with satisfies(T, Iterable) or test_behavior(T, Iterable, objs).
Helpers
BaseTypeContracts.check Function
check(T::Type) -> Dict{Type, NamedTuple}Run satisfies(T, B) for every registered Base contract B where T <: B. Returns a dict mapping each applicable Base type to its satisfies result.
Scoped to exactly the curated Base types this package covers (base_contract_types): a convenience for getting every applicable contract's result in one call, rather than naming each one individually with satisfies/implements.
For a simple boolean result use all_implements, or for a single interface use implements(T, AbstractArray) etc.
BaseTypeContracts.all_implements Function
all_implements(T::Type) -> BoolReturn true if T satisfies every applicable Base contract. Equivalent to all(r -> r.satisfied, values(check(T))). Designed for direct use with @test:
@test all_implements(Vector{Int})
@test all_implements(Dict{String, Int})Returns true (vacuously) for a type with no applicable Base contract at all — unlike TypeContracts' own implements(T), which throws ArgumentError in that case. A typo'd or unrelated type therefore "passes" silently; if that matters, check !isempty(check(T)) first, or use implements(T) for the throwing variant.
BaseTypeContracts.base_contract_types Function
base_contract_types() -> TupleReturn the Base abstract types for which contracts are registered (excludes the Iterable marker).