comparison mercurial/ui.py @ 49888:8147abc05794

pytype: stop excluding mercurial/ui.py ui.extractchoices() is perhaps making assumptions that it shouldn't about the pattern always matching, but presumably we have test coverage for that. PyCharm flags the updated classes with a warning "Class xxx must implement all abstract methods", and suggests adding `abc.ABC` to the superclasses. I'm not sure why, unless it doesn't recognize the `__getattr__()` delegation pattern. Additionally, we can't unconditionally subclass `typing.BinaryIO` because that defeats the `__getattr__` delegation to the wrapped object at runtime. Instead, it has to only subclass during the type checking phase[1]. In any event, this fixes: File "/mnt/c/Users/Matt/hg/mercurial/ui.py", line 1518, in _runpager: Function subprocess.Popen.__new__ was called with the wrong arguments [wrong-arg-types] Expected: (cls, args, bufsize, executable, stdin, stdout: Optional[Union[IO, int]] = ..., ...) Actually passed: (cls, args, bufsize, stdin, stdout: Union[mercurial.utils.procutil.WriteAllWrapper, mercurial.windows.winstdout], ...) File "/mnt/c/Users/Matt/hg/mercurial/ui.py", line 1798, in extractchoices: No attribute 'group' on None [attribute-error] In Optional[Match[bytes]] File "/mnt/c/Users/Matt/hg/mercurial/ui.py", line 1799, in extractchoices: No attribute 'group' on None [attribute-error] In Optional[Match[bytes]] [1] https://stackoverflow.com/q/71365594
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 25 Nov 2022 18:39:47 -0500
parents 2e726c934fcd
children 25fe689a4a64
comparison
equal deleted inserted replaced
49887:e1953a34c110 49888:8147abc05794
1793 # containing "$$" so let's try to find the first valid-looking 1793 # containing "$$" so let's try to find the first valid-looking
1794 # prompt to start parsing. Sadly, we also can't rely on 1794 # prompt to start parsing. Sadly, we also can't rely on
1795 # choices containing spaces, ASCII, or basically anything 1795 # choices containing spaces, ASCII, or basically anything
1796 # except an ampersand followed by a character. 1796 # except an ampersand followed by a character.
1797 m = re.match(br'(?s)(.+?)\$\$([^$]*&[^ $].*)', prompt) 1797 m = re.match(br'(?s)(.+?)\$\$([^$]*&[^ $].*)', prompt)
1798
1799 assert m is not None # help pytype
1800
1798 msg = m.group(1) 1801 msg = m.group(1)
1799 choices = [p.strip(b' ') for p in m.group(2).split(b'$$')] 1802 choices = [p.strip(b' ') for p in m.group(2).split(b'$$')]
1800 1803
1801 def choicetuple(s): 1804 def choicetuple(s):
1802 ampidx = s.index(b'&') 1805 ampidx = s.index(b'&')