djblets.util.typing¶
Common type definitions used for Djblets and consuming projects.
New in version 3.3.
- class ToJsonProtocol(*args, **kwargs)¶
Bases:
Protocol
Protocol for a class containing a to_json function.
This enables supporting classes that can serialize themselves via a
to_json()
method inSerializableJSONValue
.New in version 4.0.
- to_json() djblets.util.typing.SerializableJSONValue ¶
Return a JSON-serializable value for the object.
- Returns:
The JSON-serializable value.
- Return type:
- __abstractmethods__ = frozenset({})¶
- __annotations__ = {}¶
- __callable_proto_members_only__ = True¶
- __init__(*args, **kwargs)¶
- __parameters__ = ()¶
- __protocol_attrs__ = {'to_json'}¶
- classmethod __subclasshook__(other)¶
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
- KwargsDict¶
A type indicating a dictionary used for keyword arguments.
New in version 3.3.
- StrOrPromise¶
A type indicating a Unicode string or lazily-localized string.
New in version 3.3.
alias of
Union
[str
,StrPromise
]
- StrPromise¶
A type indicating a lazily-localized string.
New in version 3.3.
alias of
Promise
- JSONValue¶
A type indicating a valid value in JSON data.
All values are natively-supported JSON data. To support Python objects that can be serialized to JSON, see
SerializableJSONValue
.New in version 3.3.
alias of
Union
[JSONDict
,JSONDictImmutable
,JSONList
,JSONListImmutable
,None
,bool
,float
,int
,str
]
- JSONDict¶
A type for a dictionary mapping strings to JSON vlaues.
All values are natively-supported JSON data. To support Python objects that can be serialized to JSON, see
SerializableJSONDict
.New in version 3.3.
alias of
Dict
[str
,Union
[JSONDict
,JSONDictImmutable
,JSONList
,JSONListImmutable
,None
,bool
,float
,int
,str
]]
- JSONDictImmutable¶
An immutable type mapping strings to JSON vlaues.
This is an immutable version of
JSONDict
, which cannot be modified once set. It can help with type narrowing and is recommended when returning data from a function that should not be changed.All values are natively-supported JSON data. To support Python objects that can be serialized to JSON, see
SerializableJSONDictImmutable
.New in version 3.4.
alias of
Mapping
[str
,Union
[JSONDict
,JSONDictImmutable
,JSONList
,JSONListImmutable
,None
,bool
,float
,int
,str
]]
- JSONList¶
A type for a list of JSON values.
All values are natively-supported JSON data. To support Python objects that can be serialized to JSON, see
SerializableJSONList
.New in version 3.3.
alias of
List
[Union
[JSONDict
,JSONDictImmutable
,JSONList
,JSONListImmutable
,None
,bool
,float
,int
,str
]]
- JSONListImmutable¶
An immutable type of a list of JSON values.
This is an immutable version of
JSONList
, which cannot be modified once set. It can help with type narrowing and is recommended when returning data from a function that should not be changed.All values are natively-supported JSON data. To support Python objects that can be serialized to JSON, see
SerializableJSONListImmutable
.New in version 3.4.
alias of
Sequence
[Union
[JSONDict
,JSONDictImmutable
,JSONList
,JSONListImmutable
,None
,bool
,float
,int
,str
]]
- SerializableJSONValue¶
A type indicating a valid value that can be serialized to JSON.
These values are all supported in
DjbletsJSONEncoder
.New in version 4.0.
alias of
Union
[SerializableJSONDict
,SerializableJSONDictImmutable
,SerializableJSONList
,SerializableJSONListImmutable
,Decimal
,JSONDict
,JSONDictImmutable
,JSONList
,JSONListImmutable
,None
,bool
,float
,int
,str
,StrPromise
,ToJsonProtocol
,UUID
,date
,datetime
,time
,timedelta
]
- SerializableJSONDict¶
A type for a dictionary mapping strings to JSON-serializable values.
These values are all supported in
DjbletsJSONEncoder
.New in version 4.0.
alias of
Dict
[str
,Union
[SerializableJSONDict
,SerializableJSONDictImmutable
,SerializableJSONList
,SerializableJSONListImmutable
,Decimal
,JSONDict
,JSONDictImmutable
,JSONList
,JSONListImmutable
,None
,bool
,float
,int
,str
,StrPromise
,ToJsonProtocol
,UUID
,date
,datetime
,time
,timedelta
]]
- SerializableJSONDictImmutable¶
An immutable type mapping strings to JSON-serializable values.
This is an immutable version of
SerializableJSONDict
, which cannot be modified once set. It can help with type narrowing and is recommended when returning data from a function that should not be changed.These values are all supported in
DjbletsJSONEncoder
.New in version 4.0.
alias of
Mapping
[str
,Union
[SerializableJSONDict
,SerializableJSONDictImmutable
,SerializableJSONList
,SerializableJSONListImmutable
,Decimal
,JSONDict
,JSONDictImmutable
,JSONList
,JSONListImmutable
,None
,bool
,float
,int
,str
,StrPromise
,ToJsonProtocol
,UUID
,date
,datetime
,time
,timedelta
]]
- SerializableJSONList¶
A type for a list of JSON-serializable values.
These values are all supported in
DjbletsJSONEncoder
.New in version 4.0.
alias of
List
[Union
[SerializableJSONDict
,SerializableJSONDictImmutable
,SerializableJSONList
,SerializableJSONListImmutable
,Decimal
,JSONDict
,JSONDictImmutable
,JSONList
,JSONListImmutable
,None
,bool
,float
,int
,str
,StrPromise
,ToJsonProtocol
,UUID
,date
,datetime
,time
,timedelta
]]
- SerializableJSONListImmutable¶
An immutable type of a list of JSON-serializable values.
This is an immutable version of
SerializableJSONList
, which cannot be modified once set. It can help with type narrowing and is recommended when returning data from a function that should not be changed.These values are all supported in
DjbletsJSONEncoder
.New in version 4.0.
alias of
Sequence
[Union
[SerializableJSONDict
,SerializableJSONDictImmutable
,SerializableJSONList
,SerializableJSONListImmutable
,Decimal
,JSONDict
,JSONDictImmutable
,JSONList
,JSONListImmutable
,None
,bool
,float
,int
,str
,StrPromise
,ToJsonProtocol
,UUID
,date
,datetime
,time
,timedelta
]]