Mercurial > public > mercurial-scm > hg
comparison mercurial/scmutil.py @ 50925:d718eddf01d9
safehasattr: drop usage in favor of hasattr
The two functions should now be equivalent at least in their usage in core.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 31 Aug 2023 23:56:15 +0200 |
parents | b3174be5e7f7 |
children | 18c8c18993f0 |
comparison
equal
deleted
inserted
replaced
50924:7a8ea1397816 | 50925:d718eddf01d9 |
---|---|
231 if isinstance(reason, str): | 231 if isinstance(reason, str): |
232 # SSLError of Python 2.7.9 contains a unicode | 232 # SSLError of Python 2.7.9 contains a unicode |
233 reason = encoding.unitolocal(reason) | 233 reason = encoding.unitolocal(reason) |
234 ui.error(_(b"abort: error: %s\n") % stringutil.forcebytestr(reason)) | 234 ui.error(_(b"abort: error: %s\n") % stringutil.forcebytestr(reason)) |
235 except (IOError, OSError) as inst: | 235 except (IOError, OSError) as inst: |
236 if ( | 236 if hasattr(inst, "args") and inst.args and inst.args[0] == errno.EPIPE: |
237 util.safehasattr(inst, "args") | |
238 and inst.args | |
239 and inst.args[0] == errno.EPIPE | |
240 ): | |
241 pass | 237 pass |
242 elif getattr(inst, "strerror", None): # common IOError or OSError | 238 elif getattr(inst, "strerror", None): # common IOError or OSError |
243 if getattr(inst, "filename", None) is not None: | 239 if getattr(inst, "filename", None) is not None: |
244 ui.error( | 240 ui.error( |
245 _(b"abort: %s: '%s'\n") | 241 _(b"abort: %s: '%s'\n") |
559 hexnode = hex(node) | 555 hexnode = hex(node) |
560 nodetree = None | 556 nodetree = None |
561 if cache is not None: | 557 if cache is not None: |
562 nodetree = cache.get(b'disambiguationnodetree') | 558 nodetree = cache.get(b'disambiguationnodetree') |
563 if not nodetree: | 559 if not nodetree: |
564 if util.safehasattr(parsers, 'nodetree'): | 560 if hasattr(parsers, 'nodetree'): |
565 # The CExt is the only implementation to provide a nodetree | 561 # The CExt is the only implementation to provide a nodetree |
566 # class so far. | 562 # class so far. |
567 index = cl.index | 563 index = cl.index |
568 if util.safehasattr(index, 'get_cindex'): | 564 if hasattr(index, 'get_cindex'): |
569 # the rust wrapped need to give access to its internal index | 565 # the rust wrapped need to give access to its internal index |
570 index = index.get_cindex() | 566 index = index.get_cindex() |
571 nodetree = parsers.nodetree(index, len(revs)) | 567 nodetree = parsers.nodetree(index, len(revs)) |
572 for r in revs: | 568 for r in revs: |
573 nodetree.insert(r) | 569 nodetree.insert(r) |
1064 assert fixphase or targetphase is None | 1060 assert fixphase or targetphase is None |
1065 if not replacements and not moves: | 1061 if not replacements and not moves: |
1066 return | 1062 return |
1067 | 1063 |
1068 # translate mapping's other forms | 1064 # translate mapping's other forms |
1069 if not util.safehasattr(replacements, 'items'): | 1065 if not hasattr(replacements, 'items'): |
1070 replacements = {(n,): () for n in replacements} | 1066 replacements = {(n,): () for n in replacements} |
1071 else: | 1067 else: |
1072 # upgrading non tuple "source" to tuple ones for BC | 1068 # upgrading non tuple "source" to tuple ones for BC |
1073 repls = {} | 1069 repls = {} |
1074 for key, value in replacements.items(): | 1070 for key, value in replacements.items(): |