Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

asdict that ignore sentinel

from dataclasses import dataclass
from typing import Optional, Dict, cast

SENTINEL = cast(None, object())  # have a sentinel that pretends to be 'None'


@dataclass
class Bla:
    arg1: Optional[int] = SENTINEL
    arg2: Optional[str] = SENTINEL
    arg3: Optional[Dict[str, str]] = SENTINEL

    def asdict(self):
        return {k: v for k, v in self.__dict__.items() if v is not SENTINEL}
Comment

PREVIOUS NEXT
Code Example
Python :: # multithreading for optimal use of CPU 
Python :: str vs rper in python 
Python :: install requests-html modlule click on the link to learn more about requests-html 
Python :: python nltk lookup error Resource omw-1.4 not found. 
Python :: This code is supposed to display "2 "2 + 2 = 4"" on the screen, but there is an error. Find the error in the code and fix it, so that the output is correct. 
Python :: double except python 
Python :: average values in a list python 
Python :: overlay bar plot and line plot in python 
Python :: FizzBuzz in Python Using itertools 
Python :: turn index back to column 
Python :: Python getting content from xl range 
Python :: html in nested structure 
Python :: matplotlib insert small subplot into subplot 
Python :: Python return statement (Write and Call Function) 
Python :: numpy random sin 
Python :: linear search algorithm python 
Python :: python replace every space, dash and parentheses into underscore 
Python :: affochage dun index du array list a deux dimension 
Python :: generate pycryptodome salt 
Python :: Javascript rendering problem in requests-html 
Python :: Python NumPy ravel function example array.ravel is equivalent to reshape(-1, order=order) 
Python :: python code to find duplicate row in sqlite database 
Python :: Python NumPy concatenate Function Example when axis equal to 0 
Python :: catch all event on socketio python 
Python :: pandas dt.weekday to string 
Python :: NumPy bitwise_and Example When inputs are arrays 
Python :: NumPy invert Code When the input is a number 
Python :: center pyfiglet to terminal 
Python :: penggunaan values di python 
Python :: how to process numerical data machine learning 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =