Mercurial > public > mercurial-scm > hg-stable
diff i18n/polib.py @ 52665:24ee91ba9aa8
pyupgrade: drop usage of py3 aliases for `OSError`
These were different classes in py2, but now a handful of error classes are just
an alias of `OSError`, like `IOError`, `EnvironmentError`, `WindowsError`, etc.
This is the result of running a hacked version of `pyupgrade` 3.19.1[1]
$ hg files -0 'relglob:**.py' | xargs -0 \
pyupgrade --py38-plus --keep-percent-format --keep-mock --keep-runtime-typing
The hack is because it doesn't have command line switches to disable most
changes, so it makes tons of unrelated changes all at once. The hack is to
1) patch `pyupgrade._main._fix_tokens()` to immediately return its content arg
2) change `pyupgrade._data.register_decorator()` to only register the function
if it's from the fixer we're interested in:
if func.__module__ in (
"pyupgrade._plugins.exceptions",
):
FUNCS[tp].append(func)
return func
[1] https://github.com/asottile/pyupgrade
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 05 Jan 2025 21:03:17 -0500 |
parents | f4733654f144 |
children | 5cc8deb96b48 |
line wrap: on
line diff
--- a/i18n/polib.py Mon Jan 06 14:15:40 2025 -0500 +++ b/i18n/polib.py Sun Jan 05 21:03:17 2025 -0500 @@ -459,7 +459,7 @@ string, the method to use for output. """ if self.fpath is None and fpath is None: - raise IOError('You must provide a file path to save() method') + raise OSError('You must provide a file path to save() method') contents = getattr(self, repr_method)() if fpath is None: fpath = self.fpath @@ -1393,7 +1393,7 @@ if tokens[0] in keywords and nb_tokens > 1: line = line[len(tokens[0]) :].lstrip() if re.search(r'([^\\]|^)"', line[1:-1]): - raise IOError( + raise OSError( 'Syntax error in po file %s (line %s): ' 'unescaped double quote found' % (self.instance.fpath, self.current_line) @@ -1413,7 +1413,7 @@ elif line[:1] == '"': # we are on a continuation line if re.search(r'([^\\]|^)"', line[1:-1]): - raise IOError( + raise OSError( 'Syntax error in po file %s (line %s): ' 'unescaped double quote found' % (self.instance.fpath, self.current_line) @@ -1444,7 +1444,7 @@ elif tokens[0] == '#|': if nb_tokens <= 1: - raise IOError( + raise OSError( 'Syntax error in po file %s (line %s)' % (self.instance.fpath, self.current_line) ) @@ -1460,7 +1460,7 @@ if nb_tokens == 2: # Invalid continuation line. - raise IOError( + raise OSError( 'Syntax error in po file %s (line %s): ' 'invalid continuation line' % (self.instance.fpath, self.current_line) @@ -1469,7 +1469,7 @@ # we are on a "previous translation" comment line, if tokens[1] not in prev_keywords: # Unknown keyword in previous translation comment. - raise IOError( + raise OSError( 'Syntax error in po file %s (line %s): ' 'unknown keyword %s' % (self.instance.fpath, self.current_line, tokens[1]) @@ -1482,7 +1482,7 @@ self.process(prev_keywords[tokens[1]]) else: - raise IOError( + raise OSError( 'Syntax error in po file %s (line %s)' % (self.instance.fpath, self.current_line) ) @@ -1554,7 +1554,7 @@ if action(): self.current_state = state except Exception: - raise IOError( + raise OSError( 'Syntax error in po file (line %s)' % self.current_line ) @@ -1759,14 +1759,14 @@ elif magic_number == MOFile.MAGIC_SWAPPED: ii = '>II' else: - raise IOError('Invalid mo file, magic number is incorrect !') + raise OSError('Invalid mo file, magic number is incorrect !') self.instance.magic_number = magic_number # parse the version number and the number of strings version, numofstrings = self._readbinary(ii, 8) # from MO file format specs: "A program seeing an unexpected major # revision number should stop reading the MO file entirely" if version not in (0, 1): - raise IOError('Invalid mo file, unexpected major revision number') + raise OSError('Invalid mo file, unexpected major revision number') self.instance.version = version # original strings and translation strings hash table offset msgids_hash_offset, msgstrs_hash_offset = self._readbinary(ii, 8)