Fix type checking for open builtin #943
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 445 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.365
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #943"
general
weight: 0.35
DanielTemesgen
https://github.com/pydantic/monty/issues/941
open()runs against mounted directories, but it failed type checking withunresolved-reference.update.pyfilters upstreambuiltins.pyithroughALLOWED_FUNCTIONS, andopenwas not on the list.Path.open()resolved toUnknown, because the stub tree had noiomodule.Changes
open: added toALLOWED_FUNCTIONS, so upstream typeshed'sopenandPath.opensignatures come through unchanged.iostubs: upstreamio.pyiand_io.pyiare added toCOPY_FILES.ioand_ioare listed inVERSIONSfor type checking only, likeabc.FileNotFoundError,FileExistsError,IsADirectoryError,NotADirectoryErrorandPermissionErrorare added toALLOWED_CLASSES, soexcept FileNotFoundError:aroundopen()type-checks.good_types.py,reveal_types.pyandbad_types.py, so no existing snapshot entry moves.A pytest writes through a read-write mount with type checking on.
limitations/modules.mdanddocs/type-checking.mdlistioamong the modules the type checker resolves but the runtime cannot import.Trade-offs
Upstream's signatures accept any argument value the runtime might accept, so code that forwards
encodingorbufferingfrom a variable type-checks.As a result, these pass type checking and then fail at runtime:
buffering,errors,newline,closefdoropener, and encodings other than UTF-8'x'or'+'modeswritelines(),fileno()andreadline(size)import ioFollow-ups
iostub, if iterating files turns out to be common.-
print(..., file=f);-
json.load(f)andjson.dump(obj, f);-
e.filenameande.errnoon theOSErrorsubclasses;-
except IOError:;-
from typing import TextIO.<!-- This is an auto-generated description by cubic. -->
---
Summary by cubic
Fixes type checking for the
openbuiltin by vendoring upstream typeshed'siostubs, soopen()andPath.open()resolve with overloads for text and binary modes and invalid argument types are reported before execution.io.pyiand_io.pyifrom typeshed and addsopento the allowed builtins.open()can raise to the allowed class list, soexcept FileNotFoundError:type-checks.ioand_ioas stub-only modules for type checking.open/Path.open()calls, revealed file types, and a write-through run with type checking enabled.ModuleNotFoundErrorat runtime.<sup>Written for commit ab478c1aecf8249dbf7d1dd5fcf86d90754db47d. Summary will update on new commits.</sup>
<a href="https://cubic.dev/pr/pydantic/monty/pull/943?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->