82 Commits
Author SHA1 Message Date
Mikhail Golubev cef42660a3 PY-17627 PY-17733 Resolve class attributes defined in @classmethods
The logic is similar to that for instance attributes. Top-level class
attributes and methods defined in the class body get the precedence,
followed by class attributes defined with assignments in @classmethods
unless the latter would resolve to the same assignments as in

cls.attr = cls.attr + 1

finally, we scan through all other class methods resolving the name
to the first definition inside one of them.

So far, I intentionally didn't expose such attributes in findClassAttribute()
or getClassAttributes() because users of these methods assume that
this API considers only attributes defined immediately in the class body.
Adding extra definitions from class methods might break these usages.

I had to update the inspection about typing.Final, because it relied
on the fact that resolve() on assignment targets on class objects can
lead only to those top-level class attributes, where type hints are normally
located, but now it can lead to assignments to a qualified attribute inside
a containing class method.

GitOrigin-RevId: 0ca5bdaa4efca127ac187e822a49df6795e1028a
2024-03-28 12:17:37 +00:00
andrey.matveev 6e910f2023 PY-49156 Fix problem with no completion for os.path
(cherry picked from commit 38148e31c6cb3db1c4515d0c184eac5f8675e2e1)

IJ-MR-10435

GitOrigin-RevId: b679bdff186348baac062fcb8cb1550f35876612
2021-06-25 14:17:13 +00:00
andrey.matveev b7ce3244ab PY-45776 EA-248324 Fix npe in isSameDirectoryResult
GitOrigin-RevId: e3c26a84d89bebe99443033a642d655c1e518c82
2020-12-17 17:29:27 +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
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
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
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
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 6bd03747fa PY-38322 PY-39171 Regression tests on resolve in skeleton submodules and __all__ processing
GitOrigin-RevId: 5996a0469c811efad78b063a56fae9f197865b8f
2020-03-09 16:31:45 +00:00
Aleksei Kniazev a906dd493a account for comments and line breaks in __init__ files declaring namespace package (PY-38434)
GitOrigin-RevId: 4a5a890113a8d8aa55053f6d96d946958476ea17
2020-03-06 14:33:05 +00:00
Semyon Proshev cff3f1f86d Enable pyi-stubs for os (PY-23258, PY-21395, PY-21394, PY-21397, PY-17420, PY-28984, PY-27584)
GitOrigin-RevId: 34ecf07bc68276e62315d01f3c3347f79026ec65
2019-11-20 11:37:02 +00:00
Aleksei Kniazev fbfef48442 support namespace packages defined via pkg_resources and pkg_util (PY-16688, PY-23087)
GitOrigin-RevId: fc979a18d3c8bf310f6ae4381ac7f365e8b6c180
2019-09-09 10:02:33 +00:00
Mikhail Golubev cd53226019 PY-31299 Fix resolution of built-in classes' names in PyPsiFacade
Additionally, I extracted tests on PyPsiFacade implementation into a dedicated
test case.
2018-09-26 19:51:17 +03:00
Mikhail Golubev 2d2976a889 PY-31299 Migrate PyPsiFacade#createClassByQName implementation to PyResolveImportUtil
Using PyTypeParser for this purpose is, first, too heavyweight since it does a lot of
unnecessary work, and, second, introduces unexpected problems related to the fact
that it was originally intended to resolve types in docstrings and thus too permissive
and depends on surrounding context such as existing imports.
2018-09-26 18:15:23 +03:00
Mikhail Golubev e5226b9cf5 EA-121262 Don't include incomplete from imports in implicit package members 2018-06-25 18:24:57 +03:00
Andrey Vlasovskikh 4f5eefdea2 PY-29338 Revert "PY-28629: Fix resolving skeletons for implicit relative imports"
This reverts commit be8aaaaf53.
2018-04-06 22:09:14 +03:00
Semyon Proshev 9c27646752 Don't ignore files and resolve modules in them (PY-28764) 2018-03-30 15:09:00 +03:00
fitermay bd2a9bbfee ensure packages resolve to __init__.py when possible 2018-03-13 18:11:11 +03:00
fitermay f68b3b835d PY-28685: Consider module at reference location as implcitly imported 2018-03-13 18:11:11 +03:00
Anton Bragin 695aae6810 PY-28321 Import resolution changed to respect source root order
Import resolution now gradually resolve qualified names one step at a
time to exclude cases when parent and child modules are resolved from
different source roots.
2018-02-27 13:43:35 +03:00
Andrey Vlasovskikh a8b8f04ff7 PY-28629 Fixed case sensitivity issue in test data discovery 2018-02-26 18:10:18 +03:00
fitermay be8aaaaf53 PY-28629: Fix resolving skeletons for implicit relative imports 2018-02-26 18:10:18 +03:00
Mikhail Golubev 085c4e063a PY-16412 Don't allow to unstub external files to check if target is inside a comprehension 2018-02-05 21:41:59 +03:00
Kiryl Chetyrbak a82000de58 fix PyCustomMember targeting a class 2017-07-03 19:47:08 +03:00
Brendan Douglas da77d7d1d8 Python import resolution: support multiple import source directories with the same qualified name (PY-22522) 2017-03-08 17:12:08 +03:00
Andrey Vlasovskikh 60451cb448 PY-21088 Understand __all__.append() and __all__.extend()
PyCharm used to fail to statically evaluate __all__.append() calls in
typing.py and concluded that since __all__ was too dynamic to analyse
it was better to assume that __all__ isn't present.

It affected resolving to internal module attributes not mentioned in
__all__ and even led to false positives in unused locals when these
internal names were imported from another module right next to
star-import from the module with __all__.
2016-10-26 20:06:07 +03:00
Mikhail Golubev 4c7269a765 PY-19989 Don't store results of implicit relative import in PythonPathCache 2016-07-07 11:54:46 +03:00
Andrey Vlasovskikh 6211427812 Resolve only to the first path entry if non-empty name for QualifiedNameResolver is provided (PY-18626)
Since we switched to multi-resolve for imported modules, we have to
modify the contract of QualifiedNameResolver so it doesn't return all
the results across all the paths, but rather stops on the first set
of results for a particular path in sys.path.
2016-04-21 20:17:59 +03:00
Mikhail Golubev 53dc593206 PY-17941 Fix ranking of resolve results: don't skip empty modules, prefer real files to "__all__"
Test PyBinaryModuleCompletionTest#testPySideImport failed without
special rule regarding references in "__all__".
2015-12-14 15:43:28 +03:00
Andrey Vlasovskikh ac05b12d26 Resolve members of all imported modules in both __init__.py and submodules (PY-14454, PY-14615)
We used to resolve members __init__.py of imported packages using only
the __init__.py itself, i.e. without considering their submodules. Now
we do that and we also don't filter unimported submodules because we
cannot detect them reliably. They might be imported in other modules
via some import chain.
2015-07-02 17:38:25 +03:00
Andrey Vlasovskikh c80b8263c7 Added a test for PY-14454 2015-07-01 13:10:43 +03:00
Ekaterina Tuzova dfa4380854 PY-15503 Numpy: unresolved reference: false positive for testing package referenced with numpy import only
fixed resolve for the relative from imports
2015-05-05 17:03:36 +03:00
Ekaterina Tuzova c882d5d5ed fixed resolve to the keyword argument introduced in 8b9e7981df
needed for PY-15366 No completion for matplotlib figure
2015-05-05 17:03:33 +03:00
Andrey Vlasovskikh 71f55b4760 Fixed resolving nested namespace packages 2014-11-12 16:42:52 +03:00
Mikhail Golubev e0ddef7bf1 PY-13140 Top-level module names starting with underscore are not imported via wildcard import 2014-07-10 15:09:49 +04:00
Andrey Vlasovskikh 34c523582f Implicitly imported package members are already processed in PyModuleType instead of PyFile (PY-10819) 2013-09-25 20:55:16 +04:00
Andrey Vlasovskikh 072b3887c1 Fixed unresolved references inspection for fields defined in __new__ (PY-6805)
The inspection may show false negative warnings for assigned attributes of objects
other than the return value of __new__.
2013-04-12 14:42:45 +04:00
Dmitry Jemerov 703f74d0e8 failing test for PY-7929 2012-11-01 20:23:02 +04:00
Dmitry Trofimov 606a52f82f Resolve to project sources first instead of libraries and stubs (PY-7775). 2012-10-22 00:07:32 +02:00
Andrey Vlasovskikh 5db6ed1df7 Support for implicit namespace packages in Python 3.3 (PY-7156) 2012-08-27 20:00:06 +04:00
Dmitry Jemerov 6677bdbb02 star import elements correctly resolve source of from import statement (PY-7204) 2012-08-16 09:02:55 +02:00
Andrey Vlasovskikh 55383be850 Fixed unresolved reference for reassignment of a variable after star import (PY-7026) 2012-07-23 20:15:22 +04:00
Andrey Vlasovskikh 4140c25a7b Fixed wrong resolve to submodule instead of function with the same name (PY-6866) 2012-07-03 19:07:11 +04:00
Andrey Vlasovskikh f9f42a436c Fixed resolve of imported module references in submodules with relative imports (PY-6575) 2012-05-25 22:46:59 +04:00
Andrey Vlasovskikh 981c567d14 Test for PY-6575 2012-05-23 22:45:51 +04:00
Andrey Vlasovskikh 3e9550fd41 Fixed unresolved references for namespace packages (PY-2813) 2012-04-30 20:17:02 +04:00
Dmitry Jemerov 32bca31f70 fix SOE in new-style resolve (PY-6305) (oh god the contract of findExportedName() is so confusing) 2012-04-26 11:21:12 +02:00
Dmitry Jemerov 9decb95254 don't override locally resolved module with results from global resolve cache (PY-6011) 2012-03-30 18:11:51 +02:00