示例#1
0
def parse_str_as_signature(typestr: str, line: int) -> CallableType:
    """Parse a signature represented as a string.

    Raise TypeParseError on parse error.
    """

    typestr = typestr.strip()
    tokens = lex(typestr, line)[0]
    result, i = parse_signature(tokens)
    if i < len(tokens) - 2:
        raise TypeParseError(tokens[i], i)
    return result
示例#2
0
def parse_str_as_type(typestr: str, line: int) -> Type:
    """Parse a type represented as a string.

    Raise TypeParseError on parse error.
    """
    
    typestr = typestr.strip()
    tokens = lex(typestr, line)
    result, i = parse_type(tokens, 0)
    if i < len(tokens) - 2:
        raise TypeParseError(tokens[i], i)
    return result
示例#3
0
def parse_str_as_type(typestr: str, line: int) -> Type:
    """Parse a type represented as a string.

    Raise TypeParseError on parse error.
    """

    typestr = typestr.strip()
    tokens = lex(typestr, line)[0]
    result, i = parse_type(tokens, 0)
    if i < len(tokens) - 2:
        raise TypeParseError(tokens[i], i)
    return result
示例#4
0
文件: testlex.py 项目: SRiikonen/mypy
 def assert_line(self, s, a):
     s = s.replace('\\n', '\n')
     s = s.replace('\\r', '\r')
     
     tt = lex(s)
     r = []
     for t in tt:
         r.append(t.line)
     if len(r) == len(a) + 2:
         a = a[:]
         a.append(a[-1])
         a.append(a[-1])
     assert_equal(r, a)
示例#5
0
    def assert_line(self, s, a):
        s = s.replace('\\n', '\n')
        s = s.replace('\\r', '\r')

        tt = lex(s)[0]
        r = []
        for t in tt:
            r.append(t.line)
        if len(r) == len(a) + 2:
            a = a[:]
            a.append(a[-1])
            a.append(a[-1])
        assert_equal(r, a)
示例#6
0
    def assert_line(self, s: str, a: List[int]) -> None:
        s = s.replace('\\n', '\n')
        s = s.replace('\\r', '\r')

        tt = lex(s)[0]
        r = []
        for t in tt:
            r.append(t.line)
        if len(r) == len(a) + 2:
            a = a[:]
            a.append(a[-1])
            a.append(a[-1])
        assert_equal(r, a)
示例#7
0
文件: testlex.py 项目: SRiikonen/mypy
 def assert_lex(self, src, lexed):
     src = src.replace('\\n', '\n')
     src = src.replace('\\r', '\r')
     
     if lexed.endswith(' ...'):
         lexed = lexed[:-3] + 'Break() Eof()'
     
     l = lex(src)
     r = []
     for t in l:
         r.append(str(t))
     act = ' '.join(r)
     if act != lexed:
         print('Actual:  ', act)
         print('Expected:', lexed)
     assert_equal(act, lexed)
示例#8
0
    def assert_lex(self, src, lexed):
        src = src.replace('\\n', '\n')
        src = src.replace('\\r', '\r')

        if lexed.endswith(' ...'):
            lexed = lexed[:-3] + 'Break() Eof()'

        l = lex(src)
        r = []
        for t in l:
            r.append(str(t))
        act = ' '.join(r)
        if act != lexed:
            print('Actual:  ', act)
            print('Expected:', lexed)
        assert_equal(act, lexed)
示例#9
0
    def assert_lex(self, src: Union[str, bytes], lexed: str) -> None:
        if isinstance(src, str):
            src = src.replace('\\n', '\n')
            src = src.replace('\\r', '\r')

        if lexed.endswith(' ...'):
            lexed = lexed[:-3] + 'Break() Eof()'

        l = lex(src)[0]
        r = []
        for t in l:
            r.append(str(t))
        act = ' '.join(r)
        if act != lexed:
            print('Actual:  ', act)
            print('Expected:', lexed)
        assert_equal(act, lexed)
示例#10
0
文件: testlex.py 项目: wlmgithub/mypy
    def assert_lex(self, src: Union[str, bytes], lexed: str) -> None:
        if isinstance(src, str):
            src = src.replace('\\n', '\n')
            src = src.replace('\\r', '\r')

        if lexed.endswith(' ...'):
            lexed = lexed[:-3] + 'Break() Eof()'

        l = lex(src)[0]
        r = []
        for t in l:
            r.append(str(t))
        act = ' '.join(r)
        if act != lexed:
            print('Actual:  ', act)
            print('Expected:', lexed)
        assert_equal(act, lexed)