Skip to content

Commit 7eb4114

Browse files
yoffRasmusWL
andauthored
Update python/ql/lib/semmle/python/Module.qll
Co-authored-by: Rasmus Wriedt Larsen <[email protected]>
1 parent 8f70c9f commit 7eb4114

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

python/ql/lib/semmle/python/Module.qll

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,19 @@ private predicate isPotentialPackage(Folder f) {
197197
private string moduleNameFromBase(Container file) {
198198
// We used to also require `isPotentialPackage(f)` to hold in this case,
199199
// but we saw modules not getting resolved because their folder did not
200-
// contain an `__init__.py` file.
200+
// contain an `__init__.py` file.
201201
//
202202
// This makes the folder not be a package but a namespace package instead.
203+
// In most cases this is a mistake :| See following links for more details
204+
// - https://dev.to/methane/don-t-omit-init-py-3hga
205+
// - https://packaging.python.org/en/latest/guides/packaging-namespace-packages/
206+
// - https://discuss.python.org/t/init-py-pep-420-and-iter-modules-confusion/9642
203207
//
204-
// It is possible that we can keep the requirement here, but relax
205-
// `isPotentialPackage` itself to allow for namespace packages.
208+
// It is possible that we can keep the original requirement on
209+
// `isPotentialPackage(f)` here, but relax `isPotentialPackage` itself to allow
210+
// for this behavior of missing `__init__.py` files. However, doing so involves
211+
// cascading changes (for example to `moduleNameFromFile`), and was a more involved
212+
// task than we wanted to take on.
206213
result = file.getBaseName()
207214
or
208215
file instanceof File and result = file.getStem()

0 commit comments

Comments
 (0)