Commit Graph

57 Commits

Author SHA1 Message Date
Ilia Zakoulov
91f27d8587 PY-76629: Suppress PyProtectedMemberInspection if a member is defined in .pyi
Protected member should not be highlighted as a warning if it resolves to .pyi file.
We assume that everything in .pyi file is a public API.

GitOrigin-RevId: c8275f3e48e3cd69b1676de9b78606f28ea224c8
2024-10-28 14:57:57 +00:00
lada.gagina
ad5b55918e Revert tests with over-inferring LiteralString
(cherry picked from commit 0c92e1c64362e2834b01b4e0bcbcedfefe4febe0)

IJ-MR-112631

GitOrigin-RevId: 233abfde16b19e96c5bc39c77eef1a240aa1b3e8
2023-11-07 22:10:23 +00:00
Lada Gagina
454b1287ae PY-58857 Infer typing.LiteralString for string literals
GitOrigin-RevId: 27507deabd61faedf7937415016f0f8334e5a418
2023-06-21 16:32:22 +00:00
Mikhail Golubev
d070837f27 PY-38075 Select the first matching overload unless some argument types are unknown
This behavior is similar to how mypy and pyright handle overloads relying on
their definition order, where more specific signatures are supposed to precede
more general ones. The subtle difference is that in case of Any arguments,
pyright tries to find a common supertype for return types of all matching
overloads, mypy just returns Any, and we return a union of their return types.
For the time being, it keeps things simple and matches how we treated ambiguous
signatures before.

To make this work, I've had to revise how we handle name redefinitions in files.
Previously, we processed them in the reversed order to give priority to those
later in a file, which is natural for regular .py files. It doesn't make much
sense for .pyi stubs, though, as it's impossible to redefine a name there and
multiple definitions, e.g. overloads, are supposed to have equal precedence.
Now, we don't reverse the order of name definitions in .pyi stubs at all,
and in .py files we do that preserving the original order of overloads.
A side effect of it is that now we always navigate to the first overload
of a name in a .pyi stub, as opposed to the last, but it only seems more
logical and convenient.

On the other hand, when we handle overloads in .py files, we explicitly
assign to them a lower resolve rate to give precedence to implementations.
The only exception is that when there are no implementations we still want
to prefer the latest overload, so we put it into the results second time
with a higher rate. It messed up overloads order important for type inference,
so I've introduced a dedicated RATE_LIFTED_PY_FILE_OVERLOAD rate for such
results to filter them out later in PyCallExpressionHelper. I've also added
a named RATE_PY_FILE_OVERLOAD rate of other overloads in .py files to make
them more easily distinguishable from other resolve results with a low rate.

GitOrigin-RevId: e921654e47fe1fc5da047950b70775e342996757
2023-03-14 10:56:49 +00:00
Daniil Kalinin
85f5bb3763 Tests for PY-52748 "Force new line after colon" -> "Single-clause statements" should not affect pyi-stubs
GitOrigin-RevId: 976fac3f170923a153e06a3435281f0e3436e1cd
2022-04-04 16:25:45 +00:00
Kazantcev Andrey
448901b1a8 Allow any forward reference in pyi file (PY-49004)
GitOrigin-RevId: 8ea3b8e9e9dbc4e26b274663231d531dc22fcdcc
2021-09-14 18:31:12 +00:00
andrey.matveev
ebe8f93812 PY-44974 PEP 604: Support Python3.10 unions
Support | syntax for python unions.
Also support type | None as a new style for Optional.
Fix highlighting unresolved reference issues with | syntax.
Type inference from isinstance and issubclass.
Add quick fix to switch to old-style syntax in earlier python versions (<3.10)
Fix quick documentation to render new syntax.

(cherry picked from commit 6a64ee12c2d8503a0ef102e8b67cb0b95ce77999)

IJ-MR-8400

GitOrigin-RevId: c26b868fc61f26936a3316ec06f78b66d75f6857
2021-06-14 14:38:25 +00:00
Semyon Proshev
56a1c00c2a Make python-latest project descriptor default in tests
Update test data and reduce manual language level setup

GitOrigin-RevId: d6ddec1b2b29a2b7f1a34cfb5982fd975de78d65
2021-03-15 17:33:04 +00:00
Semyon Proshev
09c1f70856 Don't consider imported element as private if it is presented in dunder all (PY-46169)
GitOrigin-RevId: b9f22ea3c7619f9db5b06e321ed3fe46cbaaea60
2020-12-31 14:04:04 +00:00
Mikhail Golubev
226fb9c27c Restore canonical import paths inside .pyi stubs
Previously, we looked only for __init__.py to detect re-exported names,
ignoring __init__.pyi that could be used for the same purpose in stub
packages.

GitOrigin-RevId: 48bc58789e47d5b9fb814b99722371fdd670ee2d
2020-12-04 15:49:35 +00:00
Semyon Proshev
5344262b4c Remove PyiTypeProvider.getCallType
It will fix PyTypeTest.testListTypeByModificationsConstructor and PyTypeTest.testDictTypeByModificationConstructor.
Callee has been resolved to overloads for a long time, it's better to filter out unmatched ones instead of calculating the same call type for every overload. Implemented in PyCallExpressionHelper.

Unify inferring call type for subscriptions and calls.
Union types order in test data has been changed since named elements are collected in reversed order in py files.
Repeat PyTypeTest.testCallableInUnion behaviour in PyTypeTest.testSubscriptionOnWeakType.
PyCallExpressionHelper.forEveryScopeTakeOverloadsOtherwiseImplementations has been updated to preserve elements order.

GitOrigin-RevId: f88eacd0a36dd5fbc59447db9dd4484d5a000bc8
2020-08-24 18:58:44 +00:00
Mikhail Golubev
bc607f85ed i18n: Extract messages from remaining pure-Python inspection
* PyTypeCheckerInspection
* PyTypedDictInspection
* PyUnnecessaryBackslashInspection
* PyUnresolvedReferencesInspection
* PyUnusedLocalInspectionVisitor
* PyTypeHintsInspection

GitOrigin-RevId: 62d72bf38ef48412baf52960bc9da2b9f6d09070
2020-08-24 13:16:58 +00:00
Semyon Proshev
ad39e8fa7b Disable PyMissingConstructorInspection and PyShadowingBuiltinsInspection in pyi files (PY-33486)
GitOrigin-RevId: f9d12c26c5ce0d69f9f5a07d28f2b35381b5a55c
2020-07-30 20:51:35 +00:00
Mikhail Khorkov
5ccf34e0cd PY-16868 Fix test resource file name (move to uppercase)
GitOrigin-RevId: 54c571e82f0ebdfa49d9c08555cc21c2dc21aaf9
2019-11-13 05:32:13 +00:00
Mikhail Khorkov
77c8ea0b13 PY-16868 Fix test resource folder name (move to lowercase)
GitOrigin-RevId: 9bb22014c09976a5a63ea8b6cdc66b9910cacd37
2019-11-13 05:32:13 +00:00
Mikhail Khorkov
403f8d9d8b PY-16868 Fix test resource file name (move to lowercase)
GitOrigin-RevId: 9b94208736d1e06f15d63c64b6a763c54a7bb05e
2019-11-12 11:34:13 +00:00
Mikhail Khorkov
ba25d399f9 PY-1421 Update test data for all 'unused import' inspection report message
GitOrigin-RevId: 1f0cbb85d9b062265f2b93e2746c11f8e72b0bff
2019-11-12 10:10:18 +00:00
Mikhail Khorkov
274387096d PY-16868 Disable property declaration inspection in .pyi file
We do not need to check property decorator in .pyi files at all.

GitOrigin-RevId: b0a9e06fd462a518437403193c270700158406c2
2019-11-12 08:31:53 +00:00
Semyon Proshev
fb4dbba4f3 Add tests for line markers navigating to stub located in stub package (PY-30942) 2018-10-29 12:10:20 +03:00
Semyon Proshev
c48f15defb Return null if found similar element is the same as the original one 2018-10-15 15:18:36 +03:00
Semyon Proshev
83a321b609 Remove dead code that resolves forward references in annotations 2018-03-13 17:36:51 +03:00
Anton Bragin
bfcf22f7dc PY-28228 Resolve annotation forward references according to PEP 563
Forward references resolution implemented for annotations according to
PEP 563. Inspections fixed to respect forward references for both
annotations and pyi stubs.

PyiReferenceResolveProvider removed since its functionality is now
implemented by PyForwardReferenceResolveProvider.
2018-02-12 11:27:21 +03:00
Semyon Proshev
fb0c5cc58b Support module with __getattr__ while resolving and type checking (PY-28017) 2018-01-22 21:43:35 +03:00
Mikhail Golubev
ae58f4e52a PY-24729 Initial support of instance attributes annotated on class level 2017-12-14 19:00:46 +03:00
Mikhail Golubev
1b13e20a8b Add a test covering another scenario broken due to implementation of getReceiver()
used in PyiTypeProvider. That was fixed in 8eda017f0f
2017-11-30 15:19:58 +03:00
Mikhail Golubev
63f25e8e4d PY-27186 Use generic type information from .pyi stub in the respective .py file
by implementing missing getGenericType() and getGenericSubstitutions()
in PyiTypeProvider.
2017-11-30 15:19:58 +03:00
Semyon Proshev
f7a325c536 Update parameter default value handling.
Don't create `Optional` type for ellipsis default parameter value.
Always include default value even if it is `None`.
2017-08-30 20:38:15 +03:00
Andrey Vlasovskikh
7a3717c7c8 One more test for PY-22808 to cover changes 2017-04-17 18:52:55 +03:00
Andrey Vlasovskikh
1f598fe985 Don't use types of not matched overloads in resulting call type (PY-22808, PY-22741)
We used to exclude all the Any types from matched overloads even though
the match was successful. Now we stop analyzing an overload immediately
when the actual arguments don't match against its parameters.
2017-04-13 21:57:59 +03:00
Semyon Proshev
6a8a56af4b PY-22475 Fixed: Switch multi-parameters handling to multi-resolved functions API
Update registering type checking problems for binary expressions:
* prefer left operators over right ones
* in case of one operator register problem in the old way
* in case of some operators register problem on the left or right argument
2017-03-06 19:43:43 +03:00
Semyon Proshev
b7513de6d5 PY-22475 Fixed: Switch multi-parameters handling to multi-resolved functions API
Update multi-callee problem registration in PyTypeCheckerInspection:
* drop callees with unmapped arguments or unfilled parameters
* in case of one callee show message in old way
* in case of some callees show message with actual types and possible sets of them
2017-03-06 19:43:42 +03:00
Mikhail Golubev
aa41ca3616 Don't wrap types returned by type providers in Coroutine and AsyncGenerator
It's their responsibility to provide the final return type for a function.
Only inferred (i.e. when there's no additional type hints) return value
types should be postprocessed like that in order to get not the
immediate type of values in return statements but the properly
parametrized special type from typing for genetators and coroutines.

Otherwise, we might end up returning something like
Coroutine[Coroutine[int]] for coroutines annotated using .pyi stubs,
because we don't take into account that PyiTypeProvider already
wraps the return type from the stub's annotation in typing.Coroutine.
2017-02-03 17:06:23 +03:00
Andrey Vlasovskikh
89370d4875 Extracted failing test case into separate test 2017-02-02 01:24:04 +03:00
Andrey Vlasovskikh
fa726936b3 Search for relative import results in roots for imports in Python stubs 2017-02-02 01:23:40 +03:00
Andrey Vlasovskikh
df4949948d Ignore unused 'as' and '*' imports in Python stubs 2017-02-02 01:23:34 +03:00
Andrey Vlasovskikh
a562e3a94f Allow forward references to any objects in the same scope inside annotations in Python stubs 2017-02-02 01:23:30 +03:00
Andrey Vlasovskikh
8e3e4dcc2e PY-19374 Allow forward references inside classes in Python stubs 2017-02-02 01:23:24 +03:00
Andrey Vlasovskikh
9382795263 PY-21231 Resolve to Python stub even if target is present in Python file 2017-02-02 01:22:47 +03:00
Mikhail Golubev
3b110194df PY-19375 Disable "Code compatibility" and "Missing or empty docstring" inspections in .pyi files 2016-05-05 14:06:33 +03:00
Andrey Vlasovskikh
5edd67644b Use upper-cased versions of built-in types in type descriptions (PY-16303) 2015-10-22 18:50:28 +03:00
Andrey Vlasovskikh
955e588e03 Show generic types in PEP 484 notation (PY-16889)
In particular, show unresolved refernces in generic bounds as Any.
We used to ignore these unresolved types which resulted in
incomprehensible warning messages.
2015-10-02 21:50:55 +03:00
Andrey Vlasovskikh
e971940c7a Disable unused locals and statement has no effect inspections for Python stubs
All parameters in Python stubs are considered used. The '...' statement
common in Python stubs has no effect but it's use is specified by
PEP 484.
2015-09-02 22:20:41 +03:00
Andrey Vlasovskikh
46588e3a78 Fixed unnecessary calls to PyiTypeProvider for generic types 2015-09-02 19:13:22 +03:00
Andrey Vlasovskikh
a0436ddad1 Allow @typing.overload functions to be located only in stubs with no original function in a Python file 2015-09-02 18:39:15 +03:00
Andrey Vlasovskikh
95840ca22b Type checker inspection checks arguments against multiple function signatures
This is necessary for @typing.overload.

Removed specialized code to check the default values of parameters
for NumPy as bad for performance (stubs->AST for every function with
default values). We'll replace it with another workaround.
2015-09-02 17:59:44 +03:00
Andrey Vlasovskikh
3115e8d79a Initial version of inferring the type of calls to overloaded functions
We don't handle the parameters of overloaded calls properly yet.
2015-09-01 17:53:34 +03:00
Andrey Vlasovskikh
e3ff134329 Compute types of overloaded top-level functions in Python stubs
The corresponding tests still don't pass since we haven't switched
to multi-signature arguments-parameters mapping.
2015-08-26 13:45:01 +03:00
Andrey Vlasovskikh
4a90af129c Collect the type of functions with @typing.overload in PyiTypeProvider
The test of overloads in Python stubs still fails since this union
type isn't used when analyzing function calls and matching arguments
against formal parameters.
2015-08-06 16:08:27 +03:00
Andrey Vlasovskikh
8454b5747b Search for *.pyi stubs in sys.path 2015-07-31 15:07:24 +03:00
Andrey Vlasovskikh
d737cf6b4e Resolve class attributes in Python stub files (PY-16402) 2015-07-13 19:23:17 +03:00