Commit Graph

121 Commits

Author SHA1 Message Date
Semyon Proshev
63b4650c38 Create pending edge from continue when loop has at least one iteration (PY-29767)
There is no edge between loop statement and next after loop instruction
when loop has at least one iteration
so `continue` is marked as one more last instruction in the loop
2018-11-09 19:21:07 +03:00
Elizaveta Shashkova
1ac30ed12d Fix unbound local variable after exception inside with statement (PY-13919)
Change control flow to make it more correct for with statement. Handle special case for Unbound local variable inspection and add tests
2018-05-29 19:54:26 +03:00
Semyon Proshev
a6c795551c Don't collect imported with as elements as named elements (PY-21837)
Because such elements are not presented in stub.
2018-04-09 17:51:35 +03:00
Semyon Proshev
42e4964191 Visit else in while in any case even if condition is True (PY-28972)
But when condition is `True`, edge to `else` is not created.
2018-03-26 19:36:15 +03:00
Semyon Proshev
6933c9d9e0 Update CFG to honour condition values in if statements (PY-24750) 2018-03-13 16:08:46 +03:00
Semyon Proshev
ddd6156be0 Consider elif inner instructions as branching points (PY-23003) 2018-03-12 17:22:16 +03:00
Semyon Proshev
222cb0d70e Don't use resolve while evaluating expressions for CFG 2018-03-07 19:21:54 +03:00
Semyon Proshev
fbee38877a Fix processing normal exits from try-except when they goes out of scope (PY-22184) 2018-02-20 15:21:44 +03:00
Semyon Proshev
1b0e13c8b0 More precise CFG for for cycles by using updated evaluator (PY-19856) 2018-02-20 13:56:13 +03:00
Semyon Proshev
494a53a364 Merge PyConstantExpressionEvaluator and PyEvaluator (PY-19856) 2018-02-20 13:56:10 +03:00
Mikhail Golubev
cbb5fe587a PY-27604 Exclude instantiated metaclasses from ancestor types of a class
but properly take them into account in PyClassType#getMetaClassType().

This check was implemented there instead of PyClass#getMetaClassType()
itself, since the former method already looks up for explicitly declared
metaclasses in ancestors unlike PyClassImpl that considers only those
specified directly in the class definition or its containing module.

Moreover, there are actual usages that expects such behavior from
PyClass#getMetaClassType(), e.g. PyAbstractClassInspection.
2018-01-11 12:45:08 +03:00
Mikhail Golubev
f7da96db03 PY-27656 PY-27604 Exclude ancestors of metaclasses from class hierarchy
in case this relationship was created implicitly by inheriting an
instance of metaclass.

It also fixes warnings about the first parameter of SQLAlchemy model
methods being named "self" instead of "cls" since we no longer consider
these classes descendants of "type".
2018-01-11 12:45:08 +03:00
Semyon Proshev
6b2814e09c Add forgotten test data (PY-25974) 2017-12-25 14:55:17 +03:00
Semyon Proshev
85bea17b09 Add pending edge from left operand in boolean expressions (PY-25974) 2017-12-25 14:24:04 +03:00
Semyon Proshev
2c1c972962 Support positive iterations in control flow (PY-14840, PY-22003) 2017-12-11 15:43:05 +03:00
Semyon Proshev
8d3d94ee88 PY-20889 Fixed: Unresolved attribute after isinstance check in boolean expression
Consider `and` and `or` expressions in PyControlFlowBuilder and use PyTypeAssertionEvaluator to make assertion for right expression.
2017-09-29 19:12:46 +03:00
Mikhail Golubev
247e0aeeb1 PY-21175 Add write instructions for assignments to attributes in CFG
to handle, in particular, lazy initialization scenarios

For instance, the statement "foo.bar = 42" should add a node
"WRITE ACCESS foo.bar" containing the corresponding target expression.

Additionally, "Unused local" inspection doesn't consider writes to
attributes, since, strictly speaking, these are not local names.
2017-07-24 14:38:41 +03:00
Mikhail Golubev
bf22c95cc3 PY-21175 Add implicit negative type assertion after "if" in CFG unconditionally
The check that we should add such synthetic node only if there were no
pending edges inside the body of if statement (e.g. if it contained only
break/continue/return for the enclosing loop) seems doubtful and
doesn't cover the simplest/most common cases.
2017-07-24 14:38:41 +03:00
Mikhail Golubev
1d3eda1e2d PY-22094 Include assert statements in CFG to resolve names in f-strings inside
Otherwise it's impossible to flow-sensitively resolve names referenced
inside such f-strings since we use the containing statement as the anchor
node in the graph.
2017-03-28 16:44:21 +02:00
Andrey Vlasovskikh
8373787e76 Consider class foo(six.with_metaclass(bar)) as new-style class (PY-22806)
Even if there are no new-style parents, the fact of having a metaclass
defined in a class is sufficient to treat it as a new-style class.
2017-03-10 21:08:00 +03:00
Semyon Proshev
05b085e461 PY-21897 Fixed: Wrong type inference with None and conditionals
Don't think that `else` after `if <reference>` means `<reference> is None`
2017-01-16 18:52:23 +03:00
Liana.Bakradze
7084f40683 PY-22042 Gutter icon for running main clause 2016-12-30 14:14:55 +03:00
Semyon Proshev
a9ecefe927 PY-21474 Fixed: Type checking confused by None default argument
PyTypeAssertionEvaluator: Mark reference which is used as condition in PyConditionalExpression as non-None
2016-11-25 19:10:02 +03:00
Semyon Proshev
54a5e386f4 PY-21458 Fixed: Live template hangs PyCharm in some case
Don't analyze implicit imports while searching iterable variable for live template
2016-11-25 19:06:51 +03:00
Semyon Proshev
a0d7707e84 PY-21224 Fixed: False positive unresolved base method when using six.with_metaclass() and multiple inheritance
Support metaclass and several base classes in six.with_metaclass
2016-11-23 14:37:35 +03:00
Mikhail Golubev
8d8c3fb930 PY-20864 Python control flow builder considers variable annotations 2016-09-26 09:09:23 +03:00
Mikhail Golubev
ccbe06603c PY-20026 Add test for the scenario provided by the user
The problem itself has been already remedied by the previous fix,
nonetheless, the example given by the user provides an interesting
case where we can encounter duplicate base classes in practice,
since we are not able to find out result of type(SomeClass) expression
yet.
2016-08-19 16:52:42 +03:00
Mikhail Golubev
28bb6dee75 PY-20026 PyClassImpl#mroLinearize() properly handles duplicate base classes
The exception could happen in this case because we used the same cached
result of MRO linearization twice without defencive copying. Then later,
as a side effect of that, in mroMerge() we deleted one "head" from
several sequences simultaneously, hence the IndexOutOfBoundsException.
2016-07-15 18:39:11 +03:00
Mikhail Golubev
9b49498808 PY-19279 Smart enter on function inserts colon after return type annotation 2016-04-28 14:28:28 +03:00
Semyon Proshev
58a92fde16 PY-12396 Fixed: Property getter live template is useful only inside python class
Separate Python liveTemplatesContext into two parts: General and Class
2016-02-15 14:19:19 +03:00
Mikhail Golubev
a955f6c927 PY-16765 For sections inside Google code style docstring use indentation configured for Python
PyFunctionBuilder and PyDocstringGenerator require a PSI element to
use proper formatting and style for generated docstring.
2015-09-23 18:42:17 +03:00
Mikhail Golubev
3826afdf6c PY-16765 In Google docstrings smart enter adds colon and indentation after section header 2015-09-07 22:01:24 +03:00
Mikhail Golubev
fbbf4dcade PY-15656 Insert closing parenthesis of parameter list right after opening one if there are no parameters 2015-04-21 15:14:26 +03:00
Mikhail Golubev
246fcae221 PY-15653 Better handling of class definitions with the list of base classes but no name node 2015-04-21 15:14:26 +03:00
Mikhail Golubev
3f519db066 PY-15653 Smart enter works better in case of function and class definitions without name element 2015-04-21 15:14:25 +03:00
Mikhail Golubev
d740159214 Merge remote-tracking branch 'origin/master' into mikhail.golubev/py-attribute-inference
Conflicts:
	python/src/com/jetbrains/python/psi/impl/PyClassImpl.java
	python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java
	python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java
	python/src/com/jetbrains/python/psi/impl/references/PyQualifiedReference.java
	python/testSrc/com/jetbrains/python/PythonCompletionTest.java
	python/testSrc/com/jetbrains/python/codeInsight/PyClassMROTest.java
2014-12-25 15:32:43 +03:00
Andrey Vlasovskikh
b37b0440d0 PY-11932 Put nulls for unresolved class types in MRO
Some of the ancestor class-like types may be unresolved. The best we
can do is to put nulls for all the unresolved classes to appropriate
places inside the MRO chain. What we used to do in this case it return
the empty sequence of the ancestors.
2014-12-22 14:05:31 +03:00
Mikhail Golubev
99f4933e70 PY-9209 Insert a space after '#' sign when using smart enter in comment 2014-11-18 01:28:45 +03:00
Mikhail Golubev
af29e9ba36 Prevent recomputation of superclasses during first call to isNewStyleClass 2014-10-17 18:12:01 +04:00
Mikhail Golubev
3c7e51dcd7 Memoize result of MRO resolution 2014-10-16 21:47:51 +04:00
Mikhail Golubev
5de0b14903 PY-12877 Fix complains found during review (IDEA-CR-397) 2014-09-08 12:47:15 +04:00
Mikhail Golubev
2851b82675 PY-12877 Add test for the case when no expression given in 'with' header 2014-08-05 13:03:29 +04:00
Mikhail Golubev
3089c9cb09 PY-12877 Complete statement doesn't insert colon for 'with' statement 2014-07-22 16:30:53 +04:00
Andrey Vlasovskikh
58f85ba28d Fixed 'isinstance' analysis for expressions that are resolved to tuples (PY-7573) 2013-09-18 19:53:04 +04:00
Andrey Vlasovskikh
196b3ce9b2 Fixed getting superclass from 'six.with_metaclass()' call 2013-09-16 21:32:48 +04:00
Ekaterina Tuzova
c022f2520f added failing test for with_metaclass 2013-09-16 16:01:27 +04:00
Andrey Vlasovskikh
83a912ad84 Added negative type assertions for 'else' and continue after 'if' then exit (PY-5084, PY-7694, PY-9118) 2013-04-22 17:56:52 +04:00
Andrey Vlasovskikh
2eab025659 Added test for MRO in complicated diamond hierarchy (PY-4183) 2013-04-18 21:29:49 +04:00
Andrey Vlasovskikh
d6972abf2a Fixed several bugs in new-style MRO algorithm 2013-04-18 21:03:50 +04:00
Andrey Vlasovskikh
451e92581d Fixed false positive in unbound vars inspection for assert False with argument (PY-7784) 2013-01-25 16:59:55 +04:00