As the class name starts with "Test", pytest interprets it as a test
case, but it is not one. Further, due to its `__init__` method, pytest
emits the following warning:
.../pip/tests/lib/__init__.py:141: PytestCollectionWarning: cannot
collect test class 'TestData' because it has a __init__ constructor
For additional information on pytest discovery, see:
https://docs.pytest.org/en/latest/example/pythoncollection.html
The list is always empty.
Removing the unused attributes simplifies the mixin and avoids the need
to add a type annotation for it.
Unused since its introduction in
bd850c0798.
The tests are a large consumer of the pip API (both the internal API and
otherwise). By running mypy on tests, we help to:
1. Ensure the internal API is consistent with regards to typing
2. Ensure the tests are representative of real life scenarios as the API
are used correctly.
3. Helps to recognize unnecessary tests that simply pass junk data to
functions which can be caught by the type checker.
4. Make sure test support code in tests/lib/ is correct and consistent.
This is especially important when refactoring such code. For example, if
we were to replace tests/lib/path.py with pathlib.
As a first start, untyped defs are allowed. All existing typing issues
have been resolved. Overtime, we can chip away at untyped defs and
eventually remove the configuration option for stricter type checking of
tests.
The following changes were made to help make mypy pass:
Remove unused record_callback argument from make_wheel() in tests.
Unused since its introduction in
6d8a58f7e1.
Replace toml with tomli_w in tests/functional/test_pep517.py. Unlike the
toml package, tomli_w contains inline typing annotations.
Remove unnecessary make_no_network_finder(). Unnecessary since
bab1e4f8a1 where the _get_pages method was
removed.
Use the tool com2ann to automatically convert most type comments to type
annotations. Some type comments continue to exist where any work beyond
the automatic conversion was required (for example, additional
formatting or circular references).
For additional information on the com2ann tool, see:
https://github.com/ilevkivskyi/com2ann
The typing module has been available since Python 3.5. Guarding the
import has been unnecessary since dropping Python 2.
Some guards remain to either:
- Avoid circular imports
- Importing objects that are also guarded by typing.TYPE_CHECKING
- Avoid mypy_extensions dependency
Removes the vendored contextlib2.
ExitStack and suppress are available from stdlib contextlib on all
supported Python versions.
The nullcontext context manager which isn't available in Python 3.6, but
the function is simple to implement. Once Python 3.6 support is dropped,
so too can the compat shim.
The stdlib module has been available since Python 3.5 and the
TYPE_CHECKING constant has been available since 3.5.2.
By using stdlib, this removes the need for pip to maintain its own
Python 2 typing compatibility shim.
https://www.python.org/dev/peps/pep-3102/
Replaces the pattern: self.name = kwargs.pop('name')
Keyword-only arguments offer some advantages:
- In the event of a typo or misuse, a more informative error is
presented to the programmer.
- More self documenting and makes interfaces more explicit.
- They more easily allow explicit typing.
Adding types to ConfigOptionParser required changing some call sites to
pass arguments without using a dict due to mypy bug:
https://github.com/python/mypy/issues/9676
Now that Python 2 is not supported, the bytes/str boundaries are more
clear and explicit. Using six.ensure_* methods for backwards
compatibility is no longer necessary as the types are known and verified
using mypy.
One exception is tests/lib/wheel.py which allows tests to pass test
setup data as either bytes or str.
The module operations.install.wheel also remains untouched as it is
especially delicate to bytes/str mixups and the current version is
working.
Use pyupgrade to convert simple string formatting to use f-string
syntax. pyupgrade is intentionally timid and will not create an f-string
if it would make the expression longer or if the substitution parameters
are anything but simple names or dotted names.
Using typing.Text is unnecessary since dropping Python 2 support.
In Python 3, typing.Text is a simple alias of str. It exists as a
backward compatibility shim for Python 2.
This removes warnings from test output in python 3.8:
/usr/lib/python3.8/signal.py:60: RuntimeWarning:
invalid signal number 32, please use valid_signals()
This implementation uses tests.lib.make_wheel, which allows more
flexible wheel configuration in a more structured way.
Output-wise this should be almost identical to the previous
implementation, with the following exceptions:
* Metadata-Version is bumped from 2.0 (previous implementation) to 2.1
(from make_wheel).
* Fields previously supplied as UNKNOWN are now omitted since they are
not significant to tests.
* The DESCRIPTION file is omitted (since the description field is now
missing, see previous point).
As we introduce stricter metadata parsing, we will need to ensure that
the wheel files used in our tests are compliant (except in the specific
way that we're testing against).
Currently we have a large number of test cases relying on undocumented or
under-documented wheel files that have various inconsistencies
(incorrect name, missing fields) that are unrelated to the features
actually under test.
With a new wheel builder helper function, we will be able to replace all
of our instances of pre-built wheel test fixtures with dynamically-generated
files in code that are correct by default.
By default, make_archive uses str paths on Python 2, which causes it to
skip files with unencodable names. By passing in a unicode base_dir
explicitly, it is smart enough to use unicode all the way down instead.
We now extract all metadata files from the wheel directly into memory
and make them available to the wrapping pkg_resources.Distribution via
the DictMetadata introduced earlier.
Previously we were copying an existing wheel to a file with a
different distribution name. When using stricter metadata parsing this
would fail, so now we use a more conformant dummy wheel function.