##// END OF EJS Templates
typing: mark the argument to mercurial.i18n.gettext() non-Optional...
typing: mark the argument to mercurial.i18n.gettext() non-Optional Few if any of the callers are handling a `None` return, which is making pytype complain. I tried adding @overload definitions to indicate the bytes -> bytes and None -> None relationship, but pytype doesn't seem to apply that to `_()` through the function assignment. What did work was to change `_()` into its own function that called `gettext()`, but that has an extra function call overhead. Even putting that function into an `if pycompat.TYPE_CHECKING` block and leaving the existing assignments in the `else` block caused pytype to lose track of the @overloads. At that point, I simply gave up. PyCharm doesn't like that it can return None, given the new type hints, but pytype doesn't complain about this nor does it see any callers passing None. The most important thing here is to catch str being passed anyway. Differential Revision: https://phab.mercurial-scm.org/D10235

File last commit:

r46179:07731064 5.5.2 stable
r47564:2c0e35f6 default
Show More
__init__.py
84 lines | 2.5 KiB | text/x-python | PythonLexer
Siddharth Agarwal
demandimport: move to separate package...
r32420 # hgdemandimport - global demand-loading of modules for Mercurial
#
# Copyright 2017 Facebook Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
'''demandimport - automatic demand-loading of modules'''
# This is in a separate package from mercurial because in Python 3,
# demand loading is per-package. Keeping demandimport in the mercurial package
# would disable demand loading for any modules in mercurial.
from __future__ import absolute_import
Jun Wu
demandimport: move HGDEMANDIMPORT test to __init__.py...
r33861 import os
Siddharth Agarwal
demandimport: move ignore list to __init__.py...
r32422 import sys
Siddharth Agarwal
demandimport: add python 3 implementation...
r32423 if sys.version_info[0] >= 3:
from . import demandimportpy3 as demandimport
else:
from . import demandimportpy2 as demandimport
Siddharth Agarwal
demandimport: move to separate package...
r32420
Gregory Szorc
demandimport: make module ignores a set (API)...
r37862 # Full module names which can't be lazy imported.
# Extensions can add to this set.
IGNORES = {
Siddharth Agarwal
demandimport: move ignore list to __init__.py...
r32422 '__future__',
'_hashlib',
# ImportError during pkg_resources/__init__.py:fixup_namespace_package
'_imp',
'_xmlplus',
'fcntl',
Augie Fackler
formatting: blacken the codebase...
r43346 'nt', # pathlib2 tests the existence of built-in 'nt' module
Siddharth Agarwal
demandimport: move ignore list to __init__.py...
r32422 'win32com.gen_py',
Augie Fackler
formatting: blacken the codebase...
r43346 'win32com.shell', # 'appdirs' tries to import win32com.shell
'_winreg', # 2.7 mimetypes needs immediate ImportError
Siddharth Agarwal
demandimport: move ignore list to __init__.py...
r32422 'pythoncom',
# imported by tarfile, not available under Windows
'pwd',
'grp',
# imported by profile, itself imported by hotshot.stats,
# not available under Windows
'resource',
# this trips up many extension authors
'gtk',
# setuptools' pkg_resources.py expects "from __main__ import x" to
# raise ImportError if x not defined
'__main__',
Augie Fackler
hgdemandimport: bypass demandimport for _ast module (issue6407)...
r46006 '_ast', # https://bugs.python.org/issue41631
Augie Fackler
formatting: blacken the codebase...
r43346 '_ssl', # conditional imports in the stdlib, issue1964
'_sre', # issue4920
Siddharth Agarwal
demandimport: move ignore list to __init__.py...
r32422 'rfc822',
'mimetools',
Augie Fackler
formatting: blacken the codebase...
r43346 'sqlalchemy.events', # has import-time side effects (issue5085)
Ludovic Chabant
hgdemandimport: exclude more sqlalchemy modules...
r46179 'sqlalchemy.dialects', # similar problems as above
Siddharth Agarwal
demandimport: move ignore list to __init__.py...
r32422 # setuptools 8 expects this module to explode early when not on windows
'distutils.msvc9compiler',
'__builtin__',
'builtins',
Augie Fackler
formatting: blacken the codebase...
r43346 'urwid.command_map', # for pudb
Manuel Jacob
demandimport: ignore `lzma` module for demandimport...
r45600 'lzma',
Gregory Szorc
demandimport: make module ignores a set (API)...
r37862 }
Siddharth Agarwal
demandimport: move ignore list to __init__.py...
r32422
_pypy = '__pypy__' in sys.builtin_module_names
if _pypy:
Gregory Szorc
demandimport: make module ignores a set (API)...
r37862 # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5)
IGNORES.add('_ctypes.pointer')
Siddharth Agarwal
demandimport: move ignore list to __init__.py...
r32422
Gregory Szorc
demandimport: make module ignores a set (API)...
r37862 demandimport.init(IGNORES)
Siddharth Agarwal
demandimport: move ignore list to __init__.py...
r32422
Siddharth Agarwal
demandimport: move to separate package...
r32420 # Re-export.
isenabled = demandimport.isenabled
disable = demandimport.disable
deactivated = demandimport.deactivated
Jun Wu
demandimport: move HGDEMANDIMPORT test to __init__.py...
r33861
Augie Fackler
formatting: blacken the codebase...
r43346
Jun Wu
demandimport: move HGDEMANDIMPORT test to __init__.py...
r33861 def enable():
Jun Wu
demandimport: disable if chg is being used...
r33862 # chg pre-imports modules so do not enable demandimport for it
Augie Fackler
formatting: blacken the codebase...
r43346 if (
'CHGINTERNALMARK' not in os.environ
and os.environ.get('HGDEMANDIMPORT') != 'disable'
):
Jun Wu
demandimport: move HGDEMANDIMPORT test to __init__.py...
r33861 demandimport.enable()