Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

future-annotations

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

future-annotations

A backport of __future__ annotations to python<3.7

  • 1.0.0
  • PyPI
  • Socket score

Maintainers
1

Build Status Azure DevOps coverage

future-annotations

A backport of __future__ annotations to python<3.7.

Installation

pip install future-annotations

Usage

Include the following encoding cookie at the top of your file (this replaces the utf-8 cookie if you already have it):

# -*- coding: future_annotations -*-

And then write python3.7+ forward-annotation code as usual!

# -*- coding: future_annotations -*-
class C:
    @classmethod
    def make(cls) -> C:
        return cls()

print(C.make())
$ python3.6 main.py
<__main__.C object at 0x7fb50825dd90>
$ mypy main.py
Success: no issues found in 1 source file

Showing transformed source

future-annotations also includes a cli to show transformed source.

$ future-annotations-show main.py
# ****************************** -*-
class C:
    @classmethod
    def make(cls) -> 'C':
        return cls()

print(C.make())

How does this work?

future-annotations has two parts:

  1. A utf-8 compatible codec which performs source manipulation
    • The codec first decodes the source bytes using the UTF-8 codec
    • The codec then leverages tokenize-rt to rewrite annotations.
  2. A .pth file which registers a codec on interpreter startup.

when you aren't using normal site registration

in setups (such as aws lambda) where you utilize PYTHONPATH or sys.path instead of truly installed packages, the .pth magic above will not take.

for those circumstances, you'll need to manually initialize future-annotations in a non-annotations wrapper. for instance:

import future_annotations

future_annotations.register()

from actual_main import main

if __name__ == '__main__':
    exit(main())

you may also like

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc