Commit Graph

100 Commits

Author SHA1 Message Date
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
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
Vasya Aksyonov
226cf2c350 PY-15046: Invert 'if' statement implementation
GitOrigin-RevId: 86ddfbe04b635d9db288b273540d06d83963cebe
2020-10-19 15:47:25 +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
Stanislav Utikeev
73dcad36e8 LAB-31 Move TensorFlow members providers to psi-impl
GitOrigin-RevId: 5283df23d8abdc7795fde7850281b876c73a25a0
2020-09-22 15:06:44 +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
d71e53b405 i18n: Extract messages from and annotate remaining Python intentions
* SpecifyTypeInPy3AnnotationsIntention
* ImportFromToImportIntention
* ImportToggleAliasIntention
* ImportToImportFromIntention
* PyGenerateDocstringIntention
* SpecifyTypeInDocstringIntention

Some of them were additionally simplified by replacing their custom
field for an intention's name with the inherited one.

GitOrigin-RevId: 72e4c1b5fe628eca36496d56396ee9e149f5104f
2020-08-25 08:47:09 +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
e8612fce3a i18n: Rename .family and .text messages in PyPsiBundle
GitOrigin-RevId: deead25466bd99be53843ee7f1c1d8f3a62191b4
2020-08-25 08:47:07 +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
Mikhail Golubev
827aa32a90 i18n: Fix a typo
GitOrigin-RevId: 8d8af0601dfc7dc68a669ccbf14395ff758387c6
2020-08-25 08:47:05 +00:00
Semyon Proshev
d8873570c5 Update PyCallExpressionHelper.getCallType to ask callee type for result
Get rid of PyNamedTupleType.DefinitionLevel (finally) and PyOverridingTypeProvider.

PyNamedTupleType is updated here since otherwise we would have to provide parameters for PyNamedTupleType with NT_FUNCTION as a definition level via PyNamedTupleType.getParameters.

Update NumpyDocStringTypeProvider and numpy test data, otherwise it will return `numpy.core.ufunc` as a type for every function having special name.
See NumpyDocStringTypeProvider.getReferenceType.

Return accidentally lost behaviour in PyiUtil.findSimilarElement for classes: don't look for similar element in ancestors.

GitOrigin-RevId: e2410eaa0e0cd5f98e4a86515b4358c140b373e6
2020-08-24 18:58:43 +00:00
Mikhail Golubev
df56210439 i18n: Remove unused and rename messages in PyPsiBundle containing "$N" in keys
These are not properly supported and often falsely reported as unused.

GitOrigin-RevId: cb9c9ce8096e14ecaff0b4f473cbb4a028eb3b44
2020-08-24 13:16:59 +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
Mikhail Golubev
0e3afcf3ef i18n: Extract messages from and annotate several Python inspections
* PyFinalInspection
* PyFromFutureImportInspection
* PyInconsistentIndentationInspection
* PyInterpreterInspection
* PyListCreationInspection
* PyMandatoryEncodingInspection
* PyMissingTypeHintsInspection
* PyNonAsciiCharInspection
* PyOverloadsInspection
* PyPackageRequirementsInspection
* PyPep8NamingInspection
* PyPropertyDefinitionInspection
* PyProtectedMemberInspection
* PyProtocolInspection
* PyShadowingBuiltinsInspection
* PyStatementEffectInspection
* PyStringFormatInspection
* PyTupleAssignmentBalanceInspection

I also replaced some existing message keys that used poorly recognized "$1"
notation or otherwise diverged from the convention in use, and updated
annotations in PythonUiService where needed.

GitOrigin-RevId: 75d73d38104c806ad5065e87f76e274b502e889d
2020-08-21 10:03:22 +00:00
Mikhail Golubev
4365fe225c i18n: Extract messages from several Python inspections
GitOrigin-RevId: 2984a5da8f02308dc5c303fdb37ebb1015bc25c1
2020-08-20 11:49:39 +00:00
Mikhail Golubev
91b2855a68 i18n: Extract messages from PyDataclassInspection
GitOrigin-RevId: b8417357579f8e7eae18ddba5fe5231647c55757
2020-08-20 11:49:38 +00:00
Mikhail Golubev
912e1e87b3 i18n: Extract remaining warnings from the Python compatibility inspection
GitOrigin-RevId: 86ab9ea4b7b612889cef31609a640a6e6da904fa
2020-08-20 11:49:35 +00:00
Mikhail Khorkov
cb9715baeb i18n: Fix Cython subsystem
GitOrigin-RevId: 22263cb0d7aaffed4b468918c8168efe5df10c9f
2020-08-20 10:37:54 +00:00
Mikhail Golubev
0adac7f9ea i18n: Add initial support in PyCompatibilityInspection
All its warnings are extracted into the bundle, but they are still poorly
adapted for translation. Each of them in constructed from two separate
messages, a common prefix and an individual feature description, with negation
of the main verb being split. Only the first message can vary depending on
the affected versions number, but both parts of the verb need to agree in many
languages other than English. It's not clear how to address it without
overhauling inspection internals, thus it will be revised later.

I also slightly updated the warnings format. Namely, put "version" in plural,
if a warning applies to multiple Python versions, and removed trailing periods
from single-sentence messages.

GitOrigin-RevId: 51e577201b11fb4e8b6967e1f5ad27143ba9f82e
2020-08-19 14:22:06 +00:00
Mikhail Golubev
7d9e25a990 i18n: Extract messages and annotate several trivial Python inspections
GitOrigin-RevId: d7ed1efc53ae0c8034e8aa52def685b421c9b4cb
2020-08-19 14:22:05 +00:00
Tagir Valeev
fa03a31c48 Messages clarified, quotes added
GitOrigin-RevId: f191ad36a574aa3543758ce87ad0b03cc01cc550
2020-08-18 12:02:48 +00:00
Mikhail Golubev
91d49d6c87 i18n: Extract Python parsing errors, fix their capitalization and format
GitOrigin-RevId: a7374f1cb1358005b371fcfdeb743a24e04e1fbf
2020-08-17 16:32:09 +00:00
Sergey Stupin
59758ad60a LAB-31 move UnresolvedReferenceAddParameterQuickFix to python-psi-impl
GitOrigin-RevId: 67870d2d9db279ccb73e80b69878950f06a08bbe
2020-08-14 12:38:00 +00:00
Sergey Stupin
6687933b24 LAB-31 move PyRenameUnresolvedRefQuickFix to python-psi-impl
GitOrigin-RevId: 0792d8386797ffbe744412471a4afe03c87a9a65
2020-08-14 12:29:30 +00:00
Sergey Stupin
6cb9f399ea LAB-31 move UnresolvedReferenceAddSelfQuickFix to python-psi-impl
GitOrigin-RevId: 884622f2a36ae373e32b00ae9fff82d9abee2d1c
2020-08-14 12:17:50 +00:00
Sergey Stupin
e5d07c3fa3 LAB-31 move UnresolvedRefTrueFalseQuickFix to python-psi-impl
GitOrigin-RevId: c763b088342644a310ae2900f71825e3be2ecd40
2020-08-14 11:22:53 +00:00
Sergey Stupin
90bc0b74e1 LAB-31 move UnresolvedRefCreateFunctionQuickFix to python-psi-impl
GitOrigin-RevId: 46cc3a8678f829bc6c7fe6e0b8b5e80c5a6f6329
2020-08-14 11:07:59 +00:00
Sergey Stupin
f7b5037798 LAB-31 move CreateClassQuickFix to python-psi-impl
GitOrigin-RevId: d78869705bcaf455d2320fb0a15eccd6c95bf1d7
2020-08-13 14:26:06 +00:00
Sergey Stupin
465b69d32c LAB-31 move add field/function quick fixes to python-psi-impl
GitOrigin-RevId: 59951f875689d397320a9dab3cced4c7160f12fb
2020-08-13 13:39:07 +00:00
Semyon Proshev
1e9182b7e0 Run PyCollectionTypeByModificationsProvider last since it could affect type inference due to recursion inside (PY-39510)
GitOrigin-RevId: 619db13e01470e9ac5f1a75a46e3cd791042f405
2020-08-04 13:27:41 +00:00
Semyon Proshev
1e1bfd58ac Inject separate python dialect into type comments (PY-35370)
No more PyDocstringFile for them since doctest and type comments should be parsed differently (at least `...` should not be skipped)

GitOrigin-RevId: 9b78ad0491859dbf381a049e93ac74bc83db4183
2020-07-20 18:38:43 +00:00
Semyon Proshev
20bca8c772 Fix formatting and i18n in type hints inspection
GitOrigin-RevId: 013724b10d61d2c7909350ac8b58b1807f8cbcb8
2020-07-14 14:26:10 +00:00
andrey.matveev
49c99c9577 [PY-20893] Fix removing full block by quick fix unused local variable for exception
GitOrigin-RevId: a518e1edee1c52543e9059e98439573770bc746b
2020-07-13 12:39:38 +00:00
Adam Hood
621ccf8591 LAB-31: add imports in same cell for auto-import action
GitOrigin-RevId: 7603c6a2fd2bd472491a15f23d66034a84aace90
2020-06-23 23:12:52 +03:00
Mikhail Golubev
4fc3af2705 PY-42700 Offer f-string-like completion after "{" in non-interpolated strings
The main idea here is that we also automatically convert the containing string
literal into a proper f-string upon selecting one of such variants.

Hopefully, it addresses the common problem of forgetting to add "f" prefix
before an interpolated (in mind) string literal in a more discoverable fashion
than a dedicated intention or a postfix template would.

GitOrigin-RevId: f59065abeb4a3b0cd7a0de42c9c06c9fad318b19
2020-06-03 19:03:09 +03:00
andrey.matveev
493cffa7fd PY-40431 i18n fix for inspection pep8 naming convention violation options
GitOrigin-RevId: 8a5b94b3066e43a1881357da36b1749444793808
2020-05-20 09:33:14 +00:00
andrey.matveev
05300f7bcc PY-40431 i18n for inspection pep8 naming convention violation options
GitOrigin-RevId: 4c6d1e7d6699ee28d419841141b28c4a0080fa76
2020-05-20 09:25:53 +00:00
Semyon Proshev
51a1dc7248 Move inferring types for typing.NewType to a separate provider (PY-21302)
GitOrigin-RevId: b406496361bdaa2f053c66a1b191e9ca12ddb2ee
2020-05-17 20:38:28 +00:00
Anton Bragin
7d337db3df PY-40431 [i18n] PyStubPackagesCompatibilityInspection
GitOrigin-RevId: 68dfeb710d0d7e0059f6660a93fa5cab06a5f8a3
2020-05-14 07:37:37 +00:00
Anton Bragin
7b7dd70435 PY-40431 [i18n] PyInspectionsSuppressor fixes i18n
GitOrigin-RevId: 49559b64b5899ffd09a0bad0688c04409e087bc9
2020-05-13 17:28:26 +00:00
Dmitry Trofimov
da9c15292f Fix name in commment
GitOrigin-RevId: e2dfc53e4cf77212fc240682e9050fae911c36bb
2020-05-12 10:33:28 +00:00
Dmitry Trofimov
f0399e1662 Decouple Python intentions
GitOrigin-RevId: e87aa7f8fde189ff2a48793879e27617ff6297e7
2020-05-01 18:44:38 +00:00
Mikhail Golubev
94c01f239f PY-41923 Mark EPs for custom target expression and class stubs as dynamic
Also, mark them as @ApiStatus.Internal instead of @Deprecated. These EP however
won't be safe to use as soon as we decide, e.g. to extract Django support into
a standalone plugin, because unloading it won't trigger rebuilding of indexes
in the current implementation leaving unused custom data in them.

GitOrigin-RevId: 3dbe4bee616c500409a088b825e3252615167069
2020-04-29 22:04:28 +00:00
Mikhail Golubev
41f7540037 PY-41923 Mark Pythonid.importCandidateProvider as dynamic
GitOrigin-RevId: 1d0dc50cafc724811bfbd336c1ecd2d62d430695
2020-04-29 22:04:28 +00:00
Semyon Proshev
e219ead527 Make several EP dynamic (PY-41923)
PyBreakpointHandlerFactory, PyConsoleOptionsProvider, PyPregeneratedSkeletonsProvider, PyClassMembersProvider, PyCanonicalPathProvider and PythonVisitorFilter

GitOrigin-RevId: d5b55eae82a2b1334ecbdcadc2bfe7c3a2f29512
2020-04-29 22:04:28 +00:00
Semyon Proshev
68b5d36ff3 Make several EP dynamic (PY-41923)
PythonRemoteInterpreterManager, Pep8ProblemSuppressor, PySdkComparator, PyReferenceCustomTargetChecker and PyDataclassParametersProvider

GitOrigin-RevId: 13acf82111e175f2095b6abc4b8838ba47a0fe16
2020-04-29 22:04:28 +00:00
Mikhail Golubev
a41d39cd3b PY-41923 Get rid of overriding bridge services in python-core-common.xml
by moving the registration of stub implementations for code-insight bridge services
from PythonPsiImpl.xml down to PythonAnalysisToolPlugin.xml where they are actually
used. All the other products using PythonPsiImpl.xml seem to include it via
python-core-common.xml, so each of them will safely get the real *ServiceImpl
implementation of the corresponding bridge.

GitOrigin-RevId: 2cf83ab8ff99efcc9ed432634e4f2d614a18cc8b
2020-04-29 22:04:28 +00:00
Alexander Koshevoy
743ce8c3a2 Move Cython parser's messages from PythonProBundle.properties to PyPsiBundle.properties
GitOrigin-RevId: fdeb63629b40d0505863ce7c8df79cefc3841ab3
2020-04-10 16:06:12 +00:00
Alexander Koshevoy
f9e153addd Move the message from CythonFunctionParsing to PyPsiBundle.properties
GitOrigin-RevId: 4e3013d8b12786df7617399ad46765b0203579c1
2020-04-10 16:06:12 +00:00