Patchwork D7008: py3: stop injecting pycompat.hasattr into modules

login
register
mail settings
Submitter phabricator
Date Oct. 6, 2019, 9:23 p.m.
Message ID <differential-rev-PHID-DREV-zzldjbnrxw2rbh574x4q-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/42049/
State Superseded
Headers show

Comments

phabricator - Oct. 6, 2019, 9:23 p.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  I only found a single user of this pattern, probably because we
  use util.hasattr everywhere.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D7008

AFFECTED FILES
  mercurial/__init__.py
  mercurial/pycompat.py
  mercurial/statprof.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel
phabricator - Oct. 7, 2019, 3:25 a.m.
martinvonz added inline comments.

INLINE COMMENTS

> statprof.py:171
>              self.sample_interval = 1.0 / frequency
> -        elif not hasattr(self, 'sample_interval'):
> +        elif not pycompat.hasattr(self, 'sample_interval'):
>              # default to 1000 Hz

Should we switch to `util.safehasattr()` for consistency?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7008/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7008

To: indygreg, #hg-reviewers
Cc: martinvonz, mercurial-devel
Augie Fackler - Oct. 7, 2019, 3:58 a.m.
I'd actually rather not - safehasattr is not required on py3.

On Sun, Oct 6, 2019 at 11:27 PM martinvonz (Martin von Zweigbergk)
<phabricator@mercurial-scm.org> wrote:
>
> martinvonz added inline comments.
>
> INLINE COMMENTS
>
> > statprof.py:171
> >              self.sample_interval = 1.0 / frequency
> > -        elif not hasattr(self, 'sample_interval'):
> > +        elif not pycompat.hasattr(self, 'sample_interval'):
> >              # default to 1000 Hz
>
> Should we switch to `util.safehasattr()` for consistency?
>
> REPOSITORY
>   rHG Mercurial
>
> CHANGES SINCE LAST ACTION
>   https://phab.mercurial-scm.org/D7008/new/
>
> REVISION DETAIL
>   https://phab.mercurial-scm.org/D7008
>
> To: indygreg, #hg-reviewers
> Cc: martinvonz, mercurial-devel
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/statprof.py b/mercurial/statprof.py
--- a/mercurial/statprof.py
+++ b/mercurial/statprof.py
@@ -168,7 +168,7 @@ 
         # a float
         if frequency:
             self.sample_interval = 1.0 / frequency
-        elif not hasattr(self, 'sample_interval'):
+        elif not pycompat.hasattr(self, 'sample_interval'):
             # default to 1000 Hz
             self.sample_interval = 1.0 / 1000.0
         else:
diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -355,6 +355,7 @@ 
     strurl = identity
     bytesurl = identity
     open = open
+    hasattr = hasattr
     setattr = setattr
 
     # this can't be parsed on Python 3
diff --git a/mercurial/__init__.py b/mercurial/__init__.py
--- a/mercurial/__init__.py
+++ b/mercurial/__init__.py
@@ -171,7 +171,7 @@ 
                 r, c = t.start
                 l = (
                     b'; from mercurial.pycompat import '
-                    b'delattr, getattr, hasattr\n'
+                    b'delattr, getattr\n'
                 )
                 for u in tokenize.tokenize(io.BytesIO(l).readline):
                     if u.type in (tokenize.ENCODING, token.ENDMARKER):
@@ -220,7 +220,7 @@ 
     # ``replacetoken`` or any mechanism that changes semantics of module
     # loading is changed. Otherwise cached bytecode may get loaded without
     # the new transformation mechanisms applied.
-    BYTECODEHEADER = b'HG\x00\x0f'
+    BYTECODEHEADER = b'HG\x00\x10'
 
     class hgloader(importlib.machinery.SourceFileLoader):
         """Custom module loader that transforms source code.