Skip to content

Conversation

@MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Oct 20, 2025

Summary

Ensure that new imports are added after any pre-existing from __future__ import.

Fixes astral-sh/ty#1382

Test Plan

Added test

@MichaReiser MichaReiser added the bug Something isn't working label Oct 20, 2025
@MichaReiser MichaReiser requested a review from sharkdp as a code owner October 20, 2025 09:41
@MichaReiser MichaReiser added the server Related to the LSP server label Oct 20, 2025
@MichaReiser MichaReiser requested a review from dcreager as a code owner October 20, 2025 09:41
@MichaReiser MichaReiser added ty Multi-file analysis & type inference bug Something isn't working server Related to the LSP server labels Oct 20, 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!

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Could you also add a test where the first statement in the file is a docstring and the second statement is a future import?

@MichaReiser MichaReiser reopened this Oct 20, 2025
@github-actions
Copy link
Contributor

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@github-actions
Copy link
Contributor

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@MichaReiser MichaReiser merged commit 24d0f65 into main Oct 21, 2025
238 of 289 checks passed
@MichaReiser MichaReiser deleted the micha/fix-future-import branch October 21, 2025 06:14
dcreager added a commit that referenced this pull request Oct 22, 2025
* main: (65 commits)
  [ty] Some more simplifications when rendering constraint sets (#21009)
  [ty] Make `attributes.md` mdtests faster (#21030)
  [ty] Set `INSTA_FORCE_PASS` and `INSTA_OUTPUT` environment variables from mdtest.py (#21029)
  [ty] Fall back to `Divergent` for deeply nested specializations (#20988)
  [`ruff`] Autogenerate TypeParam nodes (#21028)
  [ty] Add assertions to ensure that we never call `KnownClass::Tuple.to_instance()` or similar (#21027)
  [`ruff`] Auto generate ast Pattern nodes (#21024)
  [`flake8-simplify`] Skip `SIM911` when unknown arguments are present (#20697)
  Render a diagnostic for syntax errors introduced in formatter tests (#21021)
  [ty] Support goto-definition on vendored typeshed stubs (#21020)
  [ty] Implement go-to for binary and unary operators (#21001)
  [ty] Avoid ever-growing default types (#20991)
  [syntax-errors] Name is parameter and global (#20426)
  [ty] Disable panicking mdtest (#21016)
  [ty] Fix completions at end of file (#20993)
  [ty] Fix out-of-order semantic token for function with regular argument after kwargs (#21013)
  [ty] Fix auto import for files with `from __future__` import (#20987)
  [`fastapi`] Handle ellipsis defaults in FAST002 autofix (`FAST002`) (#20810)
  [`ruff`] Skip autofix for keyword and `__debug__` path params (#20960)
  [`flake8-bugbear`] Skip `B905` and `B912` if <2 iterables and no starred arguments (#20998)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working server Related to the LSP server ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto import introduces syntax errors in files with from __future__ import annotations

4 participants