imp.cache_from_source() (and thus also imp.source_from_cache()) has special semantics compared to how os.path.join() works. For instance, if you look at test_imp you will notice it tries to use the same path separator as is the farthest right in the path it is given::<div>

<br></div><div><div>  self.assertEqual(imp.cache_from_source(&#39;\\foo\\bar/baz/qux.py&#39;, True), &#39;\\foo\\bar\\baz/__pycache__/qux.{}.pyc&#39;.format(self.tag))</div><div><br></div><div>But if you do the same basic operation using ntpath, you will notice it simply doesn&#39;t care::</div>

<div><br></div><div><div>  &gt;&gt;&gt; ntpath.join(ntpath.split(&#39;a\\b/c/d.py&#39;)[0], &#39;__pycache__&#39;, &#39;d.cpython-32.pyc&#39;)</div><div>  &#39;a\\b/c\\__pycache__\\d.cpython-32.pyc</div></div><div><br></div>

<div>Basically imp.cache_from_source() goes to a bunch of effort to reuse the farthest right separator when there is an alternative separator *before* and path splitting is done. But if you look at ntpath.join(), it doesn&#39;t even attempt that much effort.<br>

<div><br></div><div>Now that we can reuse os.path.join() (directly for source_from_cache(), indirectly through easy algorithmic copying in cache_from_source()) do we want to keep the &quot;special&quot; semantics, or can I change it to match what ntpath would do when there can be more than one path separator on an OS (i.e. not do anything special)?</div>

</div></div>