Skip to content

Commit

Permalink
Fix mypy error caused by cyclic import dependency.
Browse files Browse the repository at this point in the history
Add tests that source_info_util is using the same directory as the jax root module.
  • Loading branch information
hawkinsp committed Nov 18, 2020
1 parent f939e71 commit 13db2c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions jax/_src/source_info_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import threading
from typing import Any, Optional

import jax
import jax.version
from jax.lib import xla_client

from jax._src import traceback_util
Expand All @@ -27,7 +27,7 @@
Traceback = Any # xla_client.Traceback
Frame = Any # xla_client.Traceback::Frame

_jax_path = os.path.dirname(jax.__file__)
_jax_path = os.path.dirname(jax.version.__file__)

def user_frame(source_info: Optional[Traceback]) -> Optional[Frame]:
"""Heuristic that guesses the identity of the user's code in a stack trace."""
Expand Down
11 changes: 10 additions & 1 deletion tests/errors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.


import os
import re
import traceback
import unittest

from absl.testing import absltest

import jax
from jax import grad, jit, vmap
import jax.numpy as jnp
from jax import test_util as jtu
from jax._src import traceback_util
from jax._src import source_info_util


from jax.config import config
Expand Down Expand Up @@ -145,5 +147,12 @@ def outer(x):
self.assertIsInstance(e.__cause__.__cause__,
traceback_util.FilteredStackTrace)


class SourceInfoTest(jtu.JaxTestCase):

def testJaxPathMatchesSourceInfoPath(self):
self.assertEqual(source_info_util._jax_path, os.path.dirname(jax.__file__))


if __name__ == '__main__':
absltest.main(testLoader=jtu.JaxTestLoader())

0 comments on commit 13db2c3

Please sign in to comment.