formate.classes
¶
Core classes.
Classes:
|
|
|
|
|
Represents an entry point for a hook. |
|
Represents a |
Data:
Type hint for the |
-
typeddict
FormateConfigDict
[source]¶ Bases:
TypedDict
typing.TypedDict
representing the configuration mapping parsed fromformate.toml
or similar.- Optional Keys
hooks (
Mapping
[str
,Union
[int
,ExpandedHookDict
]]) – Mapping defining the hooks to run. Each value can either be an integer (the priority) or aExpandedHookDict
.config (
Mapping
[str
,Any
]) – Mapping defining the global configuration forformate
.
-
typeddict
ExpandedHookDict
[source]¶ Bases:
TypedDict
typing.TypedDict
representing the expanded form of a hook in the mapping parsed from the config file.
-
HooksMapping
¶ Type hint for the
hooks
key of theformate
configuration mapping.Alias of
Mapping
[str
,Union
[int
,ExpandedHookDict
]]
-
class
EntryPoint
(name, obj)[source]¶ Bases:
object
Represents an entry point for a hook.
- Parameters
Attributes:
Methods:
__repr__
()Return a string representation of the
EntryPoint
.from_dict
(d)Construct an instance of
EntryPoint
from a dictionary.to_dict
([convert_values])Returns a dictionary containing the contents of the
EntryPoint
object.-
name
¶ Type:
str
The name of the entry point. The name is normalized into lowercase, with underscores replaced by hyphens.
-
__repr__
()¶ Return a string representation of the
EntryPoint
.- Return type
-
classmethod
from_dict
(d)¶ Construct an instance of
EntryPoint
from a dictionary.
-
to_dict
(convert_values=False)¶ Returns a dictionary containing the contents of the
EntryPoint
object.
-
class
Hook
(name, priority=10, args=(), kwargs={}, entry_point=None, global_config={})[source]¶ Bases:
object
Represents a
formate
reformatting hook.- Parameters
name (
str
) – The name of the entry point. The name is normalized into lowercase, with underscores replaced by hyphens.priority (
int
) – The priority of the hook. Default10
.args – The positional arguments passed to the hook function. Default
()
.kwargs (
Dict
[str
,Any
]) – The keyword arguments passed to the hook function. Default{}
.entry_point (
Optional
[EntryPoint
]) – DefaultNone
.global_config (
Mapping
[str
,Any
]) – A read-only view on the global configuration mapping, for hooks to do with as they wish. Default{}
.
Attributes:
The name of the hook.
The priority of the hook.
The positional arguments passed to the hook function.
The keyword arguments passed to the hook function.
A read-only view on the global configuration mapping, for hooks to do with as they wish.
Methods:
parse
(data)Parse the given mapping into
Hook
s.__call__
(source, filename)Call the hook.
__repr__
()Return a string representation of the
Hook
.from_dict
(d)Construct an instance of
Hook
from a dictionary.to_dict
([convert_values])Returns a dictionary containing the contents of the
Hook
object.-
name
¶ Type:
str
The name of the hook. The name is normalized into lowercase, with underscores replaced by hyphens.
-
global_config
¶ -
A read-only view on the global configuration mapping, for hooks to do with as they wish.
-
__call__
(source, filename)[source]¶ Call the hook.
- Parameters
- Return type
- Returns
The reformatted source.
- Raises
TypeError
ifentry_point
has not been set.
Changed in version 0.2.0: Added the
filename
argument.