Skip to main content

Python Languauge Utilities

This library provides utilities to use features of other languages in Python.

https://badge.fury.io/py/pythonlangutil.svg https://travis-ci.org/ehsan-keshavarzian/pythonlangutil.svg?branch=master

You can find a functional example of each feature in the examples directory. Test cases in tests directory run on top of these examples to ensure the functionality.

Access Modifiers

To identify a variable as private::

from pythonlangutil.access_modifiers import private_variable

class PrivateVariableTest(object):
   def __init__(self):
       self.id = "123"

   @private_variable('id')
   def __setattr__(self, *args, **kwargs):
       return object.__setattr__(self, *args, **kwargs)

   def insider(self):
       self.id = "321"

To identify a method as private::

from pythonlangutil.access_modifiers import private_function

class PrivateFunctionTest(object):
   def __init__(self):
       pass

   @private_function
   def private_method(self):
       return 'called from inside my own class'

   def insider(self):
       return self.private_method()

Creating Overloads

To create overloads::

from pythonlangutil.overload import Overload, signature

class OverloadTest():
    def __init__(self):
        self.male_pref = "Mr. %s"
        self.female_pref = "Ms. %s"
        self.general_pref = "Dear %s"

    @Overload
    @signature("str", "bool")
    def my_method(self, name, male):
        if male:
            return self.male_pref % name
        return self.female_pref % name

    @my_method.overload
    @signature("str")
    def my_method(self, name):
        return self.general_pref % name

    @my_method.overload
    @signature("int", "str")
    def my_method(self, times, name):
        return "\n".join([self.general_pref % name for i in range(times)])

Using Singleton Model

It prevents the instantiation of the class. The only instance of the class will be accessible through get_instance() method which will be added to class automatically.

To use singleton::

from pythonlangutil.singleton import Singleton

@Singleton()
class SingletonTest():
    def __init__(self):
        pass

Metadata

Release files for pythonlangutil 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pythonlangutil 0.1
File Size Uploaded
pythonlangutil-0.1.zip 7.3 kB Details

Release files / pythonlangutil-0.1.zip

Download URL pythonlangutil-0.1.zip
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
54cfc6a8f7c2286c20a6f2b724b0e7d91e9b3e6c924f01b5af6748c6bfafb9d5
BLAKE2b-256 checksum
How to use checksums
e7b7f689879f8c9b9ae8994b89d8220fc63fddaceda920b12184f45fd5cdb5a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page