facebook / facebook/pyrefly

Definitions under `TYPE_CHECKING` should not be importable

Open
#3,629 2 comments 0 reactions 0 assignees View on GitHub
typechecking
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

In trying to make our codebase generally compliant with [quoted annotations](https://docs.astral.sh/ruff/settings/#lint_flake8-type-checking_quote-annotations), we ran into the issue of identifying modules that were unintentionally importing definitions as a re-export, rather from the file of definitional source of truth.

When converting to quoted annotations, these re-exports become nested in a conditional, and should no longer be importable to other modules. However, pyrefly does not flag this.

Similar to https://github.com/facebook/pyrefly/issues/3624, we should not include these declarations.

### Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN0AVAJoAFAKIB9AMIAJMVIDSASQByAcQA66LRDCDRk2fOXrEWuhbr46AXjoBGEABoQ2EuURVadNFjzWuHj4rZxAyShgwKFJCBlooCgBiOhFSCKjSHwwcAjoAY1x0SDYAV0pUBghCwi1kgGUYGDoACwYGYjhEAHou8Mjowl42Lph0LsxcPLgugqKIUvLKwq66MF46VAA3VGhUbFh8wuKyiqr0OlxiJfQ4GvQyBmbCgFpNmEo4M9s6DRAAZkI9gATL8tABtd7UD4AXS0JXQgV4DBgmGemAgETylTe3wA5PN0LwYLitISGM8IgBHEoYlHPADWMFIz1QeTy8DgeIA7qhKOgSegQABfFys7EwABi0BgFDcZGFQA

### (Only applicable for extension issues) IDE Information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.