Skip to content

Bind methods whose type is a union with Any (#5234) - #5234

Closed
kinto0 wants to merge 2 commits into
facebook:mainfrom
kinto0:export-D125249508
Closed

kinto0 wants to merge 2 commits into
facebook:mainfrom
kinto0:export-D125249508

Conversation

@kinto0

@kinto0 kinto0 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Fixes #5233

make_bound_method_helper gave up on binding a union as soon as one member could not be bound. Any can never be bound, so in function | Any the function member was left unbound, and its first argument got passed as self. Binding Any just gives Any, so now Any members pass through and the other members are still bound.

Differential Revision: D125249508

@meta-cla meta-cla Bot added the cla signed label Oct 14, 2026
@meta-codesync

meta-codesync Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

@kinto0 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D125249508.

@github-actions

This comment has been minimized.

Summary: Adds a test that shows the current behavior: when a method's decorator returns `T | Any`, the method isn't bound to the instance, so its first argument gets passed as `self`. This is the bug in facebook#5233. The next diff fixes it.

Differential Revision: D125250508
@meta-codesync meta-codesync Bot changed the title Bind methods whose type is a union with Any Bind methods whose type is a union with Any (#5234) Oct 14, 2026
@kinto0
kinto0 force-pushed the export-D125249508 branch from c128dc5 to d24fade Compare October 14, 2026 17:53
kinto0 added a commit to kinto0/pyrefly that referenced this pull request Oct 14, 2026
Summary:

Fixes facebook#5233

`make_bound_method_helper` gave up on binding a union as soon as one member could not be bound. `Any` can never be bound, so in `function | Any` the function member was left unbound, and its first argument got passed as `self`. Binding `Any` just gives `Any`, so now `Any` members pass through and the other members are still bound.

Differential Revision: D125249508
@github-actions github-actions Bot added size/m and removed size/s labels Oct 14, 2026
kinto0 added a commit to kinto0/pyrefly that referenced this pull request Oct 14, 2026
Summary:

Fixes facebook#5233

`make_bound_method_helper` gave up on binding a union as soon as one member could not be bound. `Any` can never be bound, so in `function | Any` the function member was left unbound, and its first argument got passed as `self`. Binding `Any` just gives `Any`, so now `Any` members pass through and the other members are still bound.

Differential Revision: D125249508
@kinto0
kinto0 force-pushed the export-D125249508 branch from d24fade to 3834c24 Compare October 14, 2026 17:55
@github-actions github-actions Bot added size/s and removed size/m labels Oct 14, 2026
kinto0 added a commit to kinto0/pyrefly that referenced this pull request Oct 14, 2026
Summary:
Pull Request resolved: facebook#5234

Fixes facebook#5233

`make_bound_method_helper` gave up on binding a union as soon as one member could not be bound. `Any` can never be bound, so in `function | Any` the function member was left unbound, and its first argument got passed as `self`. Binding `Any` just gives `Any`, so now `Any` members pass through and the other members are still bound.

Differential Revision: D125249508
@kinto0
kinto0 force-pushed the export-D125249508 branch from 3834c24 to bd60a00 Compare October 14, 2026 17:57
@github-actions github-actions Bot added size/m and removed size/s labels Oct 14, 2026
Summary:
Pull Request resolved: facebook#5234

Fixes facebook#5233

`make_bound_method_helper` gave up on binding a union as soon as one member could not be bound. `Any` can never be bound, so in `function | Any` the function member was left unbound, and its first argument got passed as `self`. Binding `Any` just gives `Any`, so now `Any` members pass through and the other members are still bound.

Differential Revision: D125249508
@kinto0
kinto0 force-pushed the export-D125249508 branch from bd60a00 to aaa59a2 Compare October 14, 2026 18:02
@github-actions github-actions Bot added size/s and removed size/m labels Oct 14, 2026

@stroxler stroxler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@github-actions

Copy link
Copy Markdown

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

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

Projects with changes (3):
  freqtrade: +0 -2
  core: +0 -70
  optuna: +0 -10
============================================================

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

freqtrade (https://github.com/freqtrade/freqtrade)
- ERROR freqtrade/rpc/rpc.py:429:63-85: Argument `Literal['close_profit_abs']` is not assignable to parameter `self` with type `Row[float | None]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR freqtrade/rpc/rpc.py:429:63-85: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]

core (https://github.com/home-assistant/core)
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:100:21-36: Argument `Literal['start']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:100:21-36: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:100:55-76: Argument `Literal['metadata_id']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:100:55-76: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:102:21-36: Argument `Literal['start']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:102:21-36: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:103:27-48: Argument `Literal['metadata_id']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:103:27-48: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:106:30-42: Argument `Literal['id']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:106:30-42: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:216:28-50: Argument `Literal['statistic_id']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:216:28-50: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:217:28-50: Argument `Literal['statistic_id']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:217:28-50: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:219:30-42: Argument `Literal['id']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/auto_repairs/statistics/duplicates.py:219:30-42: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/migration.py:1448:44-60: Argument `Literal['id']` is not assignable to parameter `self` with type `Row[int]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/migration.py:1448:44-60: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/migration.py:1455:41-57: Argument `Literal['id']` is not assignable to parameter `self` with type `Row[int]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/migration.py:1455:41-57: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/migration.py:1456:35-55: Argument `Literal['start']` is not assignable to parameter `self` with type `Row[datetime | None, datetime | None, float | None, float | None]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/migration.py:1456:35-55: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/migration.py:1457:40-65: Argument `Literal['last_reset']` is not assignable to parameter `self` with type `Row[datetime | None, datetime | None, float | None, float | None]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/migration.py:1457:40-65: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/migration.py:1458:35-55: Argument `Literal['state']` is not assignable to parameter `self` with type `Row[datetime | None, datetime | None, float | None, float | None]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/migration.py:1458:35-55: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/migration.py:1459:33-51: Argument `Literal['sum']` is not assignable to parameter `self` with type `Row[datetime | None, datetime | None, float | None, float | None]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/migration.py:1459:33-51: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:1535:39-51: Argument `Literal['max']` is not assignable to parameter `self` with type `Row[Any]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:1535:39-51: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:1543:20-32: Argument `Literal['avg']` is not assignable to parameter `self` with type `Row[Any]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:1543:20-32: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:1549:42-55: Argument `Literal['mean']` is not assignable to parameter `self` with type `Row[Any]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:1549:42-55: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:1550:31-51: Argument `Literal['mean_weight']` is not assignable to parameter `self` with type `Row[Any]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:1550:31-51: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:1553:39-51: Argument `Literal['min']` is not assignable to parameter `self` with type `Row[Any]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:1553:39-51: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:1646:43-60: Argument `Literal['start_ts']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:1646:43-60: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:1665:43-60: Argument `Literal['start_ts']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:1665:43-60: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:1708:16-28: Argument `Literal['sum']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:1708:16-28: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:1802:16-28: Argument `Literal['sum']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:1802:16-28: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:2056:40-55: Argument `Literal['metadata_id']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:2056:40-55: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:2070:51-58: Argument `Literal['sum']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:2070:51-58: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:2072:43-50: Argument `Literal['sum']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:2072:43-50: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:2763:12-21: Argument `Literal['id']` is not assignable to parameter `self` with type `Row[int]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:2763:12-21: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:2960:20-32: Argument `Literal['id']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:2960:20-32: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:3069:49-55: Argument `Literal['id']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:3069:49-55: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:3071:37-45: Argument `Literal['mean']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:3071:37-45: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:3072:36-43: Argument `Literal['min']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:3072:36-43: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:3073:36-43: Argument `Literal['max']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:3073:36-43: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:3074:38-47: Argument `Literal['state']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:3074:38-47: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/statistics.py:3075:36-43: Argument `Literal['sum']` is not assignable to parameter `self` with type `Row[*tuple[Unknown, ...]]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/statistics.py:3075:36-43: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR homeassistant/components/recorder/table_managers/states.py:105:18-43: Argument `Literal['last_updated_ts']` is not assignable to parameter `self` with type `Row[Any]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR homeassistant/components/recorder/table_managers/states.py:105:18-43: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]

optuna (https://github.com/optuna/optuna)
- ERROR optuna/storages/_rdb/storage.py:440:42-56: Argument `Literal['study_id']` is not assignable to parameter `self` with type `Row[int, str]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR optuna/storages/_rdb/storage.py:440:42-56: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR optuna/storages/_rdb/storage.py:441:46-60: Argument `Literal['study_id']` is not assignable to parameter `self` with type `Row[int, str]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR optuna/storages/_rdb/storage.py:441:46-60: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR optuna/storages/_rdb/storage.py:442:50-64: Argument `Literal['study_id']` is not assignable to parameter `self` with type `Row[int, str]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR optuna/storages/_rdb/storage.py:442:50-64: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR optuna/storages/_rdb/storage.py:445:36-52: Argument `Literal['study_name']` is not assignable to parameter `self` with type `Row[int, str]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR optuna/storages/_rdb/storage.py:445:36-52: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]
- ERROR optuna/storages/_rdb/storage.py:450:34-48: Argument `Literal['study_id']` is not assignable to parameter `self` with type `Row[int, str]` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [bad-argument-type]
- ERROR optuna/storages/_rdb/storage.py:450:34-48: Missing argument `name` in function `sqlalchemy.engine._row_cy.BaseRow.__getattribute__` [missing-argument]

@meta-codesync meta-codesync Bot closed this in 98fc9f2 Oct 14, 2026
@meta-codesync meta-codesync Bot added the Merged label Oct 14, 2026
@meta-codesync

meta-codesync Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in 98fc9f2.

@kinto0 kinto0 added this to the v1.4 milestone Oct 14, 2026
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.

Decorated method returning Callable | Any isn't bound on attribute access

2 participants