Skip to content

Inlay hint insertion should consider imports/use qualified paths to auto import correctly  #317

@ckuethe

Description

@ckuethe

Describe the Bug

When letting pyrefly suggest type annotations on code that imports re and calls functions like re.compile, the suggested annotation do not include the full module name, at least not in VSCode.

I would have expected that if I import re, and use re.compile(), the inferred type would be re.Pattern, instead of Pattern. What if I'm also using another package that has a different something also called Pattern? I see that same pattern with argparse. If I import argparse and say ap = argparse.ArgumentParser(), the inferred type is ArgumentParser, not argparse.ArgumentParser, and the type of ap.parse_args() is inferred as NameSpace, not argparse.NameSpace.

Image

Also, what do you think about automatically importing Any with from typing import Any if I haven't already done so and pyrefly is suggesting list[Any]? If I accept that suggestion without having imported Any, VSCode tells me it "Could not find name AnyPyrefly(unknown-name)"

Sandbox Link

https://pyrefly.org/sandbox/?code=JYWwDg9gTgLgBFApgKFJWcCGUDmZsDOicAxHAO4AWEcAJhIgXDJcAQPyrjTy2YyIYoYmQA2ggORMCmAJ5wAkhJB0IwAHY4so0XADWG2kwgAzOAGNM49XyhwCMAK4mTAOmTJ88ALwJEr8whwYHEACgkTQxBECQBKUntqR1FadQl4FjY4ACNiAAMkVwAFfgEodQBtBygAXTyAGjh1CHgAK0cHODySmDL1PM4kAmSfOC9XSJsrUXDs5xNEOxwGJkpFmPiyOfgqdbgsgEF1eVpEScRaTg9MMDhfbDxCfwPcR2j1GBKoIihQ+OQbq5MLRaAB9B5vRAfcIAWgAbhJGhIYfDFtkIEREXQzpgRt4AGJWIiNTDmIQQdTeKQwaCIUEwKCODYA3BMe5gVz4b50h4EP4JYBmG77Jh5B5coiuF44SEfL4-BqKCS0OCIAAeYEQZOYrCYNJy+XFT1cADlMNEAMr4cyIPIeZrkO50fiCYSuPgCITRVwO-lbRzwPIe13RPJYJhoHgXEVYOAgCC0ZL+VyuIA

(Only applicable for extension issues) IDE Information

Pyrefly 0.16.1, Code 1.100.2-1747260578, Python 3.12.3, on Ubuntu 24LTS in case that matters.

Metadata

Metadata

Assignees

Labels

UserBugs reported by external users that should be prioritisedcodenav

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions