Skip to content

Rebase attributes facets when base type is replaced - #5112

Open
tonyyuyiding wants to merge 1 commit into
facebook:mainfrom
tonyyuyiding:fix/rebase-attribute
Open

tonyyuyiding wants to merge 1 commit into
facebook:mainfrom
tonyyuyiding:fix/rebase-attribute

Conversation

@tonyyuyiding

@tonyyuyiding tonyyuyiding commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #5016

  • I am a human, and I fully understand the code I am submitting.

This PR fixes the core problem in the original issue. I left a comment under the issue for two follow-ups that this PR does not cover. Please check #5016 (comment)

The script below shows the core problem. The if o.x: pass writes an attribute facet for x (int | None). isinstance then replaces the base type A with B, but the facet is left unchanged. Therefore, when the attribute is read from facets, we get the outdated record.

from dataclasses import dataclass
from typing import reveal_type

@dataclass(frozen=True)
class A:
    x: int | None

@dataclass(frozen=True)
class B(A):
    x: int

def f(o: A):
    if o.x: pass
    if isinstance(o, B):
        reveal_type(o.x)  # expected: int, got: int | None

In the PR, I added a rebase step after type change, which updates the records in facets according to the new ty by intersecting with the attributes defined in the class.

Test Plan

A test has been added in attribute_narrow.rs

@meta-cla meta-cla Bot added the cla signed label Oct 6, 2026
@github-actions github-actions Bot added the size/s label Oct 6, 2026
@meta-codesync

meta-codesync Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D123601975. (Because this pull request was imported automatically, there will not be any future comments.)

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

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

============================================================
SUMMARY
============================================================
Total: +6 new errors, -9 fixed errors
By preset: +0/-2 (default), +0/-2 (strict)

Projects with changes (4):
  mitmproxy: +1 -5
  jax: +5 -0
  pandas: +0 -3
  werkzeug: +0 -1
============================================================

FULL DIFF DETAILS
------------------------------------------------------------

mitmproxy (https://github.com/mitmproxy/mitmproxy)
- ERROR mitmproxy/addons/export.py:22:15-31: The type of `request` is unknown; it is inferred as an implicit `Any` [unknown-variable-type]
- ERROR mitmproxy/addons/export.py:24:12-19: Returning implicit Any from function declared to return "Request" [no-any-return-implicit]
- ERROR mitmproxy/addons/export.py:43:12-20: Returning implicit Any from function declared to return "Response" [no-any-return-implicit]
+ ERROR mitmproxy/flowfilter.py:523:21-40: Implicit conversion of `list[Question]` to `bool` is not allowed [implicit-bool]
- ERROR mitmproxy/flowfilter.py:521:40-60: The type of this argument is unknown [unknown-argument-type]
- ERROR mitmproxy/flowfilter.py:523:60-87: The type of this argument is unknown [unknown-argument-type]

jax (https://github.com/google/jax)
+ ERROR jax/_src/pallas/mosaic_gpu/lowering.py:392:46-56: The type of this argument is unknown [unknown-argument-type]
+ ERROR jax/_src/pallas/mosaic_gpu/lowering.py:400:63-73: The type of this argument is unknown [unknown-argument-type]
+ ERROR jax/_src/pallas/mosaic_gpu/lowering.py:405:64-74: The type of this argument is unknown [unknown-argument-type]
+ ERROR jax/_src/pallas/mosaic_gpu/lowering.py:3681:56-72: The type of this argument is unknown [unknown-argument-type]
+ ERROR jax/_src/pallas/mosaic_gpu/lowering.py:3689:56-72: The type of this argument is unknown [unknown-argument-type]

pandas (https://github.com/pandas-dev/pandas)
- ERROR pandas/core/reshape/merge.py:2682:21-43: The type of this argument is unknown [unknown-argument-type]
- ERROR pandas/core/reshape/merge.py:2691:32-63: Object of type `ExtensionDtype | dtype | Unknown` has no attribute `pyarrow_dtype` [missing-attribute]
- ERROR pandas/tests/indexes/test_old_base.py:602:63-74: The type of this argument is unknown [unknown-argument-type]

werkzeug (https://github.com/pallets/werkzeug)
- ERROR tests/test_local.py:208:12-41: `in` is not supported between `Literal['int(']` and `None` [not-iterable]

@tonyyuyiding
tonyyuyiding marked this pull request as ready for review October 6, 2026 11:43
@github-actions
github-actions Bot requested a review from maggiemoss October 7, 2026 09:13

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect type narrowing via isinstance after temporary type narrowing on initial object

2 participants