Skip to content

Panic if --typeshed is set to a subdirectory of a first-party search path #523

@kkpattern

Description

@kkpattern

Reproduce step

  1. create a file named main.py with the following content:
def add(a: int, b: int) -> int:
    return a + b

add(1, "2")
  1. Execute the following commands:
git clone https://github.com/python/typeshed.git
cd typeshed
git checkout ea39b363e02f47debdf583dd88b477e0b0bd546d
cd ..
ty check --typeshed typeshed main.py

Output:

error[panic]: Panicked at /root/.cargo/git/checkouts/salsa-e6f3bb7c2a062968/4818b15/src/function/fetch.rs:143:25 when checking `/home/.../ty-playground/main.py`: `dependency graph cycle when querying try_call_dunder_get_(Id(6802)), set cycle_fn/cycle_initial to fixpoint iterate.
Query stack:
[
    check_types(Id(c00)),
    infer_scope_types(Id(1000)),
    explicit_bases_(Id(2c02)),
    infer_deferred_types(Id(32c8)),
    explicit_bases_(Id(2c03)),
    infer_deferred_types(Id(50cc)),
    explicit_bases_(Id(2c04)),
    infer_deferred_types(Id(505e)),
    explicit_bases_(Id(2c05)),
    infer_deferred_types(Id(5056)),
    infer_definition_types(Id(5014)),
    infer_expression_types(Id(24ac)),
    symbol_by_id(Id(2806)),
    infer_expression_type(Id(248b)),
    infer_expression_types(Id(248b)),
    member_lookup_with_policy_(Id(4c01)),
    symbol_by_id(Id(2807)),
    infer_definition_types(Id(550b)),
    explicit_bases_(Id(2c0c)),
    infer_deferred_types(Id(550a)),
    infer_definition_types(Id(5488)),
    explicit_bases_(Id(2c15)),
    infer_deferred_types(Id(6c8b)),
    infer_definition_types(Id(57ca)),
    infer_expression_types(Id(254e)),
    try_call_dunder_get_(Id(6802)),
    class_member_with_policy_(Id(6409)),
    symbol_by_id(Id(280f)),
    infer_definition_types(Id(1453)),
    signature_(Id(4005)),
    infer_deferred_types(Id(5019)),
    infer_definition_types(Id(500d)),
    infer_expression_types(Id(24a5)),
    member_lookup_with_policy_(Id(4c12)),
    try_call_dunder_get_(Id(6801)),
    class_member_with_policy_(Id(6406)),
    try_call_dunder_get_(Id(6804)),
    class_member_with_policy_(Id(6410)),
    class_member_with_policy_(Id(6410)),
    infer_definition_types(Id(3b4f)),
    try_mro_(Id(5805)),
]`
info: This indicates a bug in ty.
info: If you could open an issue at https://github.com/astral-sh/ty/issues/new?title=%5Bpanic%5D, we'd be very appreciative!
info: Platform: linux x86_64
info: Args: ["ty", "check", "--typeshed", "typeshed", "main.py"]
info: run with `RUST_BACKTRACE=1` environment variable to show the full backtrace information
info: query stacktrace:
   0: infer_expression_types(Id(24a5))
             at crates/ty_python_semantic/src/types/infer.rs:223
             cycle heads: symbol_by_id(Id(2807)) -> 0, symbol_by_id(Id(2806)) -> 0, infer_expression_type(Id(248b)) -> 0, member_lookup_with_policy_(Id(4c01)) -> 0, symbol_by_id(Id(280f)) -> 0, infer_definition_types(Id(1453)) -> 0
   1: infer_definition_types(Id(500d))
             at crates/ty_python_semantic/src/types/infer.rs:149
   2: infer_deferred_types(Id(5019))
             at crates/ty_python_semantic/src/types/infer.rs:187
   3: signature_(Id(4005))
             at crates/ty_python_semantic/src/types.rs:6927
   4: infer_definition_types(Id(1453))
             at crates/ty_python_semantic/src/types/infer.rs:149
             cycle heads: symbol_by_id(Id(2807)) -> 0, symbol_by_id(Id(2806)) -> 0, infer_expression_type(Id(248b)) -> 0, member_lookup_with_policy_(Id(4c01)) -> 0
   5: symbol_by_id(Id(280f))
             at crates/ty_python_semantic/src/symbol.rs:586
   6: class_member_with_policy_(Id(6409))
             at crates/ty_python_semantic/src/types.rs:550
   7: try_call_dunder_get_(Id(6802))
             at crates/ty_python_semantic/src/types.rs:550
   8: infer_expression_types(Id(254e))
             at crates/ty_python_semantic/src/types/infer.rs:223
             cycle heads: symbol_by_id(Id(2806)) -> 0, infer_expression_type(Id(248b)) -> 0, symbol_by_id(Id(2807)) -> 0, member_lookup_with_policy_(Id(4c01)) -> 0
   9: infer_definition_types(Id(57ca))
             at crates/ty_python_semantic/src/types/infer.rs:149
  10: infer_deferred_types(Id(6c8b))
             at crates/ty_python_semantic/src/types/infer.rs:187
  11: explicit_bases_(Id(2c15))
             at crates/ty_python_semantic/src/types/class.rs:551
  12: infer_definition_types(Id(5488))
             at crates/ty_python_semantic/src/types/infer.rs:149
             cycle heads: symbol_by_id(Id(2807)) -> 0, member_lookup_with_policy_(Id(4c01)) -> 0, symbol_by_id(Id(2806)) -> 0, infer_expression_type(Id(248b)) -> 0
  13: infer_deferred_types(Id(550a))
             at crates/ty_python_semantic/src/types/infer.rs:187
  14: explicit_bases_(Id(2c0c))
             at crates/ty_python_semantic/src/types/class.rs:551
  15: infer_definition_types(Id(550b))
             at crates/ty_python_semantic/src/types/infer.rs:149
  16: symbol_by_id(Id(2807))
             at crates/ty_python_semantic/src/symbol.rs:586
  17: member_lookup_with_policy_(Id(4c01))
             at crates/ty_python_semantic/src/types.rs:550
  18: infer_expression_types(Id(248b))
             at crates/ty_python_semantic/src/types/infer.rs:223
  19: infer_expression_type(Id(248b))
             at crates/ty_python_semantic/src/types/infer.rs:279
  20: symbol_by_id(Id(2806))
             at crates/ty_python_semantic/src/symbol.rs:586
  21: infer_expression_types(Id(24ac))
             at crates/ty_python_semantic/src/types/infer.rs:223
  22: infer_definition_types(Id(5014))
             at crates/ty_python_semantic/src/types/infer.rs:149
  23: infer_deferred_types(Id(5056))
             at crates/ty_python_semantic/src/types/infer.rs:187
  24: explicit_bases_(Id(2c05))
             at crates/ty_python_semantic/src/types/class.rs:551
  25: infer_deferred_types(Id(505e))
             at crates/ty_python_semantic/src/types/infer.rs:187
  26: explicit_bases_(Id(2c04))
             at crates/ty_python_semantic/src/types/class.rs:551
  27: infer_deferred_types(Id(50cc))
             at crates/ty_python_semantic/src/types/infer.rs:187
  28: explicit_bases_(Id(2c03))
             at crates/ty_python_semantic/src/types/class.rs:551
  29: infer_deferred_types(Id(32c8))
             at crates/ty_python_semantic/src/types/infer.rs:187
  30: explicit_bases_(Id(2c02))
             at crates/ty_python_semantic/src/types/class.rs:551
  31: infer_scope_types(Id(1000))
             at crates/ty_python_semantic/src/types/infer.rs:122
  32: check_types(Id(c00))
             at crates/ty_python_semantic/src/types.rs:84


Found 1 diagnostic
WARN A fatal error occurred while checking some files. Not all project files were analyzed. See the diagnostics list above for details.

Without the --typeshed ty can work correctly:

error[invalid-argument-type]: Argument to function `add` is incorrect
 --> main.py:4:8
  |
2 |     return a + b
3 |
4 | add(1, "2")
  |        ^^^ Expected `int`, found `Literal["2"]`
  |
info: Function defined here
 --> main.py:1:5
  |
1 | def add(a: int, b: int) -> int:
  |     ^^^         ------ Parameter declared here
2 |     return a + b
  |
info: rule `invalid-argument-type` is enabled by default

Found 1 diagnostic

Version

ty 0.0.1-alpha.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingconfigurationRelated to settings and configurationfatala fatal error (panic or crash)importsModule resolution, site-packages discovery, import-related diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions