comparison mercurial/encoding.py @ 51673:f70f61a8c5bc

typing: restore `encoding.encoding` and `encoding.encodingmode` to bytes Somewhere between hg 3dbc7b1ecaba and hg 8e3f6b5bf720, pytype determined the signature of these fields changed from `bytes` to `Any`. Not sure why- the type of `environ` then and now is: `Union[WindowsEnviron, Dict[bytes, bytes], os._Environ[bytes]]` That said, PyCharm wasn't able to figure out the type of `environ`, and the `WindowsEnviron` class extends `MutableMapping` without specifying bytes for the key and value types in py3.9. But that's not changed in my setup, so I can't explain it.
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 10 Jul 2024 17:37:35 -0400
parents f4a0806081f2
children 493034cc3265
comparison
equal deleted inserted replaced
51672:138ab7c6a6ff 51673:f70f61a8c5bc
101 # No idea if it should be rewritten to the canonical name 'utf-8' on Python 3. 101 # No idea if it should be rewritten to the canonical name 'utf-8' on Python 3.
102 # https://bugs.python.org/issue13216 102 # https://bugs.python.org/issue13216
103 if pycompat.iswindows: 103 if pycompat.iswindows:
104 _encodingrewrites[b'cp65001'] = b'utf-8' 104 _encodingrewrites[b'cp65001'] = b'utf-8'
105 105
106 encoding: bytes = b'' # help pytype avoid seeing None value
106 try: 107 try:
107 encoding = environ.get(b"HGENCODING") 108 encoding = environ.get(b"HGENCODING", b'')
108 if not encoding: 109 if not encoding:
109 encoding = locale.getpreferredencoding().encode('ascii') or b'ascii' 110 encoding = locale.getpreferredencoding().encode('ascii') or b'ascii'
110 encoding = _encodingrewrites.get(encoding, encoding) 111 encoding = _encodingrewrites.get(encoding, encoding)
111 except locale.Error: 112 except locale.Error:
112 encoding = b'ascii' 113 encoding = b'ascii'
113 encodingmode = environ.get(b"HGENCODINGMODE", b"strict") 114 encodingmode: bytes = environ.get(b"HGENCODINGMODE", b"strict")
114 fallbackencoding = b'ISO-8859-1' 115 fallbackencoding = b'ISO-8859-1'
115 116
116 117
117 class localstr(bytes): 118 class localstr(bytes):
118 """This class allows strings that are unmodified to be 119 """This class allows strings that are unmodified to be