Skip to main content

a simple way to remember to remove dead code due to notanymore supported

Project description

Some stupid badges:

https://badge.fury.io/py/insupportable.png https://travis-ci.org/Carreau/insupportable.png?branch=master

I am really annoyed, more and more, especially in old project to figure out what code is a war a workaround for old version of python, or another library.

This library should provide a simple way to warn you as early as possible when you can remove some legacy code, that deals with unsupported library version.

By default come pre-configured with Python 2/3 convenience function, but works with other libraries and more fine grained version numbering.

# warn you you have dead code if you
# drop Python2 support
from insupportable import support
if support('PY2'):
    print("You are on python 2")
else:
    print("You are on python 3")
# warn you you have dead code if you
# drop Python2 support
from insupportable import support
if support('PY3'):
    print("You are on python 3")
else:
    print("You are on python 2")

Set it up to drop Python2 support.

Quick and dirty way, modify global config, which is not recommended as it may affect other libraries that use this too, but super usefull.

support.config(PY2=False)

if support(PY2):
    print("You are on python 2")
else:
    print("You are on python 3")

warn the following:

mymodule/myfile.py:3: UserWarning: You are not supporting PY2 anymore
  if support(PY2):
mymodule/myfile.py:3: UserWarning: PY2 is the last supported feature of this group, you can simplifiy this logic.
  if support(PY2):

More involve way, create a config context that have effect only locally:

from insupportable import S

support = S(PY2=False).support

....

Advance configuration/custom features:

Example:

support.config(config=({
    'WindowsPhone':True,
    'Android'     :False,
    'iOS'         :False
   },))
if support('WindowsPhone'):
    print('Click on start menu')
else:
    print("Probably Android - but you don't support it anymore")
mymodule/myfile.py:1: UserWarning: WindowsPhone is the last supported feature of this group, you can simplifiy this logic.
  if support('WindowsPhone'):

TODO:

Write predicates and document like:

if workaround('tornado==2.2'):
    # do something special

The predicate would decide wether or not to yield depending on the version of tornado, and warn if min tornado is higher than 2.2

Deprecation decorator:

@deprecated_since('2.3.1',will_remove='3.0.0')
def my_api('something'):
    """deprecated fucntion that should
    warn user when function is **called**

    when module version is >= 3.0, the decorator should warn **developper** at **compile** time
    that code has to be removed.
    """

This case is more interesting than support() as there is 2 pass, the decoration of the function itsef, and the execution of the function. will_remove should infer next major I guess. Should we add option to deprecate after/at a date for some case like API.

@deprecate_after(date='2015/10/15'):
def marty_from_the_future(self):
    """
    Docs has some invalid ssl certificates ?
    """

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

insupportable-0.1.1.7-py2.py3-none-any.whl (24.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file insupportable-0.1.1.7-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for insupportable-0.1.1.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e56c749c6d4a7e488a265f5e920bc19d436a87208662ed30dec8367f005cabc0
MD5 804a26d1b4337c810a7ba04426548975
BLAKE2b-256 a3cee15b860e50476a91c088b1c2c5ce73e08702d88051e3f0727089e480566e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page