This refactoring allows simplifying and unifying logic whilst calculating substitutions for callable types and its matching in `PyTypeChecker`
GitOrigin-RevId: e61bd1f6cf19539b0a66ff2e3e47164aec0c0aa1
For these symbols pyrefly returns non-qualified name that must be resolved further. From performance point of view it's better to specialcase them.
GitOrigin-RevId: 0fa4e85f03ef9df197ccfeef49c92b0118d70dab
The `resolved` parameter in `PyTypingTypeProvider.getTypeForResolvedElement`
is never a `TypedDict(...)` or `NewType(...)` call expression. The corresponding logic handling these cases is unreachable.
GitOrigin-RevId: 1270647014962e403b0620770f5c73700ca9ac52
Non-project files by default are not indexed, do not have a module and do not have an SDK.
`PyExternalFilesIndexService` is resposible for adding a custom entities to the workspace model.
Space-RevId: dd7c50009e56dea0d69914c9f7f1524c7e77fe20
GitOrigin-RevId: cdfa2a578a01431fb9e0a06ce820c1d9b0f3fc0d
Also, some small fixes here and there to ensure it works correctly
Space-RevId: 90f4b41c0eca9aae4c49841d756f7c96f805fcff
GitOrigin-RevId: 844c13869fb113df46537c4a644dbbfb8ba8c977
For the time being, it's possible to declare an intersection type
as "A & B", though it should be either wrapped in a string literal,
used with `from __future__ import annotations` or with Python 3.14+
to avoid runtime errors (and there still be warnings about unresolved
`type.__and__`) and it's not possible to generate a type hint for them.
At least until intersection types are added to the typing specification,
or we adopt something similar to "ty_extensions".
Specific use cases, such as using intersections for type narrowing,
`super()`, overloads, etc. will be addressed separately.
Space-RevId: 16c28a020f0b102f54f56ae25b5c25dc143fd76d
GitOrigin-RevId: d2581559197819fbbc49e4f75b62aa2962924938
So that `Alias = list["int | str"]` is valid, but `Alias = "int | str"` is not.
Writing `Alias: TypeAlias = "int | str"` (explicit type alias), however, is fine.
This behavior is enforced by the conformance test suite, see aliases_implicit.py.
Previously `PyTypeHintsInspectionTest.testImplicitTypeAliasesMultiFile`
passed "by accident" because we didn't consider the string content of
`BadTypeAlias14 = "int | str"` a valid type hint. Properly recognizing
union types in quotes made the test fail, even though the original rule
has nothing to do with union types themselves.
Adding a test on the new behavior revealed several other problems.
First, in PyTypingTypeProvider we completely bypassed well-formedness checks of
`PyTypingAliasStubType.getAssignedValueIfTypeAliasLike` calling directly
`PyTargetExpression.findAssignedValue` in files where AST access was allowed.
Second, `PyTypingAliasStubType.VALID_TYPE_ANNOTATION_ELEMENTS` didn't include
starred expressions, so all type aliases containing unpacked TypeVarTuples
(e.g. `*Ts`) were considered illegal. It broke detecting type parameter scopes
for implicit type aliases in `PyTypingTypeProvider.getTypeParameterScope`, where
`PyTypingAliasStubType.looksLikeTypeHint` is used.
Addressing that also made a correct generic type to be inferred in an existing test
`PyTypingTest.testGenericVariadicsIntersectsSameName`.
Space-RevId: 9629e7e50e82c1df863bd0fe115596e9ed48afed
GitOrigin-RevId: bc0eecfcdaf14d7f2eb53d79950a53fae0d2d273
Use a more permissive regex used for language injections inside type hints
to recognize old style type aliases to be saved in PSI stubs and valid
type hints.
Space-RevId: 3ce489544374c8764db6447438cc3b5f5d2d78cd
GitOrigin-RevId: 776ead0ca9580dbcc6874a84791550289a6f3a9a
The class with the same qualified name is present in intellij.python.parser module, so having a duplicating one is confusing and leads to problems in scripts which analyses class files.
Space-RevId: f2baabd8ed6d66be239394b6c18558da1d3de8ff
GitOrigin-RevId: 379ded2168da297d0308da6523f5ae6d27f9b417
This also avoids calling potentially expensive `hashCode`/`equals` for deeply nested types.
Space-RevId: 269d3e2d1ebf299c3eea45ddcc1955190577bc6f
GitOrigin-RevId: 35e195b49084e0cb0a071db83607117e98e38451
Use the containing PSI element as the context for the type hint code fragment instead of the whole file. This allows resolving symbols within the local scopes.
When looking for a start instruction in `PyDefUseUtil.getLatestDefs()`, use the parent element's instruction if the element itself is missing from the CFG.
Fix resolution of string type hints and comments by allowing forward references in PyExpressionCodeFragment.
Space-RevId: b44603176d5b50b20f9a5964714d3661d71c8a08
GitOrigin-RevId: 715bcd011543c060e0dff965d94fbd8cc6f7e591
Since we use flow-sensitive name resolution for attribute qualifiers,
it's sufficient to check that they don't resolve into definitions other
than the parameter being processed, no need to track reassignments
manually.
GitOrigin-RevId: ea321af075dc1c3a7b58f052b36eaf0ac832e37c
We already had protection against reassignment to a parameter name,
but it didn't take into account that we also skip conditional branches and loops
to collect only definitely accessed attributes of an object, so if reassignments
took place under conditions, even in every branch, they didn't prevent us
from collecting subsequently accessed attributes.
GitOrigin-RevId: d41b8f4c3dbce6643d915923172d32a8e4e6466c