Typing Stubs for six
This package provides typing stubs for the `six` library, enabling static type checking for code that uses `six`. It is part of the community-maintained Typeshed project, which regularly releases updated stubs for third-party packages. The current version, 1.17.0.20260408, aims for compatibility with `six==1.17.*` and is designed for modern Python 3 environments.
Warnings
- gotcha The `six` library is primarily intended for maintaining Python 2 and 3 compatibility in a single codebase. For new Python 3-only projects, it is generally recommended to use native Python 3 features directly (e.g., `urllib.parse` instead of `six.moves.urllib.parse`) to avoid unnecessary abstraction layers and potential confusion.
- gotcha `types-six` (and Typeshed stubs generally) are designed for modern Python versions. Specifically, `types-six` requires Python `>=3.10`, even though the runtime `six` library itself supports Python `2.7` and `3.3+`. This means `types-six` cannot be used to provide type hints for older Python 2 or Python 3 projects.
- gotcha `types-six` is a stub-only package. It provides type information solely for static analysis tools (like Mypy, Pyright, PyCharm) and does not contain any executable code or influence runtime behavior. You must install the `six` runtime library separately (`pip install six`) for your application to function.
Install
-
pip install types-six
Imports
- six.moves.urllib.parse
import six.moves.urllib.parse
Quickstart
import six.moves.urllib.parse
def get_scheme(url: six.text_type) -> six.text_type:
parsed_url = six.moves.urllib.parse.urlparse(url)
return parsed_url.scheme
url_str: six.text_type = 'http://example.com/path'
scheme: six.text_type = get_scheme(url_str)
print(f"The scheme is: {scheme}")
# To type-check this:
# 1. pip install six types-six mypy
# 2. Save the code above as example.py
# 3. Run: mypy example.py