Philipp Hahn 7c3edba6ce python2/gettext improvements (#2235)
* py2: gettext: info()

returns a Dict[str, str]

<https://docs.python.org/2/library/gettext.html#gettext.NullTranslations.info>
> Return the “protected” _info variable.

<https://docs.python.org/2/library/gettext.html#the-gnutranslations-class>
> The entire set of key/value pairs are placed into a dictionary and set
> as the “protected” _info instance variable.

* py2: gettext: charset()

returns an Optional[str]

<https://docs.python.org/2/library/gettext.html#gettext.NullTranslations.charset>
> Return the “protected” _charset variable.

<https://docs.python.org/2/library/gettext.html#the-gnutranslations-class>
> If the key Content-Type is found, then the charset property is used to
> initialize the “protected” _charset instance variable, defaulting to
> None if not found.

* py2: gettext: [set_]output_charset()

allows to set an Optional[str]

<https://docs.python.org/2/library/gettext.html#gettext.NullTranslations.output_charset>
> Return the “protected” _output_charset variable.

<https://docs.python.org/2/library/gettext.html#gettext.NullTranslations.set_output_charset>
> Change the “protected” _output_charset variable, which defines the
> encoding used to return translated messages.

<https://docs.python.org/2/library/gettext.html#gettext.GNUTranslations.lgettext>
> Equivalent to gettext(), but the translation is returned in the
> preferred system encoding, if no other encoding was explicitly set with
> set_output_charset().

* py2: gettext: install(..., names)

allows to set an Optional[str]

<https://docs.python.org/2/library/gettext.html#gettext.NullTranslations.install>
> If the names parameter is given, it must be a sequence containing the
> names of functions you want to install in the builtins namespace in
> addition to _().

* py2: gettext: localdir=None

is Optional[str]

<https://docs.python.org/2/library/gettext.html#gettext.bindtextdomain>
> If localedir is omitted or None, then the current binding for domain
> is returned.

* py2: gettext: languages=None

is Optional[Sequence[str]]

<https://docs.python.org/2/library/gettext.html#gettext.find>
> If languages is not given, then the following environment variables
> are searched: ...

* py2: gettext: codeset=None

is Optional[str]

<https://docs.python.org/2/library/gettext.html#gettext.translation>
> If provided, codeset will change the charset used to encode translated
> strings.

* py2: gettext: translation(class_=None)

is Optional[type]

<https://docs.python.org/2/library/gettext.html#gettext.translation>
> The actual class instantiated is either class_ if provided, otherwise
> GNUTranslations.

* py2: gettext: translation(fallback)

is bool

<https://docs.python.org/2/library/gettext.html#gettext.translation>
> ..., this function raises IOError if fallback is false (which is the
> default), and returns a NullTranslations instance if fallback is true.

* py2: gettext: install(unicode)

is bool

<https://docs.python.org/2/library/gettext.html#gettext.install>
> The unicode flag is passed to the resulting translation object’s
> install() method.

which is already expecting `bool`.
2018-06-16 10:19:24 -07:00
2018-03-28 20:25:50 -07:00
2015-10-01 08:43:06 -07:00
2016-12-20 04:07:44 -08:00

typeshed

Build Status Chat at https://gitter.im/python/typing

About

Typeshed contains external type annotations for the Python standard library and Python builtins, as well as third party packages.

This data can e.g. be used for static analysis, type checking or type inference.

For information on how to use typeshed, read below. Information for contributors can be found in CONTRIBUTING.md. Please read it before submitting pull requests.

Typeshed supports Python versions 2.7 and 3.3 and up.

Using

If you're just using mypy (or pytype or PyCharm), as opposed to developing it, you don't need to interact with the typeshed repo at all: a copy of typeshed is bundled with mypy.

When you use a checked-out clone of the mypy repo, a copy of typeshed should be included as a submodule, using

$ git clone --recurse-submodules https://github.com/python/mypy.git

or

$ git clone https://github.com/python/mypy.git
$ cd mypy
$ git submodule init
$ git submodule update

and occasionally you will have to repeat the final command (git submodule update) to pull in changes made in the upstream typeshed repo.

PyCharm and pytype similarly include a copy of typeshed. The one in pytype can be updated in the same way if you are working with the pytype repo.

Format

Each Python module is represented by a .pyi "stub". This is a normal Python file (i.e., it can be interpreted by Python 3), except all the methods are empty. Python function annotations (PEP 3107) are used to describe the types the function has.

See PEP 484 for the exact syntax of the stub files and CONTRIBUTING.md for the coding style used in typeshed.

Directory structure

stdlib

This contains stubs for modules the Python standard library -- which includes pure Python modules, dynamically loaded extension modules, hard-linked extension modules, and the builtins.

third_party

Modules that are not shipped with Python but have a type description in Python go into third_party. Since these modules can behave differently for different versions of Python, third_party has version subdirectories, just like stdlib.

NOTE: When you're contributing a new stub for a package that you did not develop, please obtain consent of the package owner (this is specified in PEP 484). The best way to obtain consent is to file an issue in the third-party package's tracker and include the link to a positive response in your PR for typeshed.

For more information on directory structure and stub versioning, see the relevant section of CONTRIBUTING.md.

Contributing

Please read CONTRIBUTING.md before submitting pull requests. If you have questions related to contributing, drop by the typing Gitter.

Running the tests

The tests are automatically run by Travis CI on every PR and push to the repo. There are several sets of tests: tests/mypy_test.py runs tests against mypy, while tests/pytype_test.py runs tests against pytype.

Both sets of tests are shallow -- they verify that all stubs can be imported but they don't check whether stubs match their implementation (in the Python standard library or a third-party package). Also note that each set of tests has a blacklist of modules that are not tested at all. The blacklists also live in the tests directory.

In addition, you can run tests/mypy_selftest.py to run mypy's own test suite using the typeshed code in your repo. This will sometimes catch issues with incorrectly typed stubs, but is much slower than the other tests.

To manually run the mypy tests, you need to have Python 3.5 or higher; Python 3.6.1 or higher is recommended.

Run:

$ python3.6 -m venv .venv3
$ source .venv3/bin/activate
(.venv3)$ pip3 install -r requirements-tests-py3.txt

This will install mypy (you need the latest master branch from GitHub), typed-ast, and flake8. You can then run mypy tests and flake8 tests by invoking:

(.venv3)$ python3 tests/mypy_test.py
...
(.venv3)$ python3 tests/mypy_selftest.py
...
(.venv3)$ flake8
...

(Note that flake8 only works with Python 3.6 or higher.)

To run the pytype tests, you need a separate virtual environment with Python 2.7, and a Python 3.6 interpreter somewhere you can point to. Run:

$ virtualenv --python=python2.7 .venv2
$ source .venv2/bin/activate
(.venv2)$ pip install -r requirements-tests-py2.txt

This will install pytype from its GitHub repo. You can then run pytype tests by running:

(.venv2)$ python tests/pytype_test.py --python36-exe=/path/to/python3.6

For mypy, if you are in the typeshed repo that is submodule of the mypy repo (so .. refers to the mypy repo), there's a shortcut to run the mypy tests that avoids installing mypy:

$ PYTHONPATH=.. python3 tests/mypy_test.py

You can mypy tests to a single version by passing -p2 or -p3.5 e.g.

$ PYTHONPATH=.. python3 tests/mypy_test.py -p3.5
running mypy --python-version 3.5 --strict-optional # with 342 files
Description
Collection of library stubs for Python, with static types
Readme Multiple Licenses 29 MiB
Languages
Python 99.8%
Shell 0.2%