formate.classes¶
Core classes.
Classes:
|
|
|
|
|
Represents an entry point for a hook. |
|
Represents a |
Data:
Type hint for the |
-
typeddict
FormateConfigDict[source]¶ Bases:
TypedDicttyping.TypedDictrepresenting the configuration mapping parsed fromformate.tomlor 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:
TypedDicttyping.TypedDictrepresenting the expanded form of a hook in the mapping parsed from the config file.
-
HooksMapping¶ Type hint for the
hookskey of theformateconfiguration mapping.Alias of
Mapping[str,Union[int,ExpandedHookDict]]
-
class
EntryPoint(name, obj)[source]¶ Bases:
objectRepresents an entry point for a hook.
- Parameters
Attributes:
Methods:
Used for pickling.
__repr__()Return a string representation of the
EntryPoint.__setattr__(name, val)Implement
setattr(self, name).__setstate__(state)Used for pickling.
from_dict(d)Construct an instance of
EntryPointfrom a dictionary.to_dict([convert_values])Returns a dictionary containing the contents of the
EntryPointobject.-
name¶ Type:
strThe 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
-
__setattr__(name, val)¶ Implement
setattr(self, name).
-
classmethod
from_dict(d)¶ Construct an instance of
EntryPointfrom a dictionary.
-
to_dict(convert_values=False)¶ Returns a dictionary containing the contents of the
EntryPointobject.
-
class
Hook(name, priority=10, args=(), kwargs={}, entry_point=None, global_config={})[source]¶ Bases:
objectRepresents a
formatereformatting 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.
The extensions of filetypes supported by this hook.
Methods:
parse(data)Parse the given mapping into
Hooks.__call__(source, filename)Call the hook.
Used for pickling.
__repr__()Return a string representation of the
Hook.__setattr__(name, val)Implement
setattr(self, name).__setstate__(state)Used for pickling.
from_dict(d)Construct an instance of
Hookfrom a dictionary.to_dict([convert_values])Returns a dictionary containing the contents of the
Hookobject.-
name¶ Type:
strThe name of the hook. The name is normalized into lowercase, with underscores replaced by hyphens.
-
entry_point¶ Type:
Optional[EntryPoint]
-
global_config¶ -
A read-only view on the global configuration mapping, for hooks to do with as they wish.
-
property
supported_filetypes¶ The extensions of filetypes supported by this hook.
-
__call__(source, filename)[source]¶ Call the hook.
- Parameters
- Return type
- Returns
The reformatted source.
- Raises
TypeErrorifentry_pointhas not been set.
Changed in version 0.2.0: Added the
filenameargument.
-
__setattr__(name, val)¶ Implement
setattr(self, name).