From eee791f04f34c3df855f8a31284fd6a45634a909 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Mon, 28 May 2012 17:17:12 +0400 Subject: [PATCH] Added the __module__ attribute to new-style classes (PY-6634) --- python/helpers/generator3.py | 4 +++- python/helpers/required_gen_version | 2 +- python/testData/completion/mro.py | 2 +- .../moduleAttribute.py | 12 ++++++++++++ .../PyUnresolvedReferencesInspectionTest.java | 5 +++++ 5 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 python/testData/inspections/PyUnresolvedReferencesInspection/moduleAttribute.py diff --git a/python/helpers/generator3.py b/python/helpers/generator3.py index e0c550c3e7b6..447a63403df7 100644 --- a/python/helpers/generator3.py +++ b/python/helpers/generator3.py @@ -24,7 +24,7 @@ but seemingly no one uses them in C extensions yet anyway. # * re.search-bound, ~30% time, in likes of builtins and _gtk with complex docstrings. # None of this can seemingly be easily helped. Maybe there's a simpler and faster parser library? -VERSION = "1.107" # Must be a number-dot-number string, updated with each change that affects generated skeletons +VERSION = "1.108" # Must be a number-dot-number string, updated with each change that affects generated skeletons # Note: DON'T FORGET TO UPDATE! VERSION_CONTROL_HEADER_FORMAT = '# from %s by generator %s' @@ -1795,6 +1795,8 @@ class ModuleRedeclarator(object): for item_name in sortedNoCase(others.keys()): item = others[item_name] self.fmtValue(out, item, indent + 1, prefix=item_name + " = ") + if p_name == "object": + out(indent + 1, "__module__ = ''") if others: out(0, "") # empty line after the block # diff --git a/python/helpers/required_gen_version b/python/helpers/required_gen_version index e8cfa76de1a4..6f3efcf4121d 100644 --- a/python/helpers/required_gen_version +++ b/python/helpers/required_gen_version @@ -6,7 +6,7 @@ (default) 1.92 # anything not explicitly marked -(built-in) 1.106 # skeletons of all built-in modules are built together +(built-in) 1.108 # skeletons of all built-in modules are built together # Note: modules like itertools, etc are "(built-in)" and are ignored if given separately _fileio 1.101 diff --git a/python/testData/completion/mro.py b/python/testData/completion/mro.py index cee5359fcabe..d661f0befef0 100644 --- a/python/testData/completion/mro.py +++ b/python/testData/completion/mro.py @@ -2,4 +2,4 @@ class C(object): pass -C.__m \ No newline at end of file +C.__mr \ No newline at end of file diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/moduleAttribute.py b/python/testData/inspections/PyUnresolvedReferencesInspection/moduleAttribute.py new file mode 100644 index 000000000000..8e4dec410776 --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection/moduleAttribute.py @@ -0,0 +1,12 @@ +class OldStyle: + pass + +class NewStyle(object): + pass + +x = OldStyle() +y = NewStyle() +print(OldStyle.__module__) +print(NewStyle.__module__) +print(x.__module__) +print(y.__module__) diff --git a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java index f483114d1c9e..9ad2a1b4f9e3 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java @@ -121,6 +121,11 @@ public class PyUnresolvedReferencesInspectionTest extends PyTestCase { doTest(); } + // PY-6634 + public void testModuleAttribute() { + doTest(); + } + private void doTest() { myFixture.configureByFile(TEST_DIRECTORY + getTestName(true) + ".py"); myFixture.enableInspections(PyUnresolvedReferencesInspection.class);