D7380: encoding: define per-use identity functions only in typechecking mode
yuja added a comment. > strtolocal = pycompat.identity # type: (str) -> bytes > strfromlocal = pycompat.identity # type: (bytes) -> str `# type: Callable[[str], bytes]` might work. pytype complained `# type: ... -> ...` is an invalid type comment. REPOSITORY rHG Mercurial CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7380/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7380 To: durin42, #hg-reviewers Cc: yuja, dlax, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: D7380: encoding: define per-use identity functions only in typechecking mode
> strtolocal = pycompat.identity # type: (str) -> bytes > strfromlocal = pycompat.identity # type: (bytes) -> str `# type: Callable[[str], bytes]` might work. pytype complained `# type: ... -> ...` is an invalid type comment. ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D7380: encoding: define per-use identity functions only in typechecking mode
dlax added a comment. Have you tried using variables annotations? Like: strtolocal = pycompat.identity # type: (str) -> bytes strfromlocal = pycompat.identity # type: (bytes) -> str REPOSITORY rHG Mercurial CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7380/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7380 To: durin42, #hg-reviewers Cc: dlax, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D7380: encoding: define per-use identity functions only in typechecking mode
durin42 added a comment. Let's not land this for now: it's breaking a fair amount of typechecking. :( REPOSITORY rHG Mercurial CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7380/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7380 To: durin42, #hg-reviewers Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D7380: encoding: define per-use identity functions only in typechecking mode
durin42 created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY This avoids some unfortunate overhead from my previous iteration. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D7380 AFFECTED FILES mercurial/encoding.py CHANGE DETAILS diff --git a/mercurial/encoding.py b/mercurial/encoding.py --- a/mercurial/encoding.py +++ b/mercurial/encoding.py @@ -25,6 +25,7 @@ Any, Callable, List, +TYPE_CHECKING, Text, Type, TypeVar, @@ -32,7 +33,7 @@ ) # keep pyflakes happy -for t in (Any, Callable, List, Text, Type, Union): +for t in (Any, Callable, List, Text, Type, Union, TYPE_CHECKING): assert t _Tlocalstr = TypeVar('_Tlocalstr', bound=localstr) @@ -265,16 +266,20 @@ strfromlocal = unifromlocal strmethod = unimethod else: +strtolocal = pycompat.identity +strfromlocal = pycompat.identity +strmethod = pycompat.identity -def strtolocal(s): -# type: (str) -> bytes -return s +if 'TYPE_CHECKING' in globals() and TYPE_CHECKING: -def strfromlocal(s): -# type: (bytes) -> str -return s +def strtolocal(s): +# type: (str) -> bytes +return s -strmethod = pycompat.identity +def strfromlocal(s): +# type: (bytes) -> str +return s + if not _nativeenviron: # now encoding and helper functions are available, recreate the environ To: durin42, #hg-reviewers Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel