Fix an upcoming pytype error in absltest.

I'm working on an improvement to pytype's type-checking of function type
comments, which exposes an annotation error in absltest.
_TempFile._open() was annotated as returning Union[TextIO, BinaryIO] but is
used as:

def open_text(...) -> ContextManager[TextIO]:
  ...
  return self._open(...)

which will cause pytype to complain about open_text returning bytes when text
is expected. The proper way to fix this issue would be to use typing.overload
and typing.Literal to define multiple signatures for _open(), but pytype
doesn't fully support Literal yet, so I've added type comments with the
right types in open_text() and open_bytes().

This change also fixes a mistake in the return annotation on _open() and
alphabetically orders all typing imports.

PiperOrigin-RevId: 283783117
Change-Id: I4d78a9eb1c98218e62a9b0662931213f7c5c1668
1 file changed
tree: d937bb872638b53b95a90307b6bbe95c6cc58c28
  1. absl/
  2. smoke_tests/
  3. third_party/
  4. AUTHORS
  5. CONTRIBUTING.md
  6. LICENSE
  7. MANIFEST.in
  8. README.md
  9. setup.py
  10. WORKSPACE
README.md

Abseil Python Common Libraries

This repository is a collection of Python library code for building Python applications. The code is collected from Google's own Python code base, and has been extensively tested and used in production.

Features

  • Simple application startup
  • Distributed commandline flags system
  • Custom logging module with additional features
  • Testing utilities

Getting Started

Installation

To install the package, simply run:

pip install absl-py

Or install from source:

python setup.py install

Running Tests

To run Abseil tests, you can clone the git repo and run bazel:

git clone https://github.com/abseil/abseil-py.git
cd abseil-py
bazel test absl/...

Example Code

Please refer to smoke_tests/sample_app.py as an example to get started.

Documentation

See the Abseil Python Developer Guide.

Future Releases

The current repository includes an initial set of libraries for early adoption. More components and interoperability with Abseil C++ Common Libraries will come in future releases.

License

The Abseil Python library is licensed under the terms of the Apache license. See LICENSE for more information.