Mercurial > public > mercurial-scm > hg
comparison mercurial/mdiff.py @ 51928:d94e21b5b693
mdiff: tweak calls into `bdiff.fixws` to match its type hints
It turns out that protocol classes can be used for modules too, which is great
because all of the dynamically loaded modules (and their attributes) are
currently inferred as `Any`. See the next commit for details.
A protocol class for the `bdiff` module detected this (trivial) mismatch, so
correct it first. The various implementations of this method are typed as
taking a `bool`. The `cext` implementation parses its arguments with
`PyArg_ParseTuple(args, "Sb:fixws", &s, &allws)`, which wants an `int`. But
experimenting in `hg debugshell` under py38, passing `True` or `False` to
`cext.fixws()` also works. We can change the implementation to use "p" (which
was introduced in py33) instead of "b", but that's beyond the scope of this.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 28 Sep 2024 19:11:39 -0400 |
parents | f4733654f144 |
children | f2832de2a46c |
comparison
equal
deleted
inserted
replaced
51927:2d51b0cf707c | 51928:d94e21b5b693 |
---|---|
103 defaultopts = diffopts() | 103 defaultopts = diffopts() |
104 | 104 |
105 | 105 |
106 def wsclean(opts, text, blank=True): | 106 def wsclean(opts, text, blank=True): |
107 if opts.ignorews: | 107 if opts.ignorews: |
108 text = bdiff.fixws(text, 1) | 108 text = bdiff.fixws(text, True) |
109 elif opts.ignorewsamount: | 109 elif opts.ignorewsamount: |
110 text = bdiff.fixws(text, 0) | 110 text = bdiff.fixws(text, False) |
111 if blank and opts.ignoreblanklines: | 111 if blank and opts.ignoreblanklines: |
112 text = re.sub(b'\n+', b'\n', text).strip(b'\n') | 112 text = re.sub(b'\n+', b'\n', text).strip(b'\n') |
113 if opts.ignorewseol: | 113 if opts.ignorewseol: |
114 text = re.sub(br'[ \t\r\f]+\n', br'\n', text) | 114 text = re.sub(br'[ \t\r\f]+\n', br'\n', text) |
115 return text | 115 return text |