Skip to content

Conversation

@Gankra
Copy link
Contributor

@Gankra Gankra commented Oct 16, 2025

This is a drive-by improvement that I stumbled backwards into while looking into

I was writing some simple tests for "thing not in old version of stdlib" diagnostics and checked what was added in 3.14, and saw compression.zstd and to my surprise discovered that import compression.zstd and from compression import zstd had completely different quality diagnostics.

This is because compression and compression.zstd were both introduced in 3.14, and so per VERSIONS policy only an entry for compression was added, and so we don't actually have any definite info on compression.zstd and give up on producing a diagnostic. However the from compression import zstd form fails on looking up compression and we do have an exact match for that, so it gets a better diagnostic!

(aside: I have now learned about the VERSIONS format and I really wish they would just enumerate all the submodules but, oh well!)

The fix is, when handling an import failure, if we fail to find an exact match we requery with the parent module. In cases like compression.zstd this lets us at least identify that, hey, not even compression exists, and luckily that fixes the whole issue. In cases where the parent module and submodule were introduced at different times then we may discover that the parent module is in-range and that's fine, we don't produce the richer stdlib diagnostic.

@Gankra Gankra added the ty Multi-file analysis & type inference label Oct 16, 2025
@Gankra Gankra requested a review from carljm as a code owner October 16, 2025 01:34
@Gankra Gankra added the diagnostics Related to reporting of diagnostics. label Oct 16, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 16, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@github-actions
Copy link
Contributor

github-actions bot commented Oct 16, 2025

mypy_primer results

Changes were detected when running on open source projects
scikit-build-core (https://github.com/scikit-build/scikit-build-core)
- src/scikit_build_core/build/_wheelfile.py:51:22: error[no-matching-overload] No overload of function `field` matches arguments
- Found 52 diagnostics
+ Found 51 diagnostics
No memory usage changes detected ✅

@Gankra
Copy link
Contributor Author

Gankra commented Oct 16, 2025

(Broken into two commits so you can see the before and after on the snapshot)

@Gankra
Copy link
Contributor Author

Gankra commented Oct 16, 2025

Can't help but wonder if we could statically precompute a Complete VERSIONS map...

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.

Ahh thank you!!

Copy link
Member

Choose a reason for hiding this comment

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

Ah nice -- can you move these existing tests to this file so that all our tests for this feature are in the same place?

## Attempting to import a stdlib module that's not yet been added
<!-- snapshot-diagnostics -->
```toml
[environment]
python-version = "3.10"
```
```py
import tomllib # error: [unresolved-import]
from string.templatelib import Template # error: [unresolved-import]
from importlib.resources import abc # error: [unresolved-import]
```
## Attempting to import a stdlib module that was previously removed
<!-- snapshot-diagnostics -->
```toml
[environment]
python-version = "3.13"
```
```py
import aifc # error: [unresolved-import]
from distutils import sysconfig # error: [unresolved-import]
```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did this but I completely misread the direction you wanted this to go so instead my new test file is deleted and I added a new test to basic.md

Copy link
Member

Choose a reason for hiding this comment

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

Haha, I don't mind either way, I'd just like all the tests for the feature to be together!

@Gankra Gankra force-pushed the gankra/old-python-version branch from 8f49ef0 to d08d591 Compare October 16, 2025 13:10
@Gankra Gankra enabled auto-merge (squash) October 16, 2025 13:13
@Gankra Gankra merged commit 6a1e91c into main Oct 16, 2025
40 checks passed
@Gankra Gankra deleted the gankra/old-python-version branch October 16, 2025 13:25
dcreager added a commit that referenced this pull request Oct 16, 2025
…rable

* origin/main:
  [ty] Support dataclass-transform `field_specifiers` (#20888)
  Bump 0.14.1 (#20925)
  Standardize syntax error construction (#20903)
  [`pydoclint`] Implement `docstring-extraneous-parameter` (`DOC102`) (#20376)
  [ty] Fix panic 'missing root' when handling completion request (#20917)
  [ty] Run file watching tests serial when using nextest (#20918)
  [ty] Add version hint for failed stdlib attribute accesses (#20909)
  More CI improvements (#20920)
  [ty] Check typeshed VERSIONS for parent modules when reporting failed stdlib imports (#20908)
dcreager added a commit that referenced this pull request Oct 17, 2025
* main:
  [ty] Prefer declared type for invariant collection literals (#20927)
  [ty] Don't track inferability via different `Type` variants (#20677)
  [ty] Use declared variable types as bidirectional type context (#20796)
  [ty] Avoid unnecessarily widening generic specializations (#20875)
  [ty] Support dataclass-transform `field_specifiers` (#20888)
  Bump 0.14.1 (#20925)
  Standardize syntax error construction (#20903)
  [`pydoclint`] Implement `docstring-extraneous-parameter` (`DOC102`) (#20376)
  [ty] Fix panic 'missing root' when handling completion request (#20917)
  [ty] Run file watching tests serial when using nextest (#20918)
  [ty] Add version hint for failed stdlib attribute accesses (#20909)
  More CI improvements (#20920)
  [ty] Check typeshed VERSIONS for parent modules when reporting failed stdlib imports (#20908)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Related to reporting of diagnostics. ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants