You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace SpecAtomType.pyClass with .ident, add BinaryIO, and align type mappings (#968)
Replace the `SpecAtomType.pyClass` variant with `.ident` using qualified
`PythonIdent`, add `typing.BinaryIO` support, and align PySpec→Laurel
type mappings with PythonToLaurel so non-primitive builtins map to `Any`
instead of lossy approximations.
## Changes
### 1. Fix missing source locations in PySpec translation errors
(`SourceRange.lean`, `Specs.lean`)
`SourceRange.format` crashed when called with a `none` range because it
unconditionally called `fm.toPosition` on zero offsets. Now it guards on
`isNone` and renders `"path:unknown"` instead. Several pattern matches
in `Specs.lean` were extracting annotated values via
`name.val`/`name.ann` but discarding the source location — these now
destructure as `⟨_, name⟩` at the binding site and pass the parent `loc`
to error reporters, ensuring translation errors always have usable
locations.
### 2. Remove `SpecAtomType.pyClass` variant (`Decls.lean`, `DDM.lean`,
`Specs.lean`, `ToLaurel.lean`)
`pyClass` stored an unqualified class name string, which was ambiguous
across modules. All construction sites now use `.ident` with a fully
qualified `PythonIdent` (module + name). DDM deserialization of legacy
`typeClass`/`typeClassNoArgs` Ion payloads produces `.ident` with empty
`pythonModule` for backward compatibility. All match arms and comparison
logic for `.pyClass` are removed.
### 3. Add `typing.BinaryIO` support (`Decls.lean`, `Specs.lean`,
`ToLaurel.lean`)
`BinaryIO` appears in boto3 stubs (e.g., `lambda_/client.py`'s `invoke`
returns `StreamingBody` typed as `BinaryIO`). Without this, pySpecs
throws "BinaryIO is not defined in module typing". Added
`PythonIdent.typingBinaryIO`, registered it in `preludeSig`, and mapped
it to `Any` in `knownIdentTypes`.
### 4. Align `knownIdentTypes` with PythonToLaurel (`ToLaurel.lean`)
Previously, PySpec→Laurel mapped types more aggressively than
PythonToLaurel: `bytes`/`bytearray`→`TString`, `complex`→`TReal`,
`dict`→`DictStrAny`, `Exception`→`Error`, `typing.List`→`ListStr`,
`typing.Dict`→`DictStrAny`. PythonToLaurel maps all of these to `Any`.
The mismatch meant pyspec-dispatched analysis could generate spurious
preconditions (e.g., string-length bounds on `bytes` parameters). Now
both paths agree: only `int`, `str`, `bool`, `float`, and `None` get
concrete Laurel types; everything else is `Any`.
By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
0 commit comments