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

Add type hints to the remaining tests #1040

Merged
merged 1 commit into from
Sep 25, 2020

Conversation

Eric-Arellano
Copy link
Contributor

Now that we have full type coverage for the tests, we'll get useful validation when adding hints to our source code that the hints line up.

@@ -376,25 +386,11 @@ def can_write_dir(path):
return os.path.isdir(path) and os.access(path, os.R_OK | os.W_OK | os.X_OK)


def touch(file, times=None):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We never used the times kwarg. It's really tricky to get right with type hints, so I took the liberty to simplify this function.

I figure that we can add back the times part if we need it.

Comment on lines -86 to -98
def yield_files(directory):
for root, _, files in os.walk(directory):
for f in files:
filename = os.path.join(root, f)
rel_filename = os.path.relpath(filename, directory)
yield filename, rel_filename


def write_zipfile(directory, dest, reverse=False):
with open_zip(dest, "w") as zf:
for filename, rel_filename in sorted(yield_files(directory), reverse=reverse):
zf.write(filename, arcname=rel_filename)
return dest
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unused

@@ -135,7 +137,7 @@ def make_project(
os.path.join(name, "my_module.py"): 'def do_something():\n print("hello world!")\n',
os.path.join(name, "package_data/resource1.dat"): 1000,
os.path.join(name, "package_data/resource2.dat"): 1000,
}
} # type: Dict[str, Union[str, int]]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the best we can do with type casting. We can't use cast() because we can't use values like Dict at runtime.

Copy link
Member

@jsirois jsirois Sep 26, 2020

Choose a reason for hiding this comment

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

See below, but this is untrue, you just need to pass the type to cast as a string.

@@ -957,6 +996,7 @@ def test_pex_multi_resolve_2():

@contextmanager
def pex_manylinux_and_tag_selection_context():
# type: () -> Iterator[Tuple[Callable[[str, str, str, str, Optional[str]], None], Callable[[str, str, str, str], None]]]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely disgusting. But we can't use type aliases because those require setting variables at runtime, and that would break Python 2.

Copy link
Member

Choose a reason for hiding this comment

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

This is untrue. You can define the inside the if TYPE_CHECKING guard, and, if you need to cast to them, pass those type aliases to cast as strings.

Comment on lines -48 to +53
assert b"This is an exception" in so, "Standard out was: %s" % so
assert b"This is an exception" in so, "Standard out was: %r" % so
Copy link
Contributor Author

Choose a reason for hiding this comment

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

MyPy warns that this will cause you to bring b"abc", with the b prefix, when using Py3. It wants us to be explicit about that.

Copy link
Contributor

@tdyas tdyas left a comment

Choose a reason for hiding this comment

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

lgtm

@Eric-Arellano Eric-Arellano merged commit aae2a6a into pex-tool:master Sep 25, 2020
@Eric-Arellano Eric-Arellano deleted the more-test-hints branch September 25, 2020 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants