  We use the mathematical language of sheaf theory to give a unified treatment
of non-locality and contextuality, in a setting which generalizes the familiar
probability tables used in non-locality theory to arbitrary measurement covers;
this includes Kochen-Specker configurations and more. We show that
contextuality, and non-locality as a special case, correspond exactly to
obstructions to the existence of global sections. We describe a linear
algebraic approach to computing these obstructions, which allows a systematic
treatment of arguments for non-locality and contextuality. We distinguish a
proper hierarchy of strengths of no-go theorems, and show that three leading
examples --- due to Bell, Hardy, and Greenberger, Horne and Zeilinger,
respectively --- occupy successively higher levels of this hierarchy. A general
correspondence is shown between the existence of local hidden-variable
realizations using negative probabilities, and no-signalling; this is based on
a result showing that the linear subspaces generated by the non-contextual and
no-signalling models, over an arbitrary measurement cover, coincide. Maximal
non-locality is generalized to maximal contextuality, and characterized in
purely qualitative terms, as the non-existence of global sections in the
support. A general setting is developed for Kochen-Specker type results, as
generic, model-independent proofs of maximal contextuality, and a new
combinatorial condition is given, which generalizes the `parity proofs'
commonly found in the literature. We also show how our abstract setting can be
represented in quantum mechanics. This leads to a strengthening of the usual
no-signalling theorem, which shows that quantum mechanics obeys no-signalling
for arbitrary families of commuting observables, not just those represented on
different factors of a tensor product.
