Commit Graph

481 Commits

Author SHA1 Message Date
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
Mikhail Golubev
5b650a5383 Make Python keyword completion dumb aware
It doesn't use indexes anyhow, and it's very inconvenient not to have it
available while they are being updated. It becomes especially noticeable with
"Idle Indexing" plugin that postpones the indexing on startup.

GitOrigin-RevId: 78dbe4399a38376ae519025e7bbe09906a7d0905
2020-10-22 17:22:28 +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
KotlinIsland
1fdb8235e9 PY-44714 PyTypedDictInspection: don't register problem with None
Fix false positive with None as TypedDict value type
close #1452

GitOrigin-RevId: 7c02d8928f2e9ef3612aaf69d6daeb5a1b71cb95
2020-10-20 16:11:42 +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
Semyon Proshev
5cc837abf5 Minor review fixes
GitOrigin-RevId: 9e7619d7aeb964f20b72504c7ac5f6cf34be64bc
2020-10-19 16:36:21 +00:00
Semyon Proshev
3d31f690f3 Re-use already calculated sdks in guessing language level
Drop `isPythonModule` call since it breaks PyStringLiteralTest.testEscapedUnicodeInLiterals.

GitOrigin-RevId: 6f5ea083a72bdb29826466a50f62cdf84cd26960
2020-10-19 16:36:20 +00:00
Semyon Proshev
4bda118750 Make LanguageLevel.toPythonVersion instance method
GitOrigin-RevId: 133ad26d0952922b57b090dc4e597dc6e3be003e
2020-10-19 16:36:19 +00:00
Aleksei Kniazev
0831f572e4 PY-15046: fixed comparison detection
close #1350

GitOrigin-RevId: dad0c658d5d1d5a3a6d92ecc9cc544f9b7ac0ff4
2020-10-19 15:47:29 +00:00
Vasya Aksyonov
5372947ac0 PY-15046: Review fixes
GitOrigin-RevId: 7d8062b0d0efdb614b421b2e4088a6ec4bcf5413
2020-10-19 15:47:26 +00:00
Vasya Aksyonov
226cf2c350 PY-15046: Invert 'if' statement implementation
GitOrigin-RevId: 86ddfbe04b635d9db288b273540d06d83963cebe
2020-10-19 15:47:25 +00:00
Semyon Proshev
603ae74c21 Make python disposable name more descriptive and not looking like interface
GitOrigin-RevId: 5009db52c121efbbf04952d3843b64ff4dc5888d
2020-10-16 14:44:56 +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
7ec52fb1e6 Don't pass future feature to parsing since it is either null or no more actual
GitOrigin-RevId: 23e266850c1b65facf135248be206387e8284c54
2020-10-16 12:24:41 +00:00
Semyon Proshev
3a14be417f Replace StatementParsing.FUTURE with FutureFeature
GitOrigin-RevId: dc8084755485048edff4659dde551f0b54e2c9c2
2020-10-16 12:24:38 +00:00
Semyon Proshev
08a5ecdd86 Remove future features that are mandatory in the supported python versions, change bounds type to language level
GitOrigin-RevId: 13c3e6ec4248d38338d09d1c3f87da6006d1ce5a
2020-10-16 12:24:36 +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
Vladimir Krivosheev
924abe229c cleanup (get rid of ServiceManager.get)
GitOrigin-RevId: 7f6a905353889c9795e5d40a8aa60f6251000f05
2020-10-16 11:34:52 +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
Alexey Kudravtsev
d2437cbdc2 avoid concrete class IntArrayList, use interface instead
GitOrigin-RevId: 0e8e08b55f58dfd3597e9999012e2746312a9e60
2020-10-07 13:51:52 +00:00
Semyon Proshev
de1646a50e Fix several exceptions raised due to sdk disposal
GitOrigin-RevId: 39f4a67d2ea5ac573c8d467a383339dc5d37eec8
2020-10-06 15:17:22 +00:00
Semyon Proshev
d53595adcf Update sdk configurator and inspection to suggest creating venv using requirements.txt or setup.py (PY-44743)
GitOrigin-RevId: e46b817ea085bca4b538c84eed3cf6d4a0a75013
2020-10-06 15:17:17 +00:00
Petr Golubev
e236a3c66f LAB-31: extracted python formatter
GitOrigin-RevId: a9f0d7afd764d1f7b3df789e3b043ab66048916b
2020-10-01 12:47:58 +00:00
Semyon Proshev
20a7eccfd8 Fix inferring type for cls in __new__ (PY-44470)
GitOrigin-RevId: b70a3d7111d70356ee27bddb337f401db0c49e1e
2020-09-30 19:17:51 +00:00
Vladimir Krivosheev
ef799565a0 cleanup
GitOrigin-RevId: db50f41393f2464428b605fbf1dafcb5c62ed508
2020-09-30 06:38:16 +00:00
Semyon Proshev
d95b00fdd8 Avoid application/project/module as parent disposable in python-related code
And fix several warnings.

GitOrigin-RevId: e97dae3116177bd919bc4ea51ceb1a3e7657e2cb
2020-09-29 10:04:22 +00:00
Vladimir Krivosheev
b1bf65d0ae cleanup (useless comment after copyright file header)
GitOrigin-RevId: 860a889e14a1d9b9d7bbcbbd6b22a447984b81b5
2020-09-28 09:08:58 +00:00
Alexey Kudravtsev
a4e9a0121a test for FileType constructor to be non-public to avoid duplicates and double instantiation because file types must be singletons
GitOrigin-RevId: d448ee007d87edbaf095f8fbe7e1b51ce8c7d9bc
2020-09-27 11:37:12 +00:00
Semyon Proshev
92e044dcc0 Override call type of typing._SpecialForm.__get_item__ (PY-43838)
GitOrigin-RevId: 92e64b0aaea816d56eee85b2bc2417e184e0c4a1
2020-09-24 19:29:49 +00:00
Mikhail Golubev
84d88c326d Make extended completion, automatically inserting imports, slightly more responsive
* Call ProgressManager.checkCancelled() more often.
* Retrieve PSI elements from the index one-by-one, not all at once.
* Filter out duplicate suggestions on the go, don't accumulate them only to
 iterate all over again.
* Don't use this completion for empty prefixes. It's painfully slow and not
 very useful. Instead, it's now automatically restarted as soon as at least some
 prefix appears.

GitOrigin-RevId: 915c5986dbbfc975ce5f43696b15c23f8febc7f2
2020-09-24 15:29:49 +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
Vladimir Krivosheev
8f5d642544 IDEA-251207 Set of plugins cannot be unloaded because of IconLoader
GitOrigin-RevId: 441b875462f12fe0d20d3830181e6280e3b829ba
2020-09-24 15:26:04 +00:00
Peter Gromov
43ace6c0ea unify some "Results might be incomplete during indexing" messages, fix grammar in related places
GitOrigin-RevId: f4f31dcadaf1945f950fe267e3def63ca623464c
2020-09-24 14:17:49 +00:00
Stanislav Utikeev
73dcad36e8 LAB-31 Move TensorFlow members providers to psi-impl
GitOrigin-RevId: 5283df23d8abdc7795fde7850281b876c73a25a0
2020-09-22 15:06:44 +00:00
Vladimir Krivosheev
a67c59c561 platform.core.impl — remove dependency on intellij.platform.util.ui and intellij.platform.core.ui
java.psi.iml — remove dependency on intellij.platform.core.ui

GitOrigin-RevId: c1d4feb04c0471c7d17b5331b86738ee54a97f80
2020-09-21 13:40:47 +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
Semyon Proshev
1fd5190df0 Fix matching type against protocol (PY-44555)
Firstly match protocol usage against its definition, then match type against protocol definition.
This way allows to get correct substitutions.

GitOrigin-RevId: 3565be1dc2991b6b55be666404e5e4715a3e3e80
2020-09-17 21:31:06 +00:00
Semyon Proshev
30c56c3d7b Toggle reversed substitutions flag when matching callables parameters (PY-37876)
Since they are passed in the reversed order.

GitOrigin-RevId: 53643ef104e51d5ebac95ae8d29522530615db66
2020-09-16 19:20:37 +00:00
Semyon Proshev
1eb2bb981a Override call type of cls.__class_getitem__ (PY-43838)
GitOrigin-RevId: 530cbf657d2a76eae2b8dc11ea246be00ca74ee9
2020-09-16 18:52:24 +00:00
Mikhail Khorkov
c505c7316b PY-32929 Fix support for PEP 484 compatible typing in Cython
Now PyCharm successfully parses var with type hinting and
correctly resolve types of function parameters

GitOrigin-RevId: 8baa06c912f5586bb60e6a03d6bad068107ffff6
2020-09-16 13:16:56 +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
5dd5df1e5e PY-15608 Don't cache the target string element in the global intention object
It causes a project leakage through the smart pointer.

GitOrigin-RevId: 0123db808ec5bc469528a2f8a773c4e29ac55366
2020-09-15 06:54:07 +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
6acfca15fc PY-15608 Postpone processing of sibling string nodes until the intention is invoked
GitOrigin-RevId: 927b813c3077c495ad51afcabefd5a8ee5f55cef
2020-09-15 06:54:05 +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
Alexey Kudravtsev
5d41e42767 cleanup: notnull and fix Processor type parameter types
GitOrigin-RevId: 694f1cf4f8b2602e5a0e199c92490e68ec303c1b
2020-09-14 13:46: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