Skip to content

Commit

Permalink
add comment that attributes must be immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering committed Nov 18, 2023
1 parent 4cdaff0 commit 5d019df
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def __init__(
features=extras,
)

# Attributes must be immutable for clone() to be safe!
# (For performance reasons, clone only creates a copy instead of a deep copy).

self._constraint: VersionConstraint
self._pretty_constraint: str
self.constraint = constraint # type: ignore[assignment]
Expand Down
2 changes: 2 additions & 0 deletions src/poetry/core/packages/directory_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def __init__(
base=base,
extras=extras,
)
# Attributes must be immutable for clone() to be safe!
# (For performance reasons, clone only creates a copy instead of a deep copy).
self._develop = develop

# cache this function to avoid multiple IO reads and parsing
Expand Down
2 changes: 2 additions & 0 deletions src/poetry/core/packages/file_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def __init__(
subdirectory=directory,
extras=extras,
)
# Attributes must be immutable for clone() to be safe!
# (For performance reasons, clone only creates a copy instead of a deep copy).

@property
def directory(self) -> str | None:
Expand Down
3 changes: 3 additions & 0 deletions src/poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def __init__(
features=features,
)

# Attributes must be immutable for clone() to be safe!
# (For performance reasons, clone only creates a copy instead of a deep copy).

self._set_version(version)

self.description = ""
Expand Down
2 changes: 2 additions & 0 deletions src/poetry/core/packages/path_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def __init__(
subdirectory: str | None = None,
extras: Iterable[str] | None = None,
) -> None:
# Attributes must be immutable for clone() to be safe!
# (For performance reasons, clone only creates a copy instead of a deep copy).
assert source_type in ("file", "directory")
self._path = path
self._base = base or Path.cwd()
Expand Down
3 changes: 3 additions & 0 deletions src/poetry/core/packages/project_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def __init__(

super().__init__(name, version)

# Attributes must be immutable for clone() to be safe!
# (For performance reasons, clone only creates a copy instead of a deep copy).

self.build_config: Mapping[str, Any] = {}
self.packages: Sequence[Mapping[str, Any]] = []
self.include: Sequence[Mapping[str, Any]] = []
Expand Down
3 changes: 3 additions & 0 deletions src/poetry/core/packages/specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def __init__(
) -> None:
from packaging.utils import canonicalize_name

# Attributes must be immutable for clone() to be safe!
# (For performance reasons, clone only creates a copy instead of a deep copy).

self._pretty_name = name
self._name = canonicalize_name(name)
self._source_type = source_type
Expand Down
2 changes: 2 additions & 0 deletions src/poetry/core/packages/url_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def __init__(
optional: bool = False,
extras: Iterable[str] | None = None,
) -> None:
# Attributes must be immutable for clone() to be safe!
# (For performance reasons, clone only creates a copy instead of a deep copy).
self._url = url
self._directory = directory

Expand Down
2 changes: 2 additions & 0 deletions src/poetry/core/packages/vcs_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def __init__(
develop: bool = False,
extras: Iterable[str] | None = None,
) -> None:
# Attributes must be immutable for clone() to be safe!
# (For performance reasons, clone only creates a copy instead of a deep copy).
self._vcs = vcs
self._source = source

Expand Down

0 comments on commit 5d019df

Please sign in to comment.