Skip to content

Conversation

@MatthewMckee4
Copy link
Contributor

@MatthewMckee4 MatthewMckee4 commented Jul 7, 2025

Summary

Slightly refactor ClassLiteral.into_callable to also look for __init__ functions of type Type::Callable to fix the issue with dataclasses, as the synthensized init created by dataclass isn't covered as it isn't FunctionLiteral

Fixes astral-sh/ty#760

Test Plan

Add subtype test from the issue

@MatthewMckee4 MatthewMckee4 changed the title Allow callable type for __init__ functions in into_callable for Class… [ty] Fix ClassLiteral.into_callable for dataclasses Jul 7, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jul 7, 2025

mypy_primer results

Changes were detected when running on open source projects
strawberry (https://github.com/strawberry-graphql/strawberry)
- error[invalid-assignment] strawberry/codegen/query_codegen.py:648:13: Object of type `<class 'GraphQLOptional'> | ((t) -> Unknown)` is not assignable to `((Unknown, /) -> Unknown) | None`
- error[invalid-assignment] strawberry/codegen/query_codegen.py:656:13: Object of type `<class 'GraphQLList'> | ((t) -> Unknown)` is not assignable to `((Unknown, /) -> Unknown) | None`
- error[invalid-parameter-default] strawberry/codegen/query_codegen.py:760:9: Default value of type `<class 'GraphQLObjectType'>` is not assignable to annotated parameter type `(str, /) -> GraphQLObjectType`
- Found 359 diagnostics
+ Found 356 diagnostics

bokeh (https://github.com/bokeh/bokeh)
- error[invalid-argument-type] src/bokeh/embed/bundle.py:186:29: Argument to function `__new__` is incorrect: Expected `(str, /) -> Unknown`, found `<class 'URL'>`
- error[invalid-argument-type] src/bokeh/embed/bundle.py:189:30: Argument to function `__new__` is incorrect: Expected `(str, /) -> Unknown`, found `<class 'URL'>`
- Found 858 diagnostics
+ Found 856 diagnostics
No memory usage changes detected ✅

@MichaReiser MichaReiser added the ty Multi-file analysis & type inference label Jul 8, 2025
Copy link
Contributor

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

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

Thank you very much!

Made a minor change to avoid one unnecessary clone.

@sharkdp sharkdp merged commit f32f7a3 into astral-sh:main Jul 9, 2025
37 checks passed
UnboundVariable pushed a commit to UnboundVariable/ruff that referenced this pull request Jul 10, 2025
…re_help

* 'main' of https://github.com/astral-sh/ruff: (34 commits)
  [docs] add capital one to who's using ruff (astral-sh#19248)
  [`pyupgrade`] Keyword arguments in `super` should suppress the `UP008` fix (astral-sh#19131)
  [`flake8-use-pathlib`] Add autofixes for `PTH100`, `PTH106`, `PTH107`, `PTH108`, `PTH110`, `PTH111`, `PTH112`, `PTH113`, `PTH114`, `PTH115`, `PTH117`, `PTH119`, `PTH120` (astral-sh#19213)
  [ty] Do not run `mypy_primer.yaml` when all changed files are Markdown files (astral-sh#19244)
  [`flake8-bandit`] Make example error out-of-the-box (`S412`) (astral-sh#19241)
  [`pydoclint`] Make example error out-of-the-box (`DOC501`) (astral-sh#19218)
  [ty] Add "kind" to completion suggestions
  [ty] Add type information to `all_members` API
  [ty] Expand API of `all_members` to return a struct
  [ty] Ecosystem analyzer PR comment workflow (astral-sh#19237)
  [ty] Merge `ty_macros` into `ruff_macros` (astral-sh#19229)
  [ty] Fix `ClassLiteral.into_callable` for dataclasses (astral-sh#19192)
  [ty] `dataclasses.field` support (astral-sh#19140)
  [ty] Fix panic for attribute expressions with empty value (astral-sh#19069)
  [ty] Return `CallableType` from `BoundMethodType.into_callable_type` (astral-sh#19193)
  [`flake8-bugbear`] Support non-context-manager calls in `B017` (astral-sh#19063)
  [ty] Improved diagnostic for reassignments of `Final` symbols (astral-sh#19214)
  [ty] Use full range for assignment definitions (astral-sh#19211)
  [`pylint`] Update `missing-maxsplit-arg` docs and error to suggest proper usage (`PLC0207`) (astral-sh#18949)
  [ty] Add `set -eu` to mypy-primer script (astral-sh#19212)
  ...

# Conflicts:
#	crates/ty_python_semantic/src/types/class.rs
@MatthewMckee4 MatthewMckee4 deleted the fix-into-callable-class-literal branch July 16, 2025 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dataclass class literal subtyping with callables not working

3 participants