[library] auto-rename single-use names in add_source
This commit is contained in:
parent
4b0a899e17
commit
ac34108253
5 changed files with 48 additions and 4 deletions
|
|
@ -287,7 +287,7 @@ class LibraryBuilder(INameView):
|
|||
self,
|
||||
source: Mapping[str, Pattern] | ILibraryView,
|
||||
*,
|
||||
rename_theirs: Callable[[INameView, str], str] | None = None,
|
||||
rename_theirs: Callable[[INameView, str], str] | None = _rename_patterns,
|
||||
rename_when: Literal['conflict', 'always'] = 'conflict',
|
||||
) -> dict[str, str]:
|
||||
"""
|
||||
|
|
@ -309,6 +309,8 @@ class LibraryBuilder(INameView):
|
|||
rename_theirs: Function used to choose visible names for imported
|
||||
source cells. Its `INameView` argument contains existing and
|
||||
previously reserved names, but does not support pattern lookup.
|
||||
By default, conflicting single-use names are made unique;
|
||||
pass `None` to reject every conflict.
|
||||
rename_when: If `'conflict'`, only conflicting names are renamed.
|
||||
If `'always'`, every imported source name is passed through
|
||||
`rename_theirs`.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,14 @@ from ..error import LibraryError
|
|||
from ..pattern import Pattern, map_layers, map_targets
|
||||
from .base import ILibrary, ILibraryView
|
||||
from .capabilities import IBorrowing, IMaterializable
|
||||
from .utils import INameView, dangling_mode_t, _plan_source_names, _source_rename_map, _validate_dangling_mode
|
||||
from .utils import (
|
||||
INameView,
|
||||
dangling_mode_t,
|
||||
_plan_source_names,
|
||||
_rename_patterns,
|
||||
_source_rename_map,
|
||||
_validate_dangling_mode,
|
||||
)
|
||||
from .mapping import LibraryView
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -304,7 +311,7 @@ class OverlayLibrary(ILibrary, IMaterializable, IBorrowing):
|
|||
self,
|
||||
source: Mapping[str, Pattern] | ILibraryView,
|
||||
*,
|
||||
rename_theirs: Callable[[INameView, str], str] | None = None,
|
||||
rename_theirs: Callable[[INameView, str], str] | None = _rename_patterns,
|
||||
rename_when: Literal['conflict', 'always'] = 'conflict',
|
||||
) -> dict[str, str]:
|
||||
"""
|
||||
|
|
@ -317,6 +324,8 @@ class OverlayLibrary(ILibrary, IMaterializable, IBorrowing):
|
|||
rename_theirs: Function used to choose visible names for imported
|
||||
source cells. Its `INameView` argument contains existing and
|
||||
previously reserved names, but does not support pattern lookup.
|
||||
By default, conflicting single-use names are made unique;
|
||||
pass `None` to reject every conflict.
|
||||
rename_when: If `'conflict'`, only conflicting names are renamed.
|
||||
If `'always'`, every imported source name is passed through
|
||||
`rename_theirs`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue