Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow "extra" to be None in the marker environment #650

Merged
merged 1 commit into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/packaging/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,9 @@ def evaluate(self, environment: Optional[Dict[str, str]] = None) -> bool:
current_environment["extra"] = ""
if environment is not None:
current_environment.update(environment)
# The API used to allow setting extra to None. We need to handle this
# case for backwards compatibility.
if current_environment["extra"] is None:
current_environment["extra"] = ""

return _evaluate_markers(self._markers, current_environment)
15 changes: 15 additions & 0 deletions tests/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import platform
import sys
from typing import cast

import pytest

Expand Down Expand Up @@ -256,6 +257,20 @@ def test_compare_markers_to_other_objects(self):
def test_environment_assumes_empty_extra(self):
assert Marker('extra == "im_valid"').evaluate() is False

def test_environment_with_extra_none(self):
# GIVEN
marker_str = 'extra == "im_valid"'

# Pretend that this is dict[str, str], even though it's not. This is a
# test for being bug-for-bug compatible with the older implementation.
environment = cast("dict[str, str]", {"extra": None})

# WHEN
marker = Marker(marker_str)

# THEN
assert marker.evaluate(environment) is False

@pytest.mark.parametrize(
("marker_string", "environment", "expected"),
[
Expand Down