Skip to content

Exclude unreachable antecedents from code flow complexity - #11806

Open
crypt0lith wants to merge 4 commits into
microsoft:mainfrom
crypt0lith:fix/unreachable-edge-complexity
Open

crypt0lith wants to merge 4 commits into
microsoft:mainfrom
crypt0lith:fix/unreachable-edge-complexity

Conversation

@crypt0lith

@crypt0lith crypt0lith commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The overcount predates #11520, which made it much more common by extending static evaluation to literals such as {}, [], 0 and "". Each operand of a binary logical operator adds 1 to its function's code flow complexity when its truthiness is evaluated statically. This can push a function over the limits for call-site return type inference (maxReturnCallSiteTypeInferenceCodeFlowComplexity, 8) and for return type inference with unannotated parameters (maxReturnTypeInferenceCodeFlowComplexity, 32), and the evaluator then infers its return type as Unknown.

Root cause

_finishFlowLabel adds the number of antecedents minus one to the code flow complexity for each label, including unreachable antecedents. Code flow analysis stops when it reaches an unreachable antecedent, so it adds no path.

When the truthiness of an operand of a binary logical operator is evaluated statically, _createFlowConditional returns the unreachable static condition node for the branch that can't be taken, rather than the same antecedent as the other branch. _addAntecedent checks whether the current flow node is reachable, not the antecedent, so it adds the unreachable node to the label as a distinct antecedent.

Filtering in _addAntecedent instead would leave some labels with no antecedents, which changes how unreachable code is reported.

Fix

Count only antecedents not flagged UnreachableStructural or UnreachableStaticCondition when computing a label's contribution to the complexity.

Test

Each b = b or {} assignment adds 1 to the complexity with the fix and 2 without it, and maxReturnCallSiteTypeInferenceCodeFlowComplexity is 8, so four is the fewest that reach the limit without the fix while staying under it with the fix.

Cases added to callSite13.py
Case Expected Description
func1 four b or {}, statically falsy right operand: Literal[1]
func2 four 0 or b, statically falsy left operand: Literal[1]
func3 eight b or {}, at the limit with the fix: Unknown
func4 four b or a, no static operand: Unknown

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@bschnurr

Copy link
Copy Markdown
Member

/benchmark

@github-actions

This comment has been minimized.

@heejaechang

Copy link
Copy Markdown
Collaborator

🟢 Pyright CLI QA — d11c6395 — verdict: green

Automated CLI checks compared this change with its base revision.
10 focused check(s) completed.

No new behavior difference was detected.

_finishFlowLabel counts unreachable antecedents toward a label's code
flow complexity, although code flow analysis never traverses them. When
the truthiness of an operand of a binary logical operator is evaluated
statically, the operand adds one, which can push a function over the
complexity limits for return type inference. Count only reachable
antecedents.
@crypt0lith
crypt0lith force-pushed the fix/unreachable-edge-complexity branch from d11c639 to 262ef8f Compare October 24, 2026 22:34

@rchiodo Rich Chiodo (rchiodo) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good complexity change. Could we add a few more controls to callSite5.py?

The current func(a, b) test has four b = b or {} lines before return a, and checks reveal_type(func(1, None), expected_text='Literal[1]'). That test would still pass if complexity counting were accidentally removed altogether.

With the same function shape, eight b = b or {} lines or four b = b or a lines reveal Unknown on both base and head. Four b = b and [] lines or four b = 0 or b lines reveal Unknown on base and Literal[1] on head. Could we add boundary and dynamic controls and one of the and or static-left variants? That would cover cases that stay Unknown as well as another form that benefits from the change.

Also, the comment in binder.ts says analysis never traverses unreachable antecedents. The flow engine does encounter them, but terminates immediately and uses flags to distinguish reachability reasons. They stay in the graph and don't add further paths. Could we clarify the wording? I don't think the graph needs to change.

@bschnurr

Copy link
Copy Markdown
Member

The inference fix reproduces on current main (d95fe63): the PR sample reveals Unknown on main and Literal[1] with 262ef8f8 integrated. The merge currently conflicts because both revisions add callSite5.py and register CallSite5. I kept the upstream fixture and replayed the PR sample separately in a scratch integration. Please give the new fixture and test a distinct name so both regressions remain covered. This verifies the motivating case, not the cost of the new counting path or the earlier primer deltas.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

sympy (https://github.com/sympy/sympy)
+   .../projects/sympy/sympy/core/exprtools.py:776:25 - error: Argument of type "One | Zero | Unknown | Expr" cannot be assigned to parameter "value" of type "bytes" in function "__setitem__"
+     Type "One | Zero | Unknown | Expr" is not assignable to type "bytes"
+       "Expr" is not assignable to "bytes" (reportArgumentType)
+   .../projects/sympy/sympy/core/tests/test_expr.py:1382:52 - error: "expand" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/sympy/sympy/core/tests/test_expr.py:1384:60 - error: "expand" is not a known attribute of "None" (reportOptionalMemberAccess)
- 38184 errors, 83 warnings, 0 informations
+ 38187 errors, 83 warnings, 0 informations

zope.interface (https://github.com/zopefoundation/zope.interface)
-   .../projects/zope.interface/src/zope/interface/common/tests/__init__.py:31:22 - error: Cannot access attribute "dependents" for class "_InterfaceClassWithCustomMethods*"
+   .../projects/zope.interface/src/zope/interface/common/tests/__init__.py:31:22 - error: Cannot access attribute "dependents" for class "<subclass of ABCInterfaceClass and _InterfaceClassWithCustomMethods>"
-   .../projects/zope.interface/src/zope/interface/common/tests/__init__.py:31:22 - error: Cannot access attribute "dependents" for class "InterfaceClass*"
+   .../projects/zope.interface/src/zope/interface/common/tests/__init__.py:31:22 - error: Cannot access attribute "dependents" for class "InterfaceClass"
+   .../projects/zope.interface/src/zope/interface/interface.py:739:44 - error: Argument of type "Any | _InterfaceClassWithCustomMethods | InterfaceClass | Self@InterfaceClass | type[Self@InterfaceClass]" cannot be assigned to parameter "cls" of type "type[Self@object]" in function "__new__"
+     Type "Any | _InterfaceClassWithCustomMethods | InterfaceClass | Self@InterfaceClass | type[Self@InterfaceClass]" is not assignable to type "type[Self@object]" (reportArgumentType)
-   .../projects/zope.interface/src/zope/interface/interface.py:989:11 - error: Cannot assign to attribute "_calculate_sro" for class "_InterfaceClassWithCustomMethods*"
+   .../projects/zope.interface/src/zope/interface/interface.py:989:11 - error: Cannot assign to attribute "_calculate_sro" for class "_InterfaceClassWithCustomMethods"
-     Attribute "_calculate_sro" is unknown (reportAttributeAccessIssue)
-   .../projects/zope.interface/src/zope/interface/interface.py:989:11 - error: Cannot assign to attribute "_calculate_sro" for class "InterfaceClass*"
-   .../projects/zope.interface/src/zope/interface/interface.py:990:11 - error: Cannot access attribute "changed" for class "_InterfaceClassWithCustomMethods*"
+   .../projects/zope.interface/src/zope/interface/interface.py:990:11 - error: Cannot access attribute "changed" for class "_InterfaceClassWithCustomMethods"
-     Attribute "changed" is unknown (reportAttributeAccessIssue)
-   .../projects/zope.interface/src/zope/interface/interface.py:990:11 - error: Cannot access attribute "changed" for class "InterfaceClass*"
-   .../projects/zope.interface/src/zope/interface/interface.py:991:18 - error: Cannot access attribute "__sro__" for class "_InterfaceClassWithCustomMethods*"
+   .../projects/zope.interface/src/zope/interface/interface.py:991:18 - error: Cannot access attribute "__sro__" for class "_InterfaceClassWithCustomMethods"
-     Attribute "__sro__" is unknown (reportAttributeAccessIssue)
-   .../projects/zope.interface/src/zope/interface/interface.py:991:18 - error: Cannot access attribute "__sro__" for class "InterfaceClass*"
-     Expression of type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" cannot be assigned to attribute "_ROOT" of class "Specification"
+     Expression of type "Any | _InterfaceClassWithCustomMethods | InterfaceClass" cannot be assigned to attribute "_ROOT" of class "Specification"
-       Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "None"
+       Type "Any | _InterfaceClassWithCustomMethods | InterfaceClass" is not assignable to type "None"
-         "InterfaceClass*" is not assignable to "None" (reportAttributeAccessIssue)
+         "InterfaceClass" is not assignable to "None" (reportAttributeAccessIssue)
-   .../projects/zope.interface/src/zope/interface/tests/test_adapter.py:1575:33 - error: Argument of type "list[_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass]" cannot be assigned to parameter "iterable" of type "Iterable[SupportsRichComparisonT(1)@sorted]" in function "sorted"
+   .../projects/zope.interface/src/zope/interface/tests/test_adapter.py:1575:33 - error: Argument of type "list[Any | _InterfaceClassWithCustomMethods | InterfaceClass]" cannot be assigned to parameter "iterable" of type "Iterable[SupportsRichComparisonT(1)@sorted]" in function "sorted"
-     Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "SupportsRichComparison"
+     Type "Any | _InterfaceClassWithCustomMethods | InterfaceClass" is not assignable to type "SupportsRichComparison"
-       Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "SupportsRichComparison"
+       Type "Any | _InterfaceClassWithCustomMethods | InterfaceClass" is not assignable to type "SupportsRichComparison"
-         Type "InterfaceClass*" is not assignable to type "SupportsRichComparison"
+         Type "InterfaceClass" is not assignable to type "SupportsRichComparison"
-           "InterfaceClass*" is incompatible with protocol "SupportsDunderLT[Any]"
+           "InterfaceClass" is incompatible with protocol "SupportsDunderLT[Any]"
-           "InterfaceClass*" is incompatible with protocol "SupportsDunderGT[Any]"
+           "InterfaceClass" is incompatible with protocol "SupportsDunderGT[Any]"
-     Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "SupportsRichComparison" (reportArgumentType)
+     Type "Any | _InterfaceClassWithCustomMethods | InterfaceClass" is not assignable to type "SupportsRichComparison" (reportArgumentType)
-   .../projects/zope.interface/src/zope/interface/tests/test_adapter.py:1579:33 - error: Argument of type "list[_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass]" cannot be assigned to parameter "iterable" of type "Iterable[SupportsRichComparisonT(1)@sorted]" in function "sorted"
+   .../projects/zope.interface/src/zope/interface/tests/test_adapter.py:1579:33 - error: Argument of type "list[Any | _InterfaceClassWithCustomMethods | InterfaceClass]" cannot be assigned to parameter "iterable" of type "Iterable[SupportsRichComparisonT(1)@sorted]" in function "sorted"
-     Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "SupportsRichComparison"
+     Type "Any | _InterfaceClassWithCustomMethods | InterfaceClass" is not assignable to type "SupportsRichComparison"
-       Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "SupportsRichComparison"
+       Type "Any | _InterfaceClassWithCustomMethods | InterfaceClass" is not assignable to type "SupportsRichComparison"
-         Type "InterfaceClass*" is not assignable to type "SupportsRichComparison"
+         Type "InterfaceClass" is not assignable to type "SupportsRichComparison"
-           "InterfaceClass*" is incompatible with protocol "SupportsDunderLT[Any]"
+           "InterfaceClass" is incompatible with protocol "SupportsDunderLT[Any]"
-           "InterfaceClass*" is incompatible with protocol "SupportsDunderGT[Any]"
+           "InterfaceClass" is incompatible with protocol "SupportsDunderGT[Any]"
-     Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "SupportsRichComparison" (reportArgumentType)
+     Type "Any | _InterfaceClassWithCustomMethods | InterfaceClass" is not assignable to type "SupportsRichComparison" (reportArgumentType)
-     Expression of type "list[_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass]" cannot be assigned to attribute "_provided" of class "Registry"
+     Expression of type "list[Any | _InterfaceClassWithCustomMethods | InterfaceClass]" cannot be assigned to attribute "_provided" of class "Registry"
-       "list[_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass]" is not assignable to "tuple[Unknown, ...]" (reportAttributeAccessIssue)
+       "list[Any | _InterfaceClassWithCustomMethods | InterfaceClass]" is not assignable to "tuple[Unknown, ...]" (reportAttributeAccessIssue)
-   .../projects/zope.interface/src/zope/interface/tests/test_adapter.py:1638:33 - error: Argument of type "list[_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass]" cannot be assigned to parameter "iterable" of type "Iterable[SupportsRichComparisonT(1)@sorted]" in function "sorted"
+   .../projects/zope.interface/src/zope/interface/tests/test_adapter.py:1638:33 - error: Argument of type "list[Any | _InterfaceClassWithCustomMethods | InterfaceClass]" cannot be assigned to parameter "iterable" of type "Iterable[SupportsRichComparisonT(1)@sorted]" in function "sorted"
-     Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "SupportsRichComparison"
+     Type "Any | _InterfaceClassWithCustomMethods | InterfaceClass" is not assignable to type "SupportsRichComparison"
-       Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "SupportsRichComparison"
+       Type "Any | _InterfaceClassWithCustomMethods | InterfaceClass" is not assignable to type "SupportsRichComparison"
-         Type "InterfaceClass*" is not assignable to type "SupportsRichComparison"
+         Type "InterfaceClass" is not assignable to type "SupportsRichComparison"
-           "InterfaceClass*" is incompatible with protocol "SupportsDunderLT[Any]"
+           "InterfaceClass" is incompatible with protocol "SupportsDunderLT[Any]"
-           "InterfaceClass*" is incompatible with protocol "SupportsDunderGT[Any]"
+           "InterfaceClass" is incompatible with protocol "SupportsDunderGT[Any]"
-     Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "SupportsRichComparison" (reportArgumentType)
+     Type "Any | _InterfaceClassWithCustomMethods | InterfaceClass" is not assignable to type "SupportsRichComparison" (reportArgumentType)

... (truncated 388 lines) ...

apprise (https://github.com/caronc/apprise)
+   .../projects/apprise/apprise/plugins/office365.py:1067:29 - error: Argument of type "Unknown | Any | None" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
+     Type "Unknown | Any | None" is not assignable to type "ConvertibleToInt"
+       Type "None" is not assignable to type "ConvertibleToInt"
+         "None" is not assignable to "str"
+         "None" is incompatible with protocol "Buffer"
+           "__buffer__" is not present
+         "None" is incompatible with protocol "SupportsInt"
+           "__int__" is not present
+         "None" is incompatible with protocol "SupportsIndex"
+     ... (reportArgumentType)
+   .../projects/apprise/apprise/plugins/office365.py:1067:29 - error: Argument of type "Unknown | Any | None" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
+     Type "Unknown | Any | None" is not assignable to type "ConvertibleToInt"
+       Type "None" is not assignable to type "ConvertibleToInt"
+         "None" is not assignable to "str"
+         "None" is incompatible with protocol "Buffer"
+           "__buffer__" is not present
+         "None" is incompatible with protocol "SupportsInt"
+           "__int__" is not present
+         "None" is incompatible with protocol "SupportsIndex" (reportArgumentType)
+   .../projects/apprise/apprise/plugins/office365.py:1108:29 - error: Argument of type "Unknown | Any | None" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
+     Type "Unknown | Any | None" is not assignable to type "ConvertibleToInt"
+       Type "None" is not assignable to type "ConvertibleToInt"
+         "None" is not assignable to "str"
+         "None" is incompatible with protocol "Buffer"
+           "__buffer__" is not present
+         "None" is incompatible with protocol "SupportsInt"
+           "__int__" is not present
+         "None" is incompatible with protocol "SupportsIndex"
+     ... (reportArgumentType)
+   .../projects/apprise/apprise/plugins/office365.py:1108:29 - error: Argument of type "Unknown | Any | None" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
+     Type "Unknown | Any | None" is not assignable to type "ConvertibleToInt"
+       Type "None" is not assignable to type "ConvertibleToInt"
+         "None" is not assignable to "str"
+         "None" is incompatible with protocol "Buffer"
+           "__buffer__" is not present
+         "None" is incompatible with protocol "SupportsInt"
+           "__int__" is not present
+         "None" is incompatible with protocol "SupportsIndex" (reportArgumentType)
- 7151 errors, 18 warnings, 0 informations
+ 7155 errors, 18 warnings, 0 informations

@github-actions

Copy link
Copy Markdown
Contributor

Compared candidate ed2f5eb9cc11d683c3ccd3d6e78c4dd24189494e against its first parent 7e29199f7b3c5bddeda6956588a15552398a66ad.

Release history charts were not rendered for this run. See the workflow run for details.

Type checker benchmark

🟢 No performance regressions detected.

Regression threshold: 20.0%
Statistic: median
Variance guard: >1.0s time and >100.0 MB memory

Package Checker Files checked Time Time delta Peak memory Memory delta Status
ansible pyright 583 19.709s -2.8% 1085.4 MB +0.6% 🟢 Pass
click pyright 17 3.332s +1.3% 358.9 MB +0.3% 🟢 Pass
homeassistant pyright 9850 139.542s -1.4% 6009.8 MB -0.5% 🟢 Pass
numpy pyright 356 39.913s +0.3% 1265.6 MB +1.8% 🟢 Pass
pandas pyright 1459 135.774s -2.1% 3579.3 MB +1.7% 🟢 Pass
pytest pyright 243 9.776s +0.3% 866.7 MB -0.7% 🟢 Pass
requests pyright 19 1.953s -0.6% 348.8 MB -0.2% 🟢 Pass
torch pyright 2400 140.454s -1.6% 4742.9 MB +2.8% 🟢 Pass
transformers pyright 2901 75.888s -6.8% 5197.0 MB +5.8% 🟢 Pass

Pyright stats

Package Parsed/bound Checked Find Read Tokenize Parse Imports Bind Check Cycles
ansible 988 583 0.040s 0.087s 0.360s 0.747s 0.207s 0.913s 16.387s 0.000s
click 111 17 0.000s 0.013s 0.113s 0.223s 0.040s 0.283s 2.303s 0.000s
homeassistant 11154 9850 0.670s 0.773s 2.810s 5.340s 1.987s 6.550s 117.633s 0.000s
numpy 606 356 0.010s 0.063s 0.350s 0.687s 0.257s 0.923s 37.187s 0.000s
pandas 1899 1459 0.070s 0.207s 1.197s 2.507s 0.253s 2.797s 127.927s 0.000s
pytest 545 243 0.013s 0.043s 0.263s 0.383s 0.093s 0.543s 8.067s 0.000s
requests 167 19 0.000s 0.017s 0.087s 0.170s 0.047s 0.223s 1.123s 0.000s
torch 3078 2400 0.173s 0.363s 1.873s 3.380s 0.530s 4.837s 127.237s 0.000s
transformers 3536 2901 0.090s 0.307s 1.433s 2.683s 0.683s 6.393s 68.883s 0.000s

@github-actions

Copy link
Copy Markdown
Contributor

mypy_primer analysis

Advisory AI analysis of primer run 44845175822, attempt 1
for commit c20778373d80c515fd213dd26bb09b9bd0a7cc30. This is not an approval or proof of correctness.

Regression review required. Potential regressions or recorded warning signals are listed first; causation must be established separately.

Potential regressions

sympy: Lowering the flow-complexity gate newly analyzes three call sites, surfacing an Expr-to-bytes write and two possible-None .expand calls; whether those paths are genuinely reachable remains unverified.

Regression warning signals require review, regardless of the AI assessment:

  • Changed diagnostic details introduce Any/Unknown.

AI assessment: Needs human review (medium confidence). PR attribution: Likely caused by the PR.

Before / baseline evidence: The baseline emitted no headers at exprtools.py:776 or test_expr.py:1382/1384. This does not establish a precise baseline type, only that these argument and optional-member checks were not reported. The recorded artifact does not include surrounding baseline reveals or the exact SymPy checkout revision.

After / PR evidence: At exprtools.py:776:25, the value assigned through __setitem__ is now inferred as One | Zero | Unknown | Expr and rejected against bytes. At test_expr.py:1382:52 and 1384:60, .expand is now checked on a value that includes None, producing reportOptionalMemberAccess. The gradual-detail signal is the Expr-containing assignability explanation, not evidence that the whole value became Unknown.

Why this matters: Users can no longer rely on these formerly silent paths type-checking: dictionary-like writes now require excluding Expr/Unknown from a bytes value, and the two test expressions require proving non-None before .expand. This may restore useful checking, but could be a false positive if call-site inference failed to preserve a branch invariant or overload relationship.

Causal analysis:

The PR changes Binder flow complexity from all label antecedents to only antecedents not marked UnreachableStructural or UnreachableStaticCondition. That can move an unannotated function below Pyright's complexity cutoff, enabling call-site return inference where the baseline skipped it. The added regression sample explicitly demonstrates this path: repeated `b = b or {}` creates statically unreachable edges, but the call must still infer Literal[1]. The three SymPy-only additions are consistent with newly inferred return/value types feeding existing assignment and optional-member checks. This is likely caused by the PR, but the raw artifact lacks the enclosing functions and exact ecosystem revision, so it is not yet possible to determine whether the newly retained None/Expr branches are correct or an inference regression. No assertion failure or complete type erasure was recorded; Unknown appears as one union member while concrete alternatives remain.

Uncertainty / next check: Resolve the exact SymPy checkout and inspect the producers used at exprtools.py:776 and test_expr.py:1382/1384. A minimal control should keep the same repeated falsy-flow pattern, then compare a definitely-bytes/non-None call with a call that can return Expr/None; the former should pass and the latter should retain the new errors.

zope.interface: Call-site inference now widens synthesized interface-class results with Any and drops four registry assignment errors, so invalid writes and member/call misuse may no longer be reliably rejected.

Regression warning signals require review, regardless of the AI assessment:

  • Changed diagnostic details introduce Any/Unknown.

AI assessment: Possible regression (medium confidence). PR attribution: Likely caused by the PR.

Before / baseline evidence: Across interface.py and declarations.py, baseline detail lines described synthesized `_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass` values and emitted separate member/call diagnostics for retained alternatives. In test_registry.py:2785, 2801, 2990, and 3006, assigning object to typed `provided` attributes produced assignment errors. These are observed baseline diagnostics; the asterisk semantics are checker display metadata, not runtime types.

After / PR evidence: The same interface-class paths are now reported as `Any | _InterfaceClassWithCustomMethods | InterfaceClass`. Numerous member/call messages are consolidated or disappear, and all four test_registry assignment headers vanish. Some remaining errors are plausibly better: for example, members implemented by Specification are no longer separately rejected. But the new Any arm and lost assignment checks are precision loss, not merely rewritten wording.

Why this matters: Downstream code can no longer rely on Pyright consistently preserving the specialized interface-class API or rejecting an arbitrary object assigned to `provided`. An Any union arm can suppress member, argument, callability, comparison, and assignment validation; loss of outer/synthesized type information matters even if some previous unknown-member reports were false positives. Runtime behavior need not change for this to be a checker regression.

Causal analysis:

The PR lowers Binder complexity by omitting statically and structurally unreachable label antecedents. Its test shows this can activate call-site return inference that the baseline complexity guard skipped. zope.interface constructs rich class-like interface objects through unannotated, flow-heavy machinery; activating a different inference path can replace the prior synthesized starred return forms with a union containing Any. That causal path matches the broad, coherent detail transition and the vanished registry checks. Counterevidence is that Specification defines several members previously reported missing, so part of the diagnostic reduction may be a genuine improvement. It does not account for Any entering the result or for unrelated object-to-provided assignments becoming accepted. Because the exact zope checkout and a baseline/head reveal at a representative constructor were not resolved, this remains a credible regression rather than a proven defect.

Uncertainty / next check: Resolve the exact ecosystem SHA and reveal the result of one affected interface constructor on baseline and head. Positive control: `_calculate_sro`, `changed`, and comparison remain usable. Negative controls: a nonexistent member/call and assigning object to typed `provided` must still fail. Also test just below/above the complexity threshold to isolate the new inference path.

apprise: Restored call-site inference now carries a possible None into two Office 365 int conversions, so Pyright newly rejects conversions that were previously unchecked at those locations.

Regression warning signals require review, regardless of the AI assessment:

  • Changed diagnostic details introduce Any/Unknown.

AI assessment: Expected improvement (medium confidence). PR attribution: Likely caused by the PR.

Before / baseline evidence: The baseline emitted no diagnostic at office365.py:1067:29 or 1108:29. The artifact contains no baseline reveal, so this establishes absence of checking at those calls, not that the argument was previously inferred as a particular safe type. The exact Apprise checkout was not recorded in the available source-run logs.

After / PR evidence: At both Office 365 locations, the argument to int is inferred as `Unknown | Any | None`; Pyright reports that this is incompatible with `_ConvertibleToInt`. The concrete None arm is enough to make each conversion unsafe. Unknown and Any indicate incomplete precision, but the outer int call is still checked rather than erased to Any.

Why this matters: Consumers can no longer rely on these conversions passing static analysis without a None guard or a stronger producer annotation. The added diagnostics can prevent a possible invalid `int(None)` path and encourage narrowing. This is a static checking improvement even without proof of a runtime failure, though the Unknown/Any arms mean useful information is still missing.

Causal analysis:

The PR changes flow complexity so label antecedents known unreachable by structure or static condition no longer consume the complexity budget. This can let Pyright perform call-site return inference for a flow-heavy unannotated helper where the baseline hit the cutoff. The exact-head test demonstrates that intended route with repeated statically-falsy `or {}` expressions and a recovered Literal[1] return. The two Apprise additions are consistent with the newly analyzed producer returning a union that preserves None into existing `int` overload checking. Unlike the zope.interface signal, the result has not become bare Any: Pyright retains a concrete unsafe alternative and emits a useful argument error. The remaining uncertainty is whether surrounding control flow should have narrowed None before these calls; absent that invariant, the diagnostics are expected improvements rather than regressions.

Uncertainty / next check: Confirm the exact Apprise revision and inspect the producer and guards feeding lines 1067 and 1108. A minimal positive control should pass a definitely numeric/string value through the same flow and type-check; a negative control should preserve a possible None and continue to fail. Reveal both arguments to determine whether Unknown/Any can also be eliminated.

Full evidence and limitations: download mypy-primer-analysis-report from this analysis run.
The original raw primer comment is unchanged. Treat uncertainty and possible regressions as requests for human review.

@crypt0lith

crypt0lith commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

I checked the project revisions from the mypy_primer analysis. All 3 findings come from main's inference running on functions that used to bail, as expected. They mostly appear to be true positives, and a pre-existing issue was surfaced:

  • Calling an inferred metaclass type[type[X]] gives an instance X instead of a class type[X]. This is from cls = type(cls)(...) in zope's InterfaceClass.__new__ at line 733.
AI disclosure: this text is AI-generated

Checked against the project revisions primer cloned (sympy 2542c76f5, zope.interface c22096908, apprise 7423ce7ed). Every delta comes from functions that now fall under a code flow complexity limit and get the return type main's inference already produces for them, instead of Unknown.

apprise: both new errors are true positives. _fetch (apprise/plugins/office365.py:1123) returns either {} or json.loads(...), so response.get("expires_in") includes None, and int(...) on it is reported at apprise/plugins/office365.py:1067 and apprise/plugins/office365.py:1108. The code catches that TypeError itself (apprise/plugins/office365.py:1070-1072).

sympy:

zope.interface: InterfaceClass.__new__ (src/zope/interface/interface.py:705-739) has attrs = attrs or {} and ... else {}, and now gets call-site return type inference.

This branch was previously deployed

1 inactive (outdated) deployment
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.

4 participants