Skip to content

Commit

Permalink
revert: remove attribute locking
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Oct 21, 2024
1 parent 68a22f8 commit aa6b503
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 26 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ A backend is also expected to copy entries from `project.licence_files`, which
are paths relative to the project directory, into the `dist-info/licenses`
folder, preserving the original source structure.

## Modifying metadata

By default, `StandardMetadata` metadata fields are immutable unless a field is
listed in `dynaimc` (not to be confused with `dynamic_metadata`). If you want to
modify fields that are not dynamic, you can use the `dataclasses.replace` /
`copy.replace` (Python 3.13+) function.

## Dynamic Metadata (METADATA 2.2+)

Pyproject-metadata supports dynamic metadata. To use it, specify your METADATA
Expand Down
15 changes: 0 additions & 15 deletions pyproject_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ class _SmartMessageSetter:
reduce boilerplate.
If a value is None, do nothing.
If a value contains a newline, indent it (may produce a warning in the future).
"""

message: email.message.Message
Expand Down Expand Up @@ -252,23 +251,10 @@ class StandardMetadata:
"""
If True, all errors will be collected and raised in an ExceptionGroup.
"""
_locked_metadata: bool = False
"""
Internal flag to prevent setting non-dynamic fields after initialization.
"""

def __post_init__(self) -> None:
self.validate()

def __setattr__(self, name: str, value: Any) -> None:
if self._locked_metadata:
metadata_name = name.replace("_", "-")
locked_fields = constants.KNOWN_METADATA_FIELDS - set(self.dynamic)
if metadata_name in locked_fields:
msg = f"Field {name!r} is not dynamic"
raise AttributeError(msg)
super().__setattr__(name, value)

@property
def auto_metadata_version(self) -> str:
"""
Expand Down Expand Up @@ -442,7 +428,6 @@ def from_pyproject( # noqa: C901
metadata_version=metadata_version,
all_errors=all_errors,
)
self._locked_metadata = True

pyproject.finalize("Failed to parse pyproject.toml")
assert self is not None
Expand Down
5 changes: 1 addition & 4 deletions tests/test_standard_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1488,10 +1488,7 @@ def test_modify_dynamic() -> None:
}
)
metadata.requires_python = packaging.specifiers.SpecifierSet(">=3.12")
with pytest.raises(
AttributeError, match=re.escape("Field 'version' is not dynamic")
):
metadata.version = packaging.version.Version("1.2.3")
metadata.version = packaging.version.Version("1.2.3")


def test_missing_keys_warns() -> None:
Expand Down

0 comments on commit aa6b503

Please sign in to comment.