Commit Graph

4127 Commits

Author SHA1 Message Date
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
Mikhail Golubev
dd56c1ce85 PY-45566 Exclude results from python-skeletons from extended completion
It has already been done for modules and packages, but not for definitions.

GitOrigin-RevId: a076e4bb1b7cc7dea6e6d5ebcec22e264e7efe39
2020-12-04 15:49:33 +00:00
Mikhail Golubev
591ccf3126 PY-45541 Display symbol's canonical import path as tail text in the lookup
Previously, we used the corresponding element's presentation for this purpose,
but it showed the shortest qualified name of its module, not necessarily the
"canonical" name that was actually used for importing. For instance, we could
have suggested `ndarray` from `numpy.core._multiarray_umath` but imported it
as `from numpy import ndarray`. It was both misleading and could have led to
duplicate entries for the same symbol among suggestions.

GitOrigin-RevId: abb350feeac9fd212d47dc0943442e0b16b21c9a
2020-12-04 15:49:31 +00:00
Mikhail Golubev
cd003c487b PY-45541 Restoring symbol's canonical import path, properly consider binary skeletons
Namely, jump from an empty placeholder __init__.py under python_stubs to the
corresponding real package from a library. Climbing up the series of __init__.py's
is necessary to detect where the name is exported, but previously these parallel
hierarchies were not supported.

GitOrigin-RevId: 3e3d5b8175758f03d24454a29e3f5d7fa120423a
2020-12-04 15:49:28 +00:00
Irina Fediaeva
8402d178e0 PY-41806: Fix false-positive warning when a class definition matches protocol dundercall. This fix raises cases when the definition of a class implements the protocol P match instance of protocol P. There won’t be any warning from PyTypeChecker for this case until in PyTypeChecker.match(PyCallableType, PyCallableType, MatchContext) added checking named, optional and star params.
GitOrigin-RevId: 6f7fdc39cbbdb751026c205fadb915f37d1dfa06
2020-12-04 08:35:52 +00:00
Mikhail Golubev
b023313048 EA-240096 Fix SOE when adding type hints for augmented assignments
It could happen when several augmented assignments are referencing
each over but don't have an ultimate target expression with a higher
resolve priority because of the CFG.

GitOrigin-RevId: 4e908f04103cc131ec48dca95a775406235228a5
2020-12-02 11:02:58 +00:00
Irina Fediaeva
0f6abfba6a PY-44918: Fix resolve path in existing user file instead of the os.path
GitOrigin-RevId: cca701106e1c558a50ed61b85efc312ff9205b1c
2020-12-01 19:44:00 +00:00
Mikhail Golubev
de08c2a947 Fix Python tests after the proofreading
GitOrigin-RevId: 2f6eb873d6321ef00d293377ec2c97195f72da21
2020-11-30 22:17:55 +00:00
andrey.matveev
4580864d68 PY-45114 Fix import prioritizing for same directory elements
Now import elements from the same directory have priority in resolve
over other equally named elements in plain directories and other equally
named elements have priority over same directory modules in ordinary and
namespace packages.
In libraries, the same directory elements should not be resolved in import.

(cherry picked from commit 2b5103dae6ca3828eee7891be248acf99bc7eb56)

IJ-CR-3755

GitOrigin-RevId: 52161f5ba43415d3ceb2ce3dc2122832da2c6197
2020-11-25 16:44:48 +00:00
Semyon Proshev
476989b083 Highlight assignment expressions used in iterables in comprehensions (PY-43619)
GitOrigin-RevId: a980602a3e90bbcfd5db03e828a5ad2a8a339569
2020-11-24 17:35:01 +00:00
Semyon Proshev
48a952a327 Make parser stricter for for statements and expressions (PY-36478)
Now it more follows original python grammar.

GitOrigin-RevId: 199f30b819c85a4eba5cab9b3f67fbf1bb7f18b6
2020-11-24 17:35:00 +00:00
Semyon Proshev
9335c066f5 Make parser stricter for assignment expressions (PY-33886, PY-36478)
Now it more follows original python grammar.

GitOrigin-RevId: f2b45554d16ff87d946950591f0e92fedcfdfaf0
2020-11-24 17:34:59 +00:00
Semyon Proshev
6fcdc21997 Support type inference for cls inside namedtuple's class methods (PY-30870, PY-33140, PY-45473)
GitOrigin-RevId: a299d681d20230acd9443f0fa37c7fd64a51d76a
2020-11-18 18:45:09 +00:00
Mikhail Golubev
9590c3643e PY-45459 Make f-string like completion available after "{" on explicit invocation
GitOrigin-RevId: fe609b6a572f2ac971b2cf34eb92afe529708628
2020-11-15 16:10:47 +00:00
Semyon Proshev
fbbb78bc4e Change receiver for initialization calls and don't resolve callee to constructors
Callee is now a receiver for these cases, previously it was `null`.
Callee is not replaced with constructors to have an ability to map it onto self/cls parameters and process `(cls: Type[T], ...) -> T` annotations.
Stay with the previous behaviour for navigation and looking for target element.

GitOrigin-RevId: c0f9894cf50fd5d7fd325f095976d096fb948e89
2020-11-11 19:30:34 +00:00
Semyon Proshev
55b934691b Sync with typeshed @ c3e04054cfe24866ff2c80955a8d8718ece20ed4
Builtins are split again, no need to split them on our side.

GitOrigin-RevId: 886e3d424f9f698271ee6c610358a3de9a28dca5
2020-11-11 18:09:08 +00:00
Irina Fediaeva
1e8a086708 PY-35698, PY-33565: Delete obsolete PyCallByClassInspection. Type checker inspection covers most of the cases since there is always some type inferred for cls/self.
IDEA-CR-68591

GitOrigin-RevId: fef66f2e1e4d17de50fcca248a3ddc957f3c316d
2020-11-10 13:31:16 +00:00
Mikhail Golubev
7e116a31df PY-45115 Improve the test after the review
* Fix a dysfunctional assertion, comparing a wrong PSI file.
* Assert that the resolve result is a file or a directory. "os" from the standard
library actually resolves to a directory in Typeshed, so getContainingFile() call
on it led to an NPE.
* Remove __init__.py from the directory where the same directory import is
performed. It better reflects the future policy when imports from explicit
packages have priority of absolute resolve results, while imports from plain
directories have priority of same directory results (see PY-45114).

GitOrigin-RevId: 5262032a38e653ce9114402fbb710aedfd278773
2020-11-06 14:05:13 +00:00
Bas Leijdekkers
eccf815b89 RegExp: conditionals support for Ruby and improved conditionals support for PHP (RUBY-27316, WI-51955)
GitOrigin-RevId: 4790db7eeaf658d724ba7c70ed138c9472bf8f2c
2020-11-06 13:44:04 +00:00
Semyon Proshev
51e8ed79bb No more explicit highlighting types in type checker inspection (PY-44957)
And hence no more weak warnings for the cases with generics.

GitOrigin-RevId: 5413395e8eff8ab0a2b87ec0cce92902f4b9bedc
2020-11-05 19:27:29 +00:00
Irina Fediaeva
8acc4ecf8a PY-43915: Fix of incorrect arguments highlighting on weak union class method call.
IDEA-CR-68254

GitOrigin-RevId: aa76636854317e57a0225ab4a98114295777fa72
2020-11-05 08:23:38 +00:00
andrey.matveev
907412afc7 PY-42750 Add new tests
(cherry picked from commit cf39dc58700d68a0d548a5de7bfe66006dde88b8)

IJ-CR-3814

