Skip to content
Myr

Warn about the use of unicode_literals

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 36f83d9 · Browse files · 6 files+67 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+67 added−2 removed

  • other:+67 added−2 removed

6 files+67 added−2 removed

modified:click/__init__.py+5 added
86 unmodified lines
87 'OptionParser',88]899091# Controls if click should emit the warning about the use of unicode92# literals.93disable_unicode_literals_warning = False949596__version__ = '5.0-dev'
modified:click/_compat.py+35 added
3 unmodified lines
4import sys5import codecs6from weakref import WeakKeyDictionary78import click91011PY2 = sys.version_info[0] == 212WIN = sys.platform.startswith('win')13DEFAULT_COLUMNS = 80141516_ansi_re = re.compile('\033\[((?:\d|;)*)([a-zA-Z])')171819def _find_unicode_literals_frame():20 import __future__21 frm = sys._getframe(1)22 idx = 123 while frm is not None:24 if frm.f_globals.get('__name__').startswith('click.'):25 frm = frm.f_back26 idx += 127 elif frm.f_code.co_flags & __future__.unicode_literals.compiler_flag:28 return idx29 else:30 break31 return 0323334def _check_for_unicode_literals():35 if not __debug__:36 return37 if not PY2 or click.disable_unicode_literals_warning:38 return39 bad_frame = _find_unicode_literals_frame()40 if bad_frame <= 0:41 return42 from warnings import warn43 warn(Warning('Click detected the use of the unicode_literals '44 '__future__ import. This is heavily discouraged '45 'because it can introduce subtle bugs in your '46 'code. You should instead use explicit u"" literals '47 'for your unicode strings. For more information see '48 'http://click.pocoo.org/python3/'),49 stacklevel=bad_frame)505152def get_filesystem_encoding():53 return sys.getfilesystemencoding() or sys.getdefaultencoding()5455
569 unmodified lines
modified:click/core.py+3 added-1 removed
12 unmodified lines
13from .formatting import HelpFormatter, join_options14from .parser import OptionParser, split_opt15from .globals import push_context, pop_context1617from ._compat import PY2, isidentifier, iteritems17from ._compat import PY2, isidentifier, iteritems, _check_for_unicode_literals181920_missing = object()21
635 unmodified lines
657 'ASCII as encoding for the environment. '658 'Either switch to Python 2 or consult '659 'http://click.pocoo.org/python3/ '660 'for mitigation steps.')661 else:662 _check_for_unicode_literals()663664 if args is None:665 args = sys.argv[1:]666 else:
1030 unmodified lines
modified:click/decorators.py+2 added-1 removed
1 unmodified line
2import inspect34from functools import update_wrapper56from ._compat import iteritems6from ._compat import iteritems, _check_for_unicode_literals7from .utils import echo8from .globals import get_current_context910
72 unmodified lines
83 help = help.decode('utf-8')84 else:85 help = inspect.cleandoc(help)86 attrs['help'] = help87 _check_for_unicode_literals()88 return cls(name=name or f.__name__.lower(),89 callback=f, params=params, **attrs)9091
211 unmodified lines
modified:docs/python3.rst+21 added
150 unmodified lines
151 <http://bugs.python.org/issue19846>`_152* `LC_CTYPE=C: pydoc leaves terminal in an unusable state153 <http://bugs.python.org/issue21398>`_ (this is relevant to Click154 because the pager support is provided by the stdlib pydoc module)155156Unicode Literals157----------------158159Starting with Click 5.0 there will be a warning for the use of the160``unicode_literals`` future import in Python 2. This has been done due to161the negative consequences of this import with regards to unintentionally162causing bugs due to introducing Unicode data to APIs that are incapable of163handling them.164165If you use ``unicode_literals`` in any file that defines a Click command166or that invokes a click command you will be given a warning. You are167strongly encouraged to not use ``unicode_literals`` and instead use168explicit ``u`` prefixes for your Unicode strings.169170If you do want to ignore the warning and continue using171``unicode_literals`` on your own peril, you can disable the warning as172follows::173174 import click175 click.disable_unicode_literals_warning = True
modified:CHANGES+1 added
19 unmodified lines
20- introduced `Context.scope`.21- The `echo` function is now threadsafe: It calls the `write` method of the22 underlying object only once.23- `prompt(hide_input=True)` now prints a newline on `^C`.24- Click will now warn if users are using ``unicode_literals``.2526Version 4.127-----------28
221 unmodified lines