Skip to content

feat(checker): BSK-E0153 constructor-to-callable conversion (conformance constructors_callable PASS)#73

Merged
MelbourneDeveloper merged 1 commit into
mainfrom
pep/e0153-constructor-to-callable
Jun 3, 2026
Merged

feat(checker): BSK-E0153 constructor-to-callable conversion (conformance constructors_callable PASS)#73
MelbourneDeveloper merged 1 commit into
mainfrom
pep/e0153-constructor-to-callable

Conversation

@MelbourneDeveloper
Copy link
Copy Markdown
Collaborator

TLDR

Adds checker rule BSK-E0153 implementing the typing-spec "Converting a constructor to callable" rule, flipping the constructors_callable.py PEP conformance file to PASS (suite 135→136/146, 93.15%).

What Was Added?

  • crates/basilisk-checker/src/rules/e0153.rsConstructorCallableMisuse rule. When a class object flows through an identity-over-callable function (def f(cb: Callable[P, R]) -> Callable[P, R]), the bound variable inherits the class's constructor-to-callable signature, and calls to it are validated. Signature derivation priority: metaclass __call____new__ (when it returns a non-Self/non-class type, e.g. -> int/-> Proxy/-> Any, so __init__ is ignored) → __init__ → empty. Detects: too few / too many positional args, unknown keyword names, and inconsistent list[T] TypeVar bindings. Conservative: starred/**kwargs unpacking suppresses arity checks.
  • crates/basilisk-checker/tests/e0153_tests.rs — 8 e2e tests (invalid calls, valid calls, metaclass passthrough, __new__-controls, float/bytes element conflict, heterogeneous list, plus isolation guards: non-identity wrappers and direct class aliases must NOT fire).
  • shared::method_name_map() — shared (class, method) → Vec<&FunctionInfo> builder.

What Was Changed or Deleted?

  • Registered e0153::ConstructorCallableMisuse in the rule registry.
  • DRY: migrated e0041, e0074, e0111, e0144 to shared::method_name_map, deleting 4 copies of the identical inline method-map builder.
  • Ratcheted the conformance threshold 92 → 93 in coverage-thresholds.json (now 136/146 = 93.15%).
  • Regenerated conformance/conformance_status.csv (constructors_callable.py → PASS, 12 caught / 0 missed / 0 FP).

How Do The Automated Tests Prove It Works?

  • e0153_tests: 8 tests pass — e.g. invalid_calls_emit_e0153 asserts exactly 4 diagnostics ("missing required argument x", "Unexpected keyword argument y", "too many positional argument", "Inconsistent binding for type variable T"); valid_calls_do_not_emit_e0153, metaclass_call_accepts_any_arguments, and non_identity_wrapper_is_not_tracked assert zero diagnostics.
  • conformance_score: gate prints 93% (136/146) >= 93% threshold — PASS; constructors_callable.py now caught=12, missed=0, and the suite-wide false-positive total is unchanged at 170 (zero new FPs).
  • Coverage: basilisk-checker at 94% ≥ 93%; all crate thresholds met; full workspace test suite green. cargo clippy --workspace --all-targets -D warnings and cargo fmt --check clean.

Spec / Doc Changes

  • docs/specs/CHECKER-ARCHITECTURE-SPEC.md: new section {#CHKARCH-DIAG-CTOR-CALLABLE} + BSK-E0153 reference-table row (code/tests cross-reference this spec ID).
  • website/src/docs/rules/index.md + zh/ mirror: added BSK-E0153 row.
  • docs/plans/CHECKER-PEP-CONFORMANCE-PLAN.md: score updated to 136/146; constructors_callable.py marked done.

Breaking Changes

  • None — additive rule; only fires on the narrow constructor-to-callable pattern (verified no other conformance file or extension fixture triggers it).

…ormance constructors_callable PASS)

Implements the typing-spec rule 'Converting a constructor to callable'.
A class object flowing through an identity-over-callable function
(def f(cb: Callable[P, R]) -> Callable[P, R]) gains the class's
constructor-to-callable signature; calls to the bound variable are now
validated against it (arity, keyword names, and list[T] TypeVar binding
consistency). Signature derivation priority: metaclass __call__, then
__new__ (when it returns a non-Self/non-class type), then __init__.

Flips conformance constructors_callable.py to PASS (12/12, 0 FP), raising
the suite to 136/146 (93.15%); conformance threshold ratcheted 92 -> 93.

Also extracts shared::method_name_map and migrates e0041/e0074/e0111/e0144
to it, removing 4 copies of the (class, method) -> Vec<&FunctionInfo>
builder (net DRY win).
@MelbourneDeveloper MelbourneDeveloper merged commit bf832a0 into main Jun 3, 2026
12 checks passed
@MelbourneDeveloper MelbourneDeveloper deleted the pep/e0153-constructor-to-callable branch June 3, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant