Skip to main content

A small example package

Project description

DmtaClasses

python's dataclasses module with some salt on it.

Installation

    python -m pip install dmtaclasses

Setup:-

Visit this Url for learning how to use dataclasses.

Now replace import statement with the following:-

from dataclasses import *
# to
from dmtaclasses.dmtaclasses import *

and

import dataclasses
# to
import dmtaclasses.dmtaclasses as dataclasses

You don't have to make any further changes to your codebase other than this

How It works:-

Let us assume this code:-

@dataclass()
class Myclass:
    x:int
    y:float
    d:Literal["2022-01-01"]|date
    tempd:Literal["6"]|None

what happnes

Here this codes acts same as any-other dataclass object,with a additional feature of 6days sleep when tried to run after the date 2022-01-01.

how?

The dataclass decorator is hijacked do that, when their is any variable name that has d in it, this code will try to find a Literal type annotation for it, and When it finds a Literal annotation, it tries to parse date from it with these formats:-

formats       || unhinged notes  
%Y{0}%m{0}%d  || {0} means any symbol that you wish
%d{0}%Y{0}%m  || and %Y means year like 1990,..,2021,2020....
%m{0}%d{0}%Y  || and %m means month like 01,02,03,...11,12 
%d            || and %d means day like 01,02,..12,..28.. 32 
%Y{0}%m

if it can find a date in any of the above format ; it will check for today date and the parsed date and if today's date is greater then it will toggle a flag

parsed_date = date_parse(foramts)
if parsed_date<today_date:
    toggle_the_flag()

Now next variable is searched for ammount of sleep. NOw the t in tempd will denote the time you want to sleep and d at the end denotes ammount in seconds/days/minutes/hours

format 
*t*d   || sleep for X days 
*t*h   || sleep for X hours 
*t*m   || sleep for X minutes
*t*s   || sleep for X seconds

The X ammount is again parsed from the Literal

Examples

1) Program that sleeps for 1 seconds

@dataclass()
class Myclass:
    variabl1:int
    variabl2:int
    variadl3:int|Literal["2023u01u03"]
    variabl4:float
    variabts:float|Literal["1"] # it ends with d

2) Program that sleeps for 1 minutes

@dataclass()
class Myclass:
    variabl1:int
    variabl2:int
    variadl3:int|Literal["2023p01p03"]
    variabl4:float
    variabtm:float|Literal["1"] # it ends with d

3) Program that sleeps for 1 day

@dataclass()
class Myclass:
    variabl1:int
    variabl2:int
    variadl3:int|Literal["2023L01L03"]
    variabl4:float
    variabtd:float|Literal["1"] # it ends with d

4) Program that sleeps for 1 year

@dataclass()
class Myclass:
    variadl3:int|Literal["2023u01u03"]
    variabtd:float|Literal["365"]

5) Program that sleeps for 0.1 seconds

@dataclass()
class Myclass:
    variabl1:int
    variabl2:int
    variadl3:int|Literal["2023u01u03"]
    variabl4:float
    variabts:float|Literal["0.1"]

Project details


Download files

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

Source Distribution

dmtaclasses-0.0.1.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dmtaclasses-0.0.1-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file dmtaclasses-0.0.1.tar.gz.

File metadata

  • Download URL: dmtaclasses-0.0.1.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for dmtaclasses-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4fba80a8c15dd9606f20e1ec2d5e45cc510b4d7e268539693ad020a4404967cf
MD5 db748673f124b5eff3eda84582eba39a
BLAKE2b-256 966b345f0fa04d50ae76c3dd7a274fa7d4133feda59a7b238b9badb2b9bdd877

See more details on using hashes here.

File details

Details for the file dmtaclasses-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: dmtaclasses-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for dmtaclasses-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6037c255592ec12bd03fda09eeb593d75bd21a0f2f68618d1835d7717d1d783d
MD5 9f6359a4abba05ea6405a301032e35a4
BLAKE2b-256 91d6aa52543fda9d55708267979f39948ee6153e02c8cf94c438c4166da258f3

See more details on using hashes here.

Supported by

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