The generic parameter of FlagHolder now represents the type of value().

(a) For a flag with default None, define_* will return a FlagHolder[Optional[T]]
(b) For a flag with default != None, define_* will return a FlagHolder[T]

When we are unable to express "default != None", we always return FlagHolder[Optional[T]]

This assumes that the type of default() and value() will be the same.

This assumption holds, till we want the type system to understand that a "required" flag with a None default cannot return a None value.

Changes:
- When exact types for default is known, add @overloads for the DEFINE_* methods for the None case and remaining cases.
- When exact types for default is now known, change return type to FlagHolder[Optional[T]] -- which has same semantics of what FlagHolder[T] used to have.
PiperOrigin-RevId: 315519341
Change-Id: I88dc63b3c5271e12f3274b7246eb602b91b84caf
4 files changed
tree: 76d3118f05952693c5fe44a9669ee41bb34145d5
  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.