Compare Pinned Release Compatibility
Core idea
Compatibility covers syntax, library APIs and behavior as well as dependency requirements. ast.parse(feature_version=(3, minor)) offers a best-effort grammar restriction on the current parser; it does not emulate an older runtime. Record the actual interpreter and exercise supported versions independently.
import astsource = 'match x:\n case 1: pass'for minor in (9, 10): try: ast.parse(source, feature_version=(3, minor)) print(minor, 'accepted') except SyntaxError: print(minor, 'rejected')Structural pattern matching entered Python 3.10. This is a grammar probe under 3.13, not a 3.9 execution.
Expected output:
9 rejected10 acceptedGate a library capability
import importlib.utilimport sysprint(sys.version_info >= (3, 11))print(importlib.util.find_spec('tomllib') is not None)tomllib was added in 3.11; this fixture observes availability in the local 3.13 runtime.
Expected output:
TrueTrueCommon mistake
A grammar check cannot detect changed APIs or runtime behavior. A version guard inside code cannot prevent a syntax error while parsing the same file.
Practice
Choose a minimum supported release and check one syntax feature and one library feature on both interpreters; leave unavailable runs unknown.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Release compatibility
Check your understanding of release compatibility.
What is printed?
import astprint(type(ast.parse("x=1").body[0]).__name__)What is printed?
print((3, 13) >= (3, 11))Does feature_version run another Python release?
What verifies library compatibility?