Skip to content
Open
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
33 changes: 22 additions & 11 deletions source/specifications/dependency-specifiers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,31 @@ safely evaluate it without running arbitrary code that could become a security
vulnerability. Markers were first standardised in :pep:`345`. This document
fixes some issues that were observed in the design described in :pep:`426`.

Comparisons in marker expressions are typed by the comparison operator and the
type of the marker value. The <marker_op> operators that are not in
<version_cmp> perform the same as they do for strings or sets in Python based on
whether the marker value is a string or set itself. The <version_cmp> operators
use the version comparison rules of the
:ref:`Version specifier specification <version-specifiers>` when those are
defined (that is when both sides have a valid version specifier). If there is no
defined behaviour of this specification and the operator exists in Python, then
the operator falls back to the Python behaviour for the types involved.
Otherwise an error should be raised. e.g. the following will result in errors::
Comparisons in marker expressions are based on the types in the table below.
The variables marked with ``Version`` or ``Version | String`` use the version
comparison rules of the :ref:`Version specifier specification
<version-specifiers>` when those are defined (that is when both sides have a
valid version specifier). If either side is not expressible as a ``Version``,
then ``>=`` and``<=``, are equivalent to ``==``; no ordering is
assumed. The ``<`` and ``>`` operators always return false on strings. The
``===`` legacy arbitrary equivalence operator does an exact, case insensitive
comparison regardless of if a string fallback is used. On other operators,
operators perform the same as they do for strings or sets in Python based on
whether the marker value is a string or set itself. Otherwise an error should
be raised; it should be noted that ``~=`` does not support string fallback.
e.g. the following will result in errors::

"dog" ~= "fred"
python_version ~= "surprise"

Variables that are marked solely as ``String`` support ``==`` and ``!=``;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They should also support ===

ordered comparison operators may also follow same rules as ``Version`` defined
above when one side is not a valid Version, with ``>=`` and ``<=`` being
equivalent to ``==``, and ``<`` and ``>`` always evaluating to ``False``. This
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They should be equivalent to === (as should == and ~=)

is legacy behavior due to an older version of this spec, and tools may choose
to warn or fail if ordered comparisons are used on ``String`` markers. ``~=``
and ``====`` (legacy arbitrary equivalence) are not supported on string fields.

User supplied constants are always encoded as strings with either ``'`` or
``"`` quote marks. Note that backslash escapes are not defined, but existing
implementations do support them. They are not included in this
Expand Down Expand Up @@ -267,7 +278,7 @@ an error like all other unknown variables.
- ``CPython``, ``Jython``
* - ``platform_release``
- :py:func:`platform.release()`
- String
- Version | String
- ``3.14.1-x86_64-linode39``, ``14.5.0``, ``1.8.0_51``
* - ``platform_system``
- :py:func:`platform.system()`
Expand Down