Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/encoding.py @ 52671:cb769c0ffe35
pyupgrade: drop a usage of `typing.Text`
This is the `typing_text` fixer in `pyupgrade`. This type was meant to be for
py2/py3 interoperability, being bytes on py2 and str on py3.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 06 Jan 2025 00:38:32 -0500 |
parents | 5cc8deb96b48 |
children |
comparison
equal
deleted
inserted
replaced
52670:4cb75772818d | 52671:cb769c0ffe35 |
---|---|
14 import unicodedata | 14 import unicodedata |
15 | 15 |
16 from typing import ( | 16 from typing import ( |
17 Any, | 17 Any, |
18 Callable, | 18 Callable, |
19 Text, | |
20 TypeVar, | 19 TypeVar, |
21 ) | 20 ) |
22 | 21 |
23 from . import ( | 22 from . import ( |
24 error, | 23 error, |
384 def colwidth(s: bytes) -> int: | 383 def colwidth(s: bytes) -> int: |
385 """Find the column width of a string for display in the local encoding""" | 384 """Find the column width of a string for display in the local encoding""" |
386 return ucolwidth(s.decode(_sysstr(encoding), 'replace')) | 385 return ucolwidth(s.decode(_sysstr(encoding), 'replace')) |
387 | 386 |
388 | 387 |
389 def ucolwidth(d: Text) -> int: | 388 def ucolwidth(d: str) -> int: |
390 """Find the column width of a Unicode string for display""" | 389 """Find the column width of a Unicode string for display""" |
391 eaw = getattr(unicodedata, 'east_asian_width', None) | 390 eaw = getattr(unicodedata, 'east_asian_width', None) |
392 if eaw is not None: | 391 if eaw is not None: |
393 return sum([eaw(c) in _wide and 2 or 1 for c in d]) | 392 return sum([eaw(c) in _wide and 2 or 1 for c in d]) |
394 return len(d) | 393 return len(d) |