GitOrigin-RevId: 979d3a108a0fd4e79d6e5b657b1eb5b6cd039df9
2020-11-05 05:11:45 +00:00
Mikhail Golubev
cf443d3061 PY-45115 Don't cache same directory import resolve results in Python 3
The cache of resolved qualified names is not context aware, so it's not safe to
keep such results in it. The legacy same directory imports in Python 2 have
already been taken into account and excluded, but we forgot to do the same for
recently enabled same directory imports in Python 3 project sources.

GitOrigin-RevId: f8885543ffa34ea652368a4f190210439173bdfc
2020-10-27 15:59:51 +00:00
andrey.matveev
c5ae9550ce PY-42750 Allow same directory imports in Python 3 and introduce explicit namespace packages
There are 3 types of directories: plain directories, ordinary packages (with
__init__.py) and PEP 420 namespace packages. There are 3 types of imports:
absolute (from a root), same directory (absolute import from the current
directory when it's not explicitly marked as a root) and relative imports
(imports that start with dot).

Absolute imports are correct in all kinds of directories.
Same directory imports are correct in Python 2 in all cases and in Python 3 if
we have the directory containing the script with this import in Python path at
runtime. Users of Python 3 often face the problem when they can run the script
from the console because the directory containing this script got into Python
path but still have red underline and an unresolved reference error in the same
directory import because PyCharm didn't know that this file will be used as a
program's entry point. Previously, the way to fix such a problem was marking it
as a source root. But this action was not so obvious, especially for newcomers.
With this feature, such imports resolve successfully and now it is not necessary
to mark directories as source roots.

Relative imports are correct only in Python 3 namespace or ordinary packages and
should not be used in plain directories. If we have a relative import in plain
directory we highlight it with a weak warning and suggest 2 ways of fixing that:
marking directory as a namespace package explicitly (with quick fix or with Mark
As | Namespace Package) or changing this import to the same directory import
with a quickfix or manually.

Explicitly marking namespace packages can later be used for automatically
running files from them and ordinary packages with "-m".
The new resolve policy and explicit namespace packages can be disabled with the
Registry flag "python.explicit.namespace.packages".

These changes also address PY-40396. Namely, now any directory with __init__.py
inside or explicitly marked as a namespace package has a package icon,
regardless of its name or parents.

GitOrigin-RevId: 310fa562eb60121243cb6d68386ffc3e45c73245
2020-10-21 16:04:26 +00:00
Semyon Proshev
feed56de02 Sync with typeshed @ 10d3c6c325090172d5dc1cb99c5ce8a9319d88b2 (PY-41509, PY-41510, PY-44819)
Enable stubs for contextlib, cprofile, fractions, keyword, pipes, pkgutil, typed_ast, zoneinfo.
Skipped several `__init__` to `__new__` changes in builtin classes.

GitOrigin-RevId: dad913f67c69396d0db2d5e550254535713ea2f3
2020-10-19 21:15:33 +00:00
Mikhail Golubev
bb31fdc67d PY-42334 Add support for PEP 613 typing.TypeAlias
Both typing.TypeAlias (available only in 3.10) and typing_extensions.TypeAlias
names are supported.

RHS values of assignments annotated with TypeAlias are always retained in
stubs and injected into (if it's a string literal), regardless of whether
they look similar to a well-formed type hint. It seems natural to assume
that if a user employs such as specific marker as "TypeAlias" at all, they
clearly indicate that the value is supposed to be a type.

The inspections "Type hints definitions and usages" and "Final classes, methods
and variables" properly analyse RHS of assignments annotated with TypeAlias.
Type hinting inspection also reports illegal usages of TypeAlias, as it was
done for other special forms in the typing module.

The type of such variables themselves is Any, however they're still displayed
as having the type "TypeAlias" in Quick Documentation to avoid confusion.

GitOrigin-RevId: fab02f6e1060c0994e1d21201768e7b28ba7d9e0
2020-10-19 19:46:54 +00:00
Aleksei Kniazev
d18717b0ec PY-15046: fixed tests location
GitOrigin-RevId: 89137463dee2d6a3862b80c98e5a173639c1defe
2020-10-19 15:47:28 +00:00
Semyon Proshev
00eb505497 Python 2.6 is no more supported in compatibility inspection
Because 2.6 is not supported since 2019.1 in IDE.

GitOrigin-RevId: 3dee3e941c921ad3a5dc6d72cca840eb5d811691
2020-10-16 12:24:45 +00:00
Semyon Proshev
d30fc4f7bc Inline language level flags that are constants in supported python versions
GitOrigin-RevId: 5e381b72505c1d896028da83b7044be51e408f0b
2020-10-16 12:24:31 +00:00
Semyon Proshev
860672992e Add language level for Python 3.10 (PY-44857)
Additionally several mandatory python versions have been aligned in FutureFeature.

GitOrigin-RevId: bfeba8d465c593c1000ed0f5226a4ab2a918a2bf
2020-10-16 12:24:27 +00:00
Semyon Proshev
b9281dd55f Mark python 3.5 as unsupported and update 3.9 modules list (PY-41512, PY-44853)
Modules list has been updated using python on Windows, seems it should be done on all OSes and merged.

GitOrigin-RevId: 621172608fffddc3e830f1133fba89a05d092eba
2020-10-08 14:37:43 +00:00
Mikhail Golubev
3f6bc5c1b9 PY-44586 Fix a typo in the test name and data: typing.overload, not override
GitOrigin-RevId: db691e2624a07a0e18bc987ef164230d5e7d0c8a
2020-09-25 20:03:57 +00:00
Mikhail Golubev
ce48522d8f Make the test data layout of extended completion tests more uniform
GitOrigin-RevId: 5ca54fd7ba3446c0548c38d81051968dc7dc4586
2020-09-24 15:29:47 +00:00
Mikhail Golubev
3518c9339d PY-44586 Don't show duplicate completion variants for overrides and stubs
We shouldn't have used function's presentation there to check it's uniqueness,
it includes parameters that we rightfully don't include in the lookup string as
not affecting the import path anyhow.

GitOrigin-RevId: 29c5d231182afb5ebbf71787baea1cd292d82370
2020-09-24 15:29:46 +00:00
Mikhail Golubev
2d4cada4b3 PY-25832 Consider only class attributes for TypeVars wrapped in typing.Type
GitOrigin-RevId: 7cbdabfcbb5acad68e801c0c755a84acae7e8310
2020-09-18 11:47:26 +00:00
Mikhail Golubev
69aae259b1 PY-25832 Consider upper bound and constraints for completion and resolve on TypeVar
GitOrigin-RevId: c6b428965b0136f7f6051c992038dc15819b8f14
2020-09-18 11:47:26 +00:00
Mikhail Golubev
54563b5b5b PY-4311 Don't display method separators for nested functions and classes
I also changed the implementation so that only the very first tokens of
declarations are considered as anchors for method separators. Otherwise,
they start to flicker as their corresponding class and function elements
are often not re-evaluated by LineMarkerProviders on changes in a document.

GitOrigin-RevId: 90488c4bd1c662634c4b6681ce78b1b64c503782
2020-09-16 17:53:05 +00:00
Semyon Proshev
69ae32f06b Sync with typeshed @ d4191de79f5d65d5b8b6fecd68773f6d43a3c731 (PY-43297)
GitOrigin-RevId: 6510912ed00a94af5dc499bee2158ac17518baab
2020-09-16 14:58:32 +00:00
Mikhail Khorkov
a7668df48f PY-11858 Fix rename functon parameter along with decorator argument
If docorated function has a parameter and the decorator has
an argument with the same name as the parameter then we must not rename
the argument in case of renaming the parameter.

GitOrigin-RevId: ebc5dcf7448080e2762004a2779cd06700c042a8
2020-09-16 12:26:09 +00:00
Mikhail Golubev
8acf3cdbd1 PY-38315 Allow to convert quotes of empty string literals
GitOrigin-RevId: 8d601b3cd3e1f0440449e540da2b8edfef8440e6
2020-09-15 06:54:06 +00:00
Mikhail Golubev
9288bc605a PY-30798 Make the intention for converting string quotes work with f-strings
To avoid possible confusion regarding its target element, the intention is now
suggested only when the caret is inside a literal part of an f-string, not at
any expression it contains.

The conversion affects only the string on which the action was invoked,
including ones in its inner expressions, but not enclosing f-strings. Hence,
converting quotes for an f-string might also change quotes of its inner strings
to preserve the syntactic correctness. Converting quotes for an inner
strings, on the other hand, is possible only if it won't break their parent
f-strings.

GitOrigin-RevId: fb997ac8e26eea728897820f0d94bd84aa9e4491
2020-09-15 06:54:03 +00:00
Mikhail Golubev
7affe68244 PY-15608 Handle converting quotes on "glued" string literal with varying quotes
Namely, if such composed literal has nodes with different quotes, convert only
the one directly under the caret. This way we both preserve the old behavior,
when quotes of all individual strings of the literal were converted, and allow
to convert quotes of at least one element if that is not possible.

I've also migrated the intention to newer PyStringElement API that appeared with
the new f-string support.

GitOrigin-RevId: a8592a46e2991b172a205f041cbc3b668e242e8a
2020-09-15 06:54:01 +00:00
Aleksei Kniazev
5f8481db13 IDEA-CR-64748: fixes for namespace package resolve (PY-39748)
(cherry picked from commit c600a4b23556442cfcf7734dc212731017bc86a2)

GitOrigin-RevId: ac9d9b8c0a86f07533acbc4bba047a475581677b
2020-09-14 13:14:49 +00:00
Aleksei Kniazev
4d54941e2c IDEA-CR-64748: account for docstring when resolving namespace package, support try-except style declarations (PY-39748, PY-39512)
(cherry picked from commit 94907cff458e56607c11163bb681988a44750bc0)

GitOrigin-RevId: ff531a0b6f8fbf707656004d0e3ace38361e5cad
2020-09-14 13:14:47 +00:00
Mikhail Golubev
efd3565bf8 PY-34873 Add a regression test for the problem
The issue itself was fixed, together with PY-32864, in
931d1ea4c09d145e763aed839dcb4acbb3e43ec7.

GitOrigin-RevId: af02861b24165da22722e2ad7891dc674a944472
2020-09-10 19:01:31 +00:00
andrey.matveev
1a44ce3c4b PY-44012 Fix disappeared warning for multi assignment and for assignment statements
GitOrigin-RevId: 78f01034ef40bf8aa160dd12cd6922c8d50b3647
2020-09-03 12:57:13 +00:00
Mikhail Golubev
d4262ba517 i18n: Extract messages about unresolved docstring parameter and import references
GitOrigin-RevId: d2a782498ce3381da8442f25bf7e93b45fb1ecdb
2020-08-26 14:25:34 +00:00
Mikhail Golubev
63be8f70f2 i18n: Extract messages from and annotate remaining Python annotators
* FStringAnnotator
* Pep8ExternalAnnotator
* AssignTargetAnnotator

GitOrigin-RevId: 73b2feabd42c7061b4dad22e5d7f7a31ad3f338d
2020-08-25 08:47:08 +00:00
Mikhail Golubev
566dd6af21 i18n: Remove more unused messages from PyPsiBundle
Some inspection had duplicated messages for their names. Normalized those
to use "INSP.NAME" keys for that purpose and removed unused copies.

Also, one of the messages was used only in a test commented ten years ago.
Got rid of that and the corresponding test data.

GitOrigin-RevId: c859370a8b62079e9e345cd03386da850de28586
2020-08-25 08:47:06 +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