Skip to main content

Pyton basic datatypes as a references.

Project description

refdatatypes

Pyton basic datatypes as a references. Solve problems with static class immutable datatypes.

Installation

pip3 install refdatatypes

Problem

class A:
    static = 1


class B(A):
    pass


print(f"int {A.static}")  # get 1 correctly
print(f"int {B.static}")  # get 1 correctly

A.static = 5
print(f"int {A.static}")  # get 5 correctly
print(f"int {B.static}")  # get 5 correctly

B.static = 6
print(f"int {A.static}")  # expected 6, but get 5 incorrectly
print(f"int {B.static}")  # get 6 correctly

A.static = 7
print(f"int {A.static}")  # get 7 correctly
print(f"int {B.static}")  # expected 7, but get unchanged 6, incorrectly

Solution

from refdatatypes.refint import RefInt


class AAA:
    static = RefInt(1)


class BBB(AAA):
    pass


print(f"refint {AAA.static.value}")  # get 1 correctly
print(f"refint {BBB.static.value}")  # get 1 correctly

AAA.static.value = 5
print(f"refint {AAA.static.value}")  # get 5 correctly
print(f"refint {BBB.static.value}")  # get 5 correctly

BBB.static.value = 6
print(f"refint {AAA.static.value}")  # get 6 correctly
print(f"refint {BBB.static.value}")  # get 6 correctly

AAA.static.value = 7
print(f"refint {AAA.static.value}")  # get 7 correctly
print(f"refint {BBB.static.value}")  # get 7 correctly

More details you can find in included examples static_class_attribute_problem.py and static_class_attribute_solution.py .

Safe datatypes

safedatatypes is simple set of function and classes which enables you to work safely with base python datatypes without error falls during convert or item access.

example

from refdatatypes.safedatatypes import safe_int

my_int = safe_int("None")  # no error
print(my_int)  # prints: `0`

example 2

from refdatatypes.safedatatypes import SafeDict

my_dict = SafeDict()
my_dict["a"] = 1

print(my_dict["a"])  # prints: `1` 
print(my_dict["b"])  # prints: `None` with no error
print(my_dict)  # prints: `{'a': 1}`

my_dict = SafeDict({"a": 1}, default_value=-1, autoset=True)
print(my_dict["a"])  # prints: `1` 
print(my_dict["b"])  # prints: `-1` with no error
print(my_dict)  # prints: `{'a': 1, 'b': -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

refdatatypes-1.2.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

refdatatypes-1.2.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file refdatatypes-1.2.1.tar.gz.

File metadata

  • Download URL: refdatatypes-1.2.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for refdatatypes-1.2.1.tar.gz
Algorithm Hash digest
SHA256 6dcc213de31cfc36ec0699aed57712985c22d0c4a4b7b39864c5d59dec3036f1
MD5 1ce91596657684e32d83ca718726d0ad
BLAKE2b-256 3e77fa1e5dea2e806d2667094b56eebd16e37e4c0f959d78d4206924b964d76f

See more details on using hashes here.

File details

Details for the file refdatatypes-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: refdatatypes-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for refdatatypes-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4003b272a2ee7c6cd7e8547de7312bd68fc37e8549b1ff578e9f7ed3cc006547
MD5 e68a083f96b1cc87b65de955f49f2bcf
BLAKE2b-256 e9be3d351a7628234b29f6e664d89237463729c998a740f75e18d1af77e2763e

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