Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

unittest types not being pulled from typeshed #301

Closed

Description

Simplified case:

import unittest

class Simple(unittest.TestCase):
    def test_success(self):
        self.assertEqual(42, 42)

    def test_exception(self):
        with self.assertRaises(Exception) as em:
            raise Exception

These have typeshed types:

def assertEqual(self, first: Any, second: Any, msg: Any = ...) -> None: ...

@overload
    def assertRaises(self,
                     exception: Union[Type[_E], Tuple[Type[_E], ...]],
                     msg: Any = ...) -> _AssertRaisesContext[_E]: ...

But in VSC you see:

image

The parameter types aren't shown for assertEqual, and there are no type hints for em in test_exception (not shown in the screenshot).

Activity

  1. MikhailArkhipov commented on Oct 23, 2018

    @MikhailArkhipov

    In Python 2 we don't use typeshed since basic analysis gives better results as source is in Python. In 3. we do pull typeshed, see #277, but all we get is exception since

    class _AssertRaisesContext(Generic[_E]):
        exception = ...  # type: _E
        def __enter__(self) -> _AssertRaisesContext[_E]: ...
        def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException],
                     exc_tb: Optional[TracebackType]) -> bool: ...
  2. jakebailey commented on Oct 23, 2018

    @jakebailey
    MemberAuthor

    Shouldn't there be more info than just "bound built-in method" regardless? I did my testing in 3.6 (also checking tensorflow analysis), and if typeshed info is really being used then I would have thought I'd see more info on both of these functions (and others).

    Expanding the exception example out to:

        def test_exception(self):
            with self.assertRaises(Exception) as em:
                raise Exception
            exc = em.exception

    em.exception does't show any types, so I don't think we're getting exception at all.

  3. MikhailArkhipov commented on Oct 23, 2018

    @MikhailArkhipov

    There are probably issues with TypeVar declarations

    _T = TypeVar('_T')
    _FT = TypeVar('_FT', bound=Callable[..., Any])
    _E = TypeVar('_E', bound=Exception)

    ex #254

  4. MikhailArkhipov commented on Oct 25, 2018

    @MikhailArkhipov

    Same as #254

  5. qubitron commented on Nov 8, 2018

    @qubitron

    I tried Jake's example above and the completions returned are very limited:
    image

    Compared to the following with Jedi:
    image

    Is Jedi over-including?

  6. MikhailArkhipov commented on Nov 8, 2018

    @MikhailArkhipov

    No. Is it Python 2 or 3 and what LS version is it.

  7. MikhailArkhipov commented on Nov 8, 2018

    @MikhailArkhipov

    2:
    image

    3:
    image

  8. qubitron commented on Nov 8, 2018

    @qubitron

    False alarm, I was on old version of extension, this works for me now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingduplicateThis issue or pull request already exists

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions