Skip to content

Always return an actual bool from has_* functions #353

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions distutils/command/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ def run(self) -> None:

# -- Predicates for the sub-command list ---------------------------

def has_pure_modules(self):
def has_pure_modules(self) -> bool:
return self.distribution.has_pure_modules()

def has_c_libraries(self):
def has_c_libraries(self) -> bool:
return self.distribution.has_c_libraries()

def has_ext_modules(self):
def has_ext_modules(self) -> bool:
return self.distribution.has_ext_modules()

def has_scripts(self):
def has_scripts(self) -> bool:
return self.distribution.has_scripts()

sub_commands = [
Expand Down
8 changes: 4 additions & 4 deletions distutils/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,24 +772,24 @@ def get_inputs(self):

# -- Predicates for sub-command list -------------------------------

def has_lib(self):
def has_lib(self) -> bool:
"""Returns true if the current distribution has any Python
modules to install."""
return (
self.distribution.has_pure_modules() or self.distribution.has_ext_modules()
)

def has_headers(self):
def has_headers(self) -> bool:
"""Returns true if the current distribution has any headers to
install."""
return self.distribution.has_headers()

def has_scripts(self):
def has_scripts(self) -> bool:
"""Returns true if the current distribution has any scripts to.
install."""
return self.distribution.has_scripts()

def has_data(self):
def has_data(self) -> bool:
"""Returns true if the current distribution has any data to.
install."""
return self.distribution.has_data_files()
Expand Down
4 changes: 3 additions & 1 deletion distutils/compilers/C/cygwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
cygwin in no-cygwin mode).
"""

from __future__ import annotations

import copy
import os
import pathlib
Expand Down Expand Up @@ -327,7 +329,7 @@ def check_config_h():
return code, f"{fn!r} {mention_inflected} {substring!r}"


def is_cygwincc(cc):
def is_cygwincc(cc: str | shlex._ShlexInstream) -> bool:
"""Try to determine if the compiler that would be used is from cygwin."""
out_string = check_output(shlex.split(cc) + ['-dumpmachine'])
return out_string.strip().endswith(b'cygwin')
Expand Down
10 changes: 5 additions & 5 deletions distutils/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,22 +1027,22 @@ def has_pure_modules(self) -> bool:
return len(self.packages or self.py_modules or []) > 0

def has_ext_modules(self) -> bool:
return self.ext_modules and len(self.ext_modules) > 0
return bool(self.ext_modules and len(self.ext_modules) > 0)

def has_c_libraries(self) -> bool:
return self.libraries and len(self.libraries) > 0
return bool(self.libraries and len(self.libraries) > 0)

def has_modules(self) -> bool:
return self.has_pure_modules() or self.has_ext_modules()

def has_headers(self) -> bool:
return self.headers and len(self.headers) > 0
return bool(self.headers and len(self.headers) > 0)

def has_scripts(self) -> bool:
return self.scripts and len(self.scripts) > 0
return bool(self.scripts and len(self.scripts) > 0)

def has_data_files(self) -> bool:
return self.data_files and len(self.data_files) > 0
return bool(self.data_files and len(self.data_files) > 0)

def is_pure(self) -> bool:
return (
Expand Down
2 changes: 1 addition & 1 deletion distutils/fancy_getopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def add_option(self, long_option, short_option=None, help_string=None):
self.option_table.append(option)
self.option_index[long_option] = option

def has_option(self, long_option):
def has_option(self, long_option: str) -> bool:
"""Return true if the option table for this parser has an
option with long name 'long_option'."""
return long_option in self.option_index
Expand Down
2 changes: 1 addition & 1 deletion distutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,6 @@ def is_mingw() -> bool:
return sys.platform == 'win32' and get_platform().startswith('mingw')


def is_freethreaded():
def is_freethreaded() -> bool:
"""Return True if the Python interpreter is built with free threading support."""
return bool(sysconfig.get_config_var('Py_GIL_DISABLED'))
Loading