You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 3, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 3, 2026. It is now read-only.
Possible name collision for same-named source file in different directories #198
From googleapis/google-cloud-python#6769 (comment). That particular issue hasn't been figured out yet, but it got me to think about whether it's generally possible for pytype to accidentally map two source files to the same pyi path, and it indeed is. With a structure like:
when pytype is run from root, ninja errors out with: ninja: error: build.ninja:11: multiple rules generate /usr/local/google/home/rechen/root/pytype_output/pyi/foo.pyi [-w dupbuild=err]. Perhaps we need to include the relative path from the current directory to the pythonpath directory in pytype_output.
Reacted by Caleb Collins-Parks, ikicic, Ben Chuanlong Du, Matthieu Caneill, Alexander Reshytko, Karim-53, HisMaj3sty and Harmon
note that this is asking pytype to analyse two unrelated projects (that happen to be sitting in the same directory on the user's filesystem). i think we should flag this as an error (possibly with a more informative error message) rather than try to put them in the same output tree.
Hmm, in this case, since all of the packages and subpackages have __init__.py files, I'd have expected pytype to be able to use the full module names to distinguish between the two files. Which directory are you running pytype from in which there's a name collision?
I have tried both the very toplevel directory as well as the cocotb subdirectory. Let me boot up the machine where I tried this and see if I can figure out more.
For some reason, I cannot reproduce this anymore. As a workaround, I had added one of those "duplicating" directories to the exclude list, but now that I removed it again, it still works, even after removing the .pytype output directory. Please disregard, sorry for the confusion.
Hmm, why are you running pytype -P /tmp/out? -P is for paths to source code directories, whereas /tmp/out looks like it contains just-generated .imports and .pyi files.
I might well have been doing something silly here. I was trying to run pytype in type-check mode, using previously-generated stubs.
Looking through pytype --help, I wasn't sure what -P is supposed to do (why would you specify source code directories with -P rather than just specifying them as the input argument?), but running pytype-single --help, I saw there was a fuller description of -P, and took it to mean that it could be used to specify a directory with previously-generated stubs - and that this also applied to regular pytype. I guess this is not the case?
Ah, the -P arguments to pytype and pytype-single are similar but not quite the same. They're both for telling pytype where the dependencies of your input files are, but for pytype, you specify source files whereas for pytype-single you specify type stubs. You wouldn't just pass these files as inputs because they would then be type-checked.
Agree with @nirradi that adding a missing __init__.py fixed the problem for me. To future visitors to this page: you may be missing __init__.py files somewhere in your packages.
Maybe the multiple rules generate error should be extended to include a note that pytype has poor compatibility with PEP 420 implicit namespace packages and to try adding __init__.py files?
Hi, thank you for your report. Google is shifting its effort to a different approach for type checking apart from pytype, and we're not planning to put in any effort in the near future in pytype, so we'll close this issue. Please see the announcement here.
Activity
martindemello commentedon Dec 3, 2018
note that this is asking pytype to analyse two unrelated projects (that happen to be sitting in the same directory on the user's filesystem). i think we should flag this as an error (possibly with a more informative error message) rather than try to put them in the same output tree.
rchen152 commentedon Dec 4, 2018
True, we may want to forbid this rather than supporting it. Either way, the current behavior (cryptic failure) isn't good.
cmarqu commentedon Oct 21, 2019
I'm trying to run pytype on a project (https://github.com/cocotb/cocotb) where the same filename exists in two different directory (e.g., https://github.com/cocotb/cocotb/blob/master/cocotb/monitors/avalon.py and https://github.com/cocotb/cocotb/blob/master/cocotb/drivers/avalon.py) - here, this is not unrelated projects. I would therefore be happy if this kind of file layout could be supported.
rchen152 commentedon Oct 21, 2019
Hmm, in this case, since all of the packages and subpackages have
__init__.pyfiles, I'd have expected pytype to be able to use the full module names to distinguish between the two files. Which directory are you running pytype from in which there's a name collision?cmarqu commentedon Oct 21, 2019
I have tried both the very toplevel directory as well as the
cocotbsubdirectory. Let me boot up the machine where I tried this and see if I can figure out more.cmarqu commentedon Oct 21, 2019
For some reason, I cannot reproduce this anymore. As a workaround, I had added one of those "duplicating" directories to the exclude list, but now that I removed it again, it still works, even after removing the
.pytypeoutput directory. Please disregard, sorry for the confusion.rchen152 commentedon Oct 21, 2019
No worries, thanks for looking into it again!
mrahtz commentedon Sep 5, 2020
An example of this error even within one project is
git clone https://github.com/hill-a/stable-baselines cd stable-baselines git checkout 3840ddf752143f7fc1a54bf3debc125855df4ca2 patch -p0 -i patch.diff pytype -o /tmp/out pytype -P /tmp/outwhere
patch.diffcontainsThis gives
ninja: error: build.ninja:46: multiple rules generate /__init__.pyi [-w dupbuild=err].rchen152 commentedon Sep 8, 2020
Hmm, why are you running
pytype -P /tmp/out? -P is for paths to source code directories, whereas /tmp/out looks like it contains just-generated .imports and .pyi files.mrahtz commentedon Sep 13, 2020
I might well have been doing something silly here. I was trying to run pytype in type-check mode, using previously-generated stubs.
Looking through
pytype --help, I wasn't sure what-Pis supposed to do (why would you specify source code directories with-Prather than just specifying them as theinputargument?), but runningpytype-single --help, I saw there was a fuller description of-P, and took it to mean that it could be used to specify a directory with previously-generated stubs - and that this also applied to regularpytype. I guess this is not the case?rchen152 commentedon Sep 16, 2020
Ah, the
-Parguments topytypeandpytype-singleare similar but not quite the same. They're both for telling pytype where the dependencies of your input files are, but forpytype, you specify source files whereas forpytype-singleyou specify type stubs. You wouldn't just pass these files as inputs because they would then be type-checked.mrahtz commentedon Sep 16, 2020
Ahh, gotcha :) Thanks!
nirradi commentedon Oct 6, 2021
This reproduces every time for me if there's no __init__.py in the folder of one of the duplicates.
lucaswiman commentedon Sep 23, 2022
Agree with @nirradi that adding a missing
__init__.pyfixed the problem for me. To future visitors to this page: you may be missing__init__.pyfiles somewhere in your packages.Maybe the
multiple rules generateerror should be extended to include a note that pytype has poor compatibility with PEP 420 implicit namespace packages and to try adding__init__.pyfiles?rchen152 commentedon Sep 27, 2022
Aha, knowing that adding
__init__.pyfiles fixes the problem is helpful, thanks! It sounds like the issue is probably here:pytype/pytype/tools/environment.py
Lines 71 to 78 in 173a7a4
__init__.pyto find subpackages, which indeed does not work for implicit namespace packages.h-joo commentedon Aug 20, 2025
Hi, thank you for your report. Google is shifting its effort to a different approach for type checking apart from pytype, and we're not planning to put in any effort in the near future in pytype, so we'll close this issue. Please see the announcement here.