[PATCH 1 of 6] util: add event handling mechanism

Matt Mackall mpm at selenic.com
Thu Aug 21 17:10:32 CDT 2014


On Wed, 2014-08-20 at 09:16 -0700, Gregory Szorc wrote:
> On 8/19/14 11:22 PM, Matt Mackall wrote:
> > On Mon, 2014-08-18 at 22:53 -0700, Gregory Szorc wrote:
> >> On 8/18/2014 10:30 PM, Gregory Szorc wrote:
> >>> # HG changeset patch
> >>> # User Gregory Szorc <gregory.szorc at gmail.com>
> >>> # Date 1408422497 25200
> >>> #      Mon Aug 18 21:28:17 2014 -0700
> >>> # Node ID 110ff56e99e2ccff03841cc8baeed7f14c35f69b
> >>> # Parent  8dda6f6ff564d8fe6ac7b8ce4c74eb9bfb5de14a
> >>> util: add event handling mechanism
> >>
> >>> diff --git a/tests/test-eventmanager.py b/tests/test-eventmanager.py
> >>> new file mode 100644
> >>> --- /dev/null
> >>> +++ b/tests/test-eventmanager.py
> >>> @@ -0,0 +1,109 @@
> >>> +from mercurial.util import event, eventmanager, safehasattr
> >>> +
> >>> +import unittest
> >>> +import silenttestrunner
> >>> +
> >>> +class testeventmanager(unittest.TestCase):
> >>> +    def test_eventsimple(self):
> >>
> >> test-check-commit-hg.t doesn't like this commit because it is
> >> introducing a function with underscores. But I just stole this naming
> >> convention from other unittest-based .py tests. I'm not sure who is in
> >> the wrong here.
> >
> > The unittest framework is wrong, as is most of the Python standard
> > library: just compare it to the core language.
> 
> PEP-8 says to use functions_with_underscores not functionsasoneword. 
> unittest is a bit inconsistent: unittest.TestCase has both camelCase and 
> lowercase methods. I'm not sure whether this is historical or an attempt 
> to distinguish and/or avoid conflicts between unittest "core" APIs and 
> user/test-supplied code.
> 
> Viewed through PEP-8, Mercurial's style convention is what's "wrong."

Please do "pydoc list|dict|file|str|etc" and count the separators. Also
look at dir(__builtins__). It's clear that Python's core style is no
separator. About the only common exception to the rule in the core
language is dict.has_key.. and that got removed in Py3.

The actual PEP8 recommendation is:

"Function names should be lowercase, with words separated by underscores
as necessary to improve readability."

The second clause has that vague "as necessary" which in practice means
"when random developer feels like it". This was a mistake, because they
ended up sacrificing a huge amount of consistency (aka writability) for
a pretty small amount of readability. And it even allows monstrosities
like "set_debuglevel" because it doesn't even suggest you should be
consistent inside a single identifier! They should have chose one way or
the other, always... and the obvious choice would have been _to match
the language itself_.

So I recommend reading that "as necessary" as "never".

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list