-
Notifications
You must be signed in to change notification settings - Fork 135
Closed
Labels
bidirectional inferenceInference of types that takes into account the context of a declared type or expected typeInference of types that takes into account the context of a declared type or expected typegenericsBugs or features relating to ty's generics implementationBugs or features relating to ty's generics implementation
Description
Summary
Thank you so much for ty, it's already much better than the alternatives in both speed and ease of setup.
The error I'm seeing suggests that ty currently does not resolve Literal values into their actual types.
E.g., ty fails this code
import xml.etree.ElementTree as ET
testsuites = ET.Element("testsuites")
testsuite = ET.SubElement(testsuites, "testsuite")
# ^^^^^^^^^^ Expected `Element[str]`, found `Element[Literal["testsuites"]]`
Full output:
❯❯❯ ty check ty_error.py
error: lint:invalid-argument-type: Argument to this function is incorrect
--> ty_error.py:4:27
|
3 | testsuites = ET.Element("testsuites")
4 | testsuite = ET.SubElement(testsuites, "testsuite")
| ^^^^^^^^^^ Expected `Element[str]`, found `Element[Literal["testsuites"]]`
5 | # ^^^^^^^^^^ Expected `Element[str]`, found `Element[Literal["testsuites"]]`
|
info: Function defined here
--> stdlib/xml/etree/ElementTree.pyi:140:5
|
138 | def __bool__(self) -> bool: ...
139 |
140 | def SubElement(parent: Element, tag: str, attrib: dict[str, str] = ..., **extra: str) -> Element: ...
| ^^^^^^^^^^ --------------- Parameter declared here
141 | def Comment(text: str | None = None) -> _CallableElement: ...
142 | def ProcessingInstruction(target: str, text: str | None = None) -> _CallableElement: ...
|
info: `lint:invalid-argument-type` is enabled by default
Found 1 diagnostic
Expected behavior: ty should not fail this code.
Tested it with both ty-0.0.0a7 and ty-0.0.0a8 (commit 994caa6fcc2fdc7ab5e56dd1b86e3075aa404b9a)
Version
No response
lancelote
Metadata
Metadata
Assignees
Labels
bidirectional inferenceInference of types that takes into account the context of a declared type or expected typeInference of types that takes into account the context of a declared type or expected typegenericsBugs or features relating to ty's generics implementationBugs or features relating to ty's generics implementation