Skip to content

Python utilities for writing cross-version compatible libraries

License

Notifications You must be signed in to change notification settings

tmkontra/compatlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

compatlib

Easily write backwards-and-forwards compatible libraries.

NOTE: you probably don't want to use this

Overview

If you have a library, you may want it to run across multiple python release versions. You might want to prefer certain features that aren't available in older versions. Use compatlib to keep your code clean.

Usage

import asyncio
from compatlib import compat

@compat.after(3, 4)
def main() -> None:
    asyncio.get_event_loop().run_until_complete(coro())
    return 3.4

@compat.after(3, 7)
def main() -> None:
    asyncio.run(coro())
    return 3.7

compatlib will resolve the latest-usable version at runtime, by comparing the overloaded methods with the interpreter sys.version_info.

When running the above code on python 3.6, it will use the first main. If you run it on python 3.7 it will run the second main.

Acknowledgement

Thanks to @wesselb for authoring the great plum multiple dispatch library, which compatlib uses as the basis of its decorator implementation. Instead of dispatching on type signatures, it dispatches on sys.version_info tuples.

TODO

  • Support dispatching on versions of libraries.
  • Support dispatching on the presence of an attribute (effectively, a boolean dispatcher)

About

Python utilities for writing cross-version compatible libraries

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages