From af9a2791278cee9628acfcc345db3f36e5c29893 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Tue, 3 May 2011 17:04:24 +0400 Subject: [PATCH 1/6] fixed PY-3455 False positive for 'Argument value equals default parameter value' with same-named classes in different modules --- .../PyArgumentEqualDefaultInspection.java | 25 ++++++++++++++++--- .../PyArgumentEqualDefaultInspection/test.py | 11 ++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java b/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java index bc3d7826af17..d667d33d103e 100644 --- a/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java @@ -1,7 +1,9 @@ package com.jetbrains.python.inspections; import com.intellij.codeInspection.ProblemsHolder; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.PsiReference; import com.jetbrains.python.PyBundle; import com.jetbrains.python.actions.RemoveArgumentEqualDefaultQuickFix; import com.jetbrains.python.psi.*; @@ -55,11 +57,10 @@ public class PyArgumentEqualDefaultInspection extends PyInspection { PyExpression defaultValue = e.getValue().getDefaultValue(); if (defaultValue != null) { PyExpression key = e.getKey(); - String text = e.getKey().getText(); if (key instanceof PyKeywordArgument && ((PyKeywordArgument)key).getValueExpression() != null) { - text = ((PyKeywordArgument)key).getValueExpression().getText(); + key = ((PyKeywordArgument)key).getValueExpression(); } - if (text.equals(defaultValue.getText())) { + if (isEqual(key, defaultValue)) { problemElements.add(e.getKey()); } } @@ -77,5 +78,23 @@ public class PyArgumentEqualDefaultInspection extends PyInspection { if (!(arguments[i] instanceof PyKeywordArgument)) canDelete = false; } } + + private boolean isEqual(PyExpression key, PyExpression defaultValue) { + if (key instanceof PyNumericLiteralExpression && defaultValue instanceof PyNumericLiteralExpression) { + if (key.getText().equals(defaultValue.getText())) + return true; + } + else { + PsiReference keyRef = key.getReference(); + PsiReference defRef = defaultValue.getReference(); + if (keyRef != null && defRef != null) { + PsiElement keyResolve = keyRef.resolve(); + PsiElement defResolve = defRef.resolve(); + if (keyResolve != null && keyResolve.equals(defResolve)) + return true; + } + } + return false; + } } } diff --git a/python/testData/inspections/PyArgumentEqualDefaultInspection/test.py b/python/testData/inspections/PyArgumentEqualDefaultInspection/test.py index be7fd9fa43e0..8dc29f64f655 100644 --- a/python/testData/inspections/PyArgumentEqualDefaultInspection/test.py +++ b/python/testData/inspections/PyArgumentEqualDefaultInspection/test.py @@ -38,3 +38,14 @@ class C(object): del self._x x = property(getx, None, fdel = delx, doc = "I'm the 'x' property.") + + +# PY-3455 +import optparse + +class Option(optparse.Option): + pass + +class OptionParser(optparse.OptionParser): + def __init__(self): + optparse.OptionParser.__init__(self, option_class=Option) \ No newline at end of file From 00146237aa8fda978d3ca7bc81948e3777239949 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Tue, 3 May 2011 17:20:21 +0400 Subject: [PATCH 2/6] improved argumentEqualDefaulsInspection for string literals --- .../inspections/PyArgumentEqualDefaultInspection.java | 4 ++++ .../inspections/PyArgumentEqualDefaultInspection/test.py | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java b/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java index d667d33d103e..dc59ce06f194 100644 --- a/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java @@ -84,6 +84,10 @@ public class PyArgumentEqualDefaultInspection extends PyInspection { if (key.getText().equals(defaultValue.getText())) return true; } + else if (key instanceof PyStringLiteralExpression && defaultValue instanceof PyStringLiteralExpression) { + if (((PyStringLiteralExpression)key).getStringValue().equals(((PyStringLiteralExpression)defaultValue).getStringValue())) + return true; + } else { PsiReference keyRef = key.getReference(); PsiReference defRef = defaultValue.getReference(); diff --git a/python/testData/inspections/PyArgumentEqualDefaultInspection/test.py b/python/testData/inspections/PyArgumentEqualDefaultInspection/test.py index 8dc29f64f655..6e6cfea07e67 100644 --- a/python/testData/inspections/PyArgumentEqualDefaultInspection/test.py +++ b/python/testData/inspections/PyArgumentEqualDefaultInspection/test.py @@ -48,4 +48,11 @@ class Option(optparse.Option): class OptionParser(optparse.OptionParser): def __init__(self): - optparse.OptionParser.__init__(self, option_class=Option) \ No newline at end of file + optparse.OptionParser.__init__(self, option_class=Option) + +## + +def bar(a = "qwer"): + pass + +bar(a = 'qwer') From 5c50eb8c350bd2a398c5be9444d51ecbb189db78 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Wed, 4 May 2011 13:53:28 +0400 Subject: [PATCH 3/6] added PY-3451 Support Structure View for reStructuredText --- python/src/META-INF/python-plugin-common.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/src/META-INF/python-plugin-common.xml b/python/src/META-INF/python-plugin-common.xml index fcfe8862615d..652cdf1990f6 100644 --- a/python/src/META-INF/python-plugin-common.xml +++ b/python/src/META-INF/python-plugin-common.xml @@ -472,7 +472,9 @@ - + + From a3894dce73251434fb964706ce8b6d812a410529 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Wed, 4 May 2011 14:51:23 +0400 Subject: [PATCH 4/6] added annotation for not defined references in ReST --- python/src/META-INF/python-plugin-common.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/python/src/META-INF/python-plugin-common.xml b/python/src/META-INF/python-plugin-common.xml index 652cdf1990f6..30c45d109c9a 100644 --- a/python/src/META-INF/python-plugin-common.xml +++ b/python/src/META-INF/python-plugin-common.xml @@ -474,6 +474,7 @@ implementationClass="com.jetbrains.rest.RestFileProviderFactory"/> + From 3f155fd404fe0078c790ae6c2c3b2d4e37e2983c Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Wed, 4 May 2011 16:37:03 +0400 Subject: [PATCH 5/6] fixed PY-3476 Reported element PyDictLiteralExpression is not from the file --- .../jetbrains/python/inspections/PyStringFormatInspection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java b/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java index eb7ebae0f28f..529cb8f88d5b 100644 --- a/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java @@ -237,7 +237,7 @@ public class PyStringFormatInspection extends PyInspection { if (myExpectedArguments > 0) { if (myExpectedArguments == (expressions.length + additionalExpressions.size())) { // probably "%s %s" % {'a':1, 'b':2}, with names forgotten in template - registerProblem(pyElement, PyBundle.message("INSP.format.requires.no.mapping")); + registerProblem(rightExpression, PyBundle.message("INSP.format.requires.no.mapping")); } else { // "braces: %s" % {'foo':1} gives "braces: {'foo':1}", implicit str() kicks in From c115af812673f48192dca24b70891c6ec495c5a5 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Wed, 4 May 2011 20:07:32 +0400 Subject: [PATCH 6/6] fixed PY-3364 Quick-doc: Align base field tag params to the right --- python/helpers/rest_formatter.py | 39 ++++++++++++++++++- .../python/documentation/ReSTRunner.java | 3 -- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/python/helpers/rest_formatter.py b/python/helpers/rest_formatter.py index b7f1736e8e87..266c794216de 100644 --- a/python/helpers/rest_formatter.py +++ b/python/helpers/rest_formatter.py @@ -1,6 +1,43 @@ import sys +from docutils.core import publish_string from epydoc.markup import DocstringLinker -from epydoc.markup.restructuredtext import parse_docstring +from epydoc.markup.restructuredtext import ParsedRstDocstring, _EpydocHTMLTranslator, _DocumentPseudoWriter, _EpydocReader + +class RestHTMLTranslator(_EpydocHTMLTranslator): + def visit_field_name(self, node): + atts = {} + if self.in_docinfo: + atts['class'] = 'docinfo-name' + else: + atts['class'] = 'field-name' + if ( self.settings.field_name_limit + and len(node.astext()) > self.settings.field_name_limit): + atts['colspan'] = 2 + self.context.append('\n ') + else: + self.context.append('') + atts['align'] = "right" + self.body.append(self.starttag(node, 'th', '', **atts)) + +class MyParsedRstDocstring(ParsedRstDocstring): + def __init__(self, document): + ParsedRstDocstring.__init__(self, document) + + def to_html(self, docstring_linker, directory=None, + docindex=None, context=None, **options): + visitor = RestHTMLTranslator(self._document, docstring_linker, + directory, docindex, context) + self._document.walkabout(visitor) + return ''.join(visitor.body) + +def parse_docstring(docstring, errors, **options): + writer = _DocumentPseudoWriter() + reader = _EpydocReader(errors) # Outputs errors to the list. + publish_string(docstring, writer=writer, reader=reader, + settings_overrides={'report_level':10000, + 'halt_level':10000, + 'warning_stream':None}) + return MyParsedRstDocstring(writer.document) try: src = "".join(sys.argv[1:]) diff --git a/python/src/com/jetbrains/python/documentation/ReSTRunner.java b/python/src/com/jetbrains/python/documentation/ReSTRunner.java index 68b5f5a3b21a..44c32332acbf 100644 --- a/python/src/com/jetbrains/python/documentation/ReSTRunner.java +++ b/python/src/com/jetbrains/python/documentation/ReSTRunner.java @@ -4,15 +4,12 @@ import com.intellij.execution.process.ProcessOutput; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.vfs.encoding.EncodingProjectManager; import com.jetbrains.python.PythonHelpersLocator; import com.jetbrains.python.sdk.PythonSdkType; import com.jetbrains.python.sdk.SdkUtil; import org.jetbrains.annotations.Nullable; import java.io.File; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; /** * User : catherine