| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,7 @@ internal class ModuleObject : ExtensionType | |||
| 19 | 19 | internal PyDict dict; | |
| 20 | 20 | protected string _namespace; | |
| 21 | 21 | private readonly PyList __all__ = new (); | |
| 22 | + private readonly HashSet<string> allNames = new(); | ||
| 22 | 23 | ||
| 23 | 24 | // Attributes to be set on the module according to PEP302 and 451 | |
| 24 | 25 | // by the import machinery. | |
@@ -178,22 +179,23 @@ public void LoadNames() | |||
| 178 | 179 | { | |
| 179 | 180 | foreach (string name in AssemblyManager.GetNames(_namespace)) | |
| 180 | 181 | { | |
| 181 | - cache.TryGetValue(name, out var m); | ||
| 182 | - if (m != null) | ||
| 182 | + bool hasValidAttribute = cache.TryGetValue(name, out var m); | ||
| 183 | + if (!hasValidAttribute) | ||
| 183 | 184 | { | |
| 184 | - continue; | ||
| 185 | - } | ||
| 186 | - BorrowedReference attr = Runtime.PyDict_GetItemString(dict, name); | ||
| 187 | - // If __dict__ has already set a custom property, skip it. | ||
| 188 | - if (!attr.IsNull) | ||
| 189 | - { | ||
| 190 | - continue; | ||
| 185 | + BorrowedReference attr = Runtime.PyDict_GetItemString(dict, name); | ||
| 186 | + // If __dict__ has already set a custom property, skip it. | ||
| 187 | + if (!attr.IsNull) | ||
| 188 | + { | ||
| 189 | + continue; | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + using var attrVal = GetAttribute(name, true); | ||
| 193 | + hasValidAttribute = !attrVal.IsNull(); | ||
| 191 | 194 | } | |
| 192 | 195 | ||
| 193 | - using var attrVal = GetAttribute(name, true); | ||
| 194 | - if (!attrVal.IsNull()) | ||
| 196 | + if (hasValidAttribute && allNames.Add(name)) | ||
| 195 | 197 | { | |
| 196 | - // if it's a valid attribute, add it to __all__ | ||
| 198 | + // if it's a valid attribute, add it to __all__ once. | ||
| 197 | 199 | using var pyname = Runtime.PyString_FromString(name); | |
| 198 | 200 | if (Runtime.PyList_Append(__all__, pyname.Borrow()) != 0) | |
| 199 | 201 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,11 @@ | |||
| 5 | 5 | import pytest | |
| 6 | 6 | import sys | |
| 7 | 7 | ||
| 8 | + # Unused import to preload the class | ||
| 9 | + # | ||
| 10 | + # This resulted in the FileStream name missing from the wildcard import later | ||
| 11 | + from System.IO import FileStream # noqa: F401 | ||
| 12 | + | ||
| 8 | 13 | def test_relative_missing_import(): | |
| 9 | 14 | """Test that a relative missing import doesn't crash. | |
| 10 | 15 | Some modules use this to check if a package is installed. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments