Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[red-knot] all types are assignable to object #15332

Merged
merged 5 commits into from
Jan 7, 2025
Merged

Conversation

carljm
Copy link
Contributor

@carljm carljm commented Jan 7, 2025

Summary

Type[Any] should be assignable to object. All types should be assignable to object.

We specifically didn't understand the former; this PR adds a test for it, and a case to ensure that Type[Any] is assignable to anything that type is assignable to (which includes object).

This PR also adds a property test that all types are assignable to object. In order to make it pass, I added a special case to check early if we are assigning to object and just return true. In principle, once we get all the more general cases correct, this special case might be removable. But having the special case for now allows the property test to pass.

And we add a property test that all types are subtypes of object. This failed for the case of an intersection with no positive elements (that is, a negation type). This really does need to be a special case for object, because there is no other type we can know that a negation type is a subtype of.

Test Plan

Added unit test and property test.

@carljm carljm added the red-knot Multi-file analysis & type inference label Jan 7, 2025
Copy link
Contributor

github-actions bot commented Jan 7, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@carljm carljm merged commit fdca2b4 into main Jan 7, 2025
21 checks passed
@carljm carljm deleted the cjm/assign-to-object branch January 7, 2025 23:19
dcreager added a commit that referenced this pull request Jan 8, 2025
* main:
  [`pylint`] Fix `unreachable` infinite loop (`PLW0101`) (#15278)
  fix invalid syntax in workflow file (#15357)
  [`pycodestyle`] Avoid false positives related to type aliases (`E252`) (#15356)
  [`flake8-builtins`] Disapply `A005` to stub files (#15350)
  Improve logging system using `logLevel`, avoid trace value (#15232)
  [`flake8-builtins`] Rename `A005` and improve its error message (#15348)
  Spruce up docs for pydoclint rules (#15325)
  [`flake8-type-checking`] Apply `TC008` more eagerly in `TYPE_CHECKING` blocks and disapply it in stubs (#15180)
  [red-knot] `knot_extensions` Python API (#15103)
  Display Union of Literals as a Literal (#14993)
  [red-knot] all types are assignable to object (#15332)
  [`ruff`] Parenthesize arguments to `int` when removing `int` would change semantics in `unnecessary-cast-to-int` (`RUF046`) (#15277)
  [`eradicate`] Correctly handle metadata blocks directly followed by normal blocks (`ERA001`) (#15330)
  Narrowing for class patterns in match statements (#15223)
  [red-knot] add call checking (#15200)
  Spruce up docs for `slice-to-remove-prefix-or-suffix` (`FURB188`) (#15328)
  [`internal`] Return statements in finally block point to end block for `unreachable` (`PLW0101`) (#15276)
  [`ruff`] Treat `)` as a regex metacharacter (`RUF043`, `RUF055`) (#15318)
  Use uv consistently throughout the documentation (#15302)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants