Last active
January 1, 2023 18:19
-
-
Save okaits/f1fe5fd62a56421d07c670db184fc3bc to your computer and use it in GitHub Desktop.
Python3 null module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from null import null | |
a = null | |
print(null) #Returns "/00" | |
print(int(null)) #Raises NullPointerException |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Null v0.0.1 | |
""" | |
import traceback | |
class Null(): | |
def __bool__(self) -> bool: | |
return False | |
def __bytes__(self) -> bytes: | |
return b"\0" | |
def __complex__(self): | |
raise(NullPointerException()) | |
def __float__(self): | |
raise(NullPointerException()) | |
def __format__(self, _) -> str: | |
return self.__str__() | |
def __int__(self): | |
raise(NullPointerException()) | |
def __str__(self) -> str: | |
return self.__bytes__().decode() | |
def __repr__(self) -> str: | |
return "null" | |
class NullPointerException(Exception): | |
pass | |
null = Null() | |
if __name__ == "__main__": | |
a = Null() | |
try: | |
print('Str: ' + str(a)) | |
except NullPointerException: | |
traceback.print_exc() | |
print() | |
try: | |
print(f'Str(f-string): {a}') | |
except NullPointerException: | |
traceback.print_exc() | |
print() | |
try: | |
print('Repr: ' + repr(a)) | |
except NullPointerException: | |
traceback.print_exc() | |
print() | |
try: | |
print('Int: ' + str(int(a))) | |
except NullPointerException: | |
traceback.print_exc() | |
print() | |
try: | |
print('Float: ' + str(float(a))) | |
except NullPointerException: | |
traceback.print_exc() | |
print() | |
try: | |
print('Bytes: ' + str(bytes(a))) | |
except NullPointerException: | |
traceback.print_exc() | |
print() | |
try: | |
print('Complex: ' + complex(a)) | |
except NullPointerException: | |
traceback.print_exc() | |
raise(SystemExit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment