Apr-30-2017, 03:21 PM
I have a small application that can convert indented python3 code into the equivalent code with braces {} and back again to indented python.
Here is an example of aby.py from my python3 windows installation.
It needs more work (the output needs better layout of spaces etc) but in principal it works.
I can see it being useful to people with C++/JAVA background that prefer to work in the braces style.
Also, I noticed a couple of days ago this link http://python-with-braces.appspot.com/
It seems to require a complete installation of python 2.x? What I'm proposing doesn't require changes to installation. But maybe my convertor could work alongside it, does anyone use it?
I'd like to develop it further but I don't know what interest there would be in it, it's only a sideline in what I'm currently doing but it does interest me..
Here is an example of aby.py from my python3 windows installation.
It needs more work (the output needs better layout of spaces etc) but in principal it works.
I can see it being useful to people with C++/JAVA background that prefer to work in the braces style.
Also, I noticed a couple of days ago this link http://python-with-braces.appspot.com/
It seems to require a complete installation of python 2.x? What I'm proposing doesn't require changes to installation. But maybe my convertor could work alongside it, does anyone use it?
I'd like to develop it further but I don't know what interest there would be in it, it's only a sideline in what I'm currently doing but it does interest me..
"""Abstract Base Classes (ABCs) according to PEP 3119.""" ; from _weakrefset import WeakSet ; def abstractmethod ( funcobj ) : { funcobj . __isabstractmethod__ = True ; return funcobj ; } ; class abstractclassmethod ( classmethod ) : { __isabstractmethod__ = True ; def __init__ ( self , callable ) : { callable . __isabstractmethod__ = True ; super ( ) . __init__ ( callable ) ; } ; } ; class abstractstaticmethod ( staticmethod ) : { __isabstractmethod__ = True ; def __init__ ( self , callable ) : { callable . __isabstractmethod__ = True ; super ( ) . __init__ ( callable ) ; } ; } ; class abstractproperty ( property ) : { __isabstractmethod__ = True ; } ; class ABCMeta ( type ) : { _abc_invalidation_counter = 0 ; def __new__ ( mcls , name , bases , namespace ) : { cls = super ( ) . __new__ ( mcls , name , bases , namespace ) ; abstracts = { name for name , value in namespace . items ( ) if getattr ( value , "__isabstractmethod__" , False ) } ; for base in bases : { for name in getattr ( base , "__abstractmethods__" , set ( ) ) : { value = getattr ( cls , name , None ) ; if getattr ( value , "__isabstractmethod__" , False ) : { abstracts . add ( name ) ; } ; } ; } ; cls . __abstractmethods__ = frozenset ( abstracts ) ; cls . _abc_registry = WeakSet ( ) ; cls . _abc_cache = WeakSet ( ) ; cls . _abc_negative_cache = WeakSet ( ) ; cls . _abc_negative_cache_version = ABCMeta . _abc_invalidation_counter ; return cls ; } ; def register ( cls , subclass ) : { if not isinstance ( subclass , type ) : { raise TypeError ( "Can only register classes" ) ; } ; if issubclass ( subclass , cls ) : { return subclass ; } ; if issubclass ( cls , subclass ) : { raise RuntimeError ( "Refusing to create an inheritance cycle" ) ; } ; cls . _abc_registry . add ( subclass ) ; ABCMeta . _abc_invalidation_counter += 1 ; return subclass ; } ; def _dump_registry ( cls , file = None ) : { """Debug helper to print the ABC registry.""" ; print ( "Class: %s.%s" % ( cls . __module__ , cls . __qualname__ ) , file = file ) ; print ( "Inv.counter: %s" % ABCMeta . _abc_invalidation_counter , file = file ) ; for name in sorted ( cls . __dict__ . keys ( ) ) : { if name . startswith ( "_abc_" ) : { value = getattr ( cls , name ) ; print ( "%s: %r" % ( name , value ) , file = file ) ; } ; } ; } ; def __instancecheck__ ( cls , instance ) : { """Override for isinstance(instance, cls).""" ; subclass = instance . __class__ ; if subclass in cls . _abc_cache : { return True ; } ; subtype = type ( instance ) ; if subtype is subclass : { if ( cls . _abc_negative_cache_version == ABCMeta . _abc_invalidation_counter and subclass in cls . _abc_negative_cache ) : { return False ; } ; return cls . __subclasscheck__ ( subclass ) ; } ; return any ( cls . __subclasscheck__ ( c ) for c in { subclass , subtype } ) ; } ; def __subclasscheck__ ( cls , subclass ) : { """Override for issubclass(subclass, cls).""" ; if subclass in cls . _abc_cache : { return True ; } ; if cls . _abc_negative_cache_version < ABCMeta . _abc_invalidation_counter : { cls . _abc_negative_cache = WeakSet ( ) ; cls . _abc_negative_cache_version = ABCMeta . _abc_invalidation_counter ; } elif subclass in cls . _abc_negative_cache : { return False ; } ; ok = cls . __subclasshook__ ( subclass ) ; if ok is not NotImplemented : { assert isinstance ( ok , bool ) ; if ok : { cls . _abc_cache . add ( subclass ) ; } else : { cls . _abc_negative_cache . add ( subclass ) ; } ; return ok ; } ; if cls in getattr ( subclass , '__mro__' , ( ) ) : { cls . _abc_cache . add ( subclass ) ; return True ; } ; for rcls in cls . _abc_registry : { if issubclass ( subclass , rcls ) : { cls . _abc_cache . add ( subclass ) ; return True ; } ; } ; for scls in cls . __subclasses__ ( ) : { if issubclass ( subclass , scls ) : { cls . _abc_cache . add ( subclass ) ; return True ; } ; } ; cls . _abc_negative_cache . add ( subclass ) ; return False ; } ; } ; class ABC ( metaclass = ABCMeta ) : { pass ; } ; def get_cache_token ( ) : { return ABCMeta . _abc_invalidation_counter ; } ;