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

Fix flake8-return warnings #4169

Merged
merged 4 commits into from
Feb 7, 2024
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
6 changes: 3 additions & 3 deletions _distutils_hack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ def find_spec(self, fullname, path, target=None):
# optimization: only consider top level modules and those
# found in the CPython test suite.
if path is not None and not fullname.startswith('test.'):
return
return None

method_name = 'spec_for_{fullname}'.format(**locals())
method = getattr(self, method_name, lambda: None)
return method()

def spec_for_distutils(self):
if self.is_cpython():
return
return None

import importlib
import importlib.abc
Expand All @@ -108,7 +108,7 @@ def spec_for_distutils(self):
# setuptools from the path but only after the hook
# has been loaded. Ref #2980.
# In either case, fall back to stdlib behavior.
return
return None

class DistutilsLoader(importlib.abc.Loader):
def create_module(self, spec):
Expand Down
8 changes: 3 additions & 5 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,8 +1127,7 @@ def obtain(self, requirement, installer=None):
None is returned instead. This method is a hook that allows subclasses
to attempt other ways of obtaining a distribution before falling back
to the `installer` argument."""
if installer is not None:
return installer(requirement)
return installer(requirement) if installer else None

def __iter__(self):
"""Yield the unique project names of the available distributions"""
Expand Down Expand Up @@ -2833,9 +2832,7 @@ def _get_metadata(self, name):

def _get_version(self):
lines = self._get_metadata(self.PKG_INFO)
version = _version_from_file(lines)

return version
return _version_from_file(lines)

def activate(self, path=None, replace=False):
"""Ensure distribution is importable on `path` (default=sys.path)"""
Expand Down Expand Up @@ -3210,6 +3207,7 @@ def _find_adapter(registry, ob):
for t in types:
if t in registry:
return registry[t]
return None


def ensure_directory(path):
Expand Down
1 change: 1 addition & 0 deletions setuptools/command/bdist_egg.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def can_scan():
"Please ask the author to include a 'zip_safe'"
" setting (either True or False) in the package's setup.py"
)
return False


# Attribute names of options for commands that might need to be convinced to
Expand Down
3 changes: 1 addition & 2 deletions setuptools/command/bdist_rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ def run(self):

def _make_spec_file(self):
spec = orig.bdist_rpm._make_spec_file(self)
spec = [
return [
line.replace(
"setup.py install ",
"setup.py install --single-version-externally-managed ",
).replace("%setup", "%setup -n %{name}-%{unmangled_version}")
for line in spec
]
return spec
1 change: 1 addition & 0 deletions setuptools/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def get_abi3_suffix():
return suffix
elif suffix == '.pyd': # Windows
return suffix
return None


class build_ext(_build_ext):
Expand Down
2 changes: 2 additions & 0 deletions setuptools/command/develop.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ def install_egg_scripts(self, dist):
script_text = strm.read()
self.install_script(dist, script_name, script_text, script_path)

return None

def install_wrapper_scripts(self, dist):
dist = VersionlessRequirement(dist)
return easy_install.install_wrapper_scripts(self, dist)
Expand Down
5 changes: 2 additions & 3 deletions setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ def install_item(self, spec, download, tmpdir, deps, install_needed=False):
for dist in dists:
if dist in spec:
return dist
return None

def select_scheme(self, name):
try:
Expand Down Expand Up @@ -1473,9 +1474,7 @@ def get_site_dirs():
with contextlib.suppress(AttributeError):
sitedirs.extend(site.getsitepackages())

sitedirs = list(map(normalize_path, sitedirs))

return sitedirs
return list(map(normalize_path, sitedirs))


def expand_paths(inputs): # noqa: C901 # is too complex (11) # FIXME
Expand Down
5 changes: 5 additions & 0 deletions setuptools/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def handle_extra_path(self):
# command without --root or --single-version-externally-managed
self.path_file = None
self.extra_dirs = ''
return None

def run(self):
# Explicit request for old-style install? Just do it
Expand All @@ -83,6 +84,8 @@ def run(self):
else:
self.do_egg_install()

return None

@staticmethod
def _called_from_setup(run_frame):
"""
Expand Down Expand Up @@ -114,6 +117,8 @@ def _called_from_setup(run_frame):

return caller_module == 'distutils.dist' and info.function == 'run_commands'

return False

def do_egg_install(self):
easy_install = self.distribution.get_command_class('easy_install')

Expand Down
1 change: 1 addition & 0 deletions setuptools/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def extract_constant(code, symbol, default=-1):
else:
const = default

return None

def _update_globals():
"""
Expand Down
2 changes: 1 addition & 1 deletion setuptools/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def analyse_name(self):
"""
if self.dist.metadata.name or self.dist.name:
# get_name() is not reliable (can return "UNKNOWN")
return None
return

log.debug("No `name` configuration, performing automatic discovery")

Expand Down
2 changes: 2 additions & 0 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,8 @@ def has_contents_for(self, package):
if p == package or p.startswith(pfx):
return True

return False

def _exclude_misc(self, name, value):
"""Handle 'exclude()' for list/tuple attrs without a special handler"""
if not isinstance(value, sequence):
Expand Down
3 changes: 1 addition & 2 deletions setuptools/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@ def _fetch_build_egg_no_warn(dist, req): # noqa: C901 # is too complex (16) #
dist_metadata = pkg_resources.PathMetadata(
dist_location, os.path.join(dist_location, 'EGG-INFO')
)
dist = pkg_resources.Distribution.from_filename(
return pkg_resources.Distribution.from_filename(
dist_location, metadata=dist_metadata
)
return dist


def strip_marker(req):
Expand Down
6 changes: 6 additions & 0 deletions setuptools/msvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ def lookup(self, key, name):
finally:
if bkey:
closekey(bkey)
return None


class SystemInfo:
Expand Down Expand Up @@ -823,6 +824,7 @@ def WindowsSdkVersion(self):
return '8.1', '8.1a'
elif self.vs_ver >= 14.0:
return '10.0', '8.1'
return None

@property
def WindowsSdkLastVersion(self):
Expand Down Expand Up @@ -914,6 +916,8 @@ def WindowsSDKExecutablePath(self):
if execpath:
return execpath

return None

@property
def FSharpInstallDir(self):
"""
Expand Down Expand Up @@ -946,6 +950,8 @@ def UniversalCRTSdkDir(self):
if sdkdir:
return sdkdir or ''

return None

@property
def UniversalCRTSdkLastVersion(self):
"""
Expand Down
7 changes: 6 additions & 1 deletion setuptools/package_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def add(self, dist):
try:
parse_version(dist.version)
except Exception:
return
return None
return super().add(dist)

# FIXME: 'PackageIndex.process_url' is too complex (14)
Expand Down Expand Up @@ -406,6 +406,7 @@ def url_ok(self, url, fatal=False):
raise DistutilsError(msg % url)
else:
self.warn(msg, url)
return False

def scan_egg_links(self, search_path):
dirs = filter(os.path.isdir, search_path)
Expand Down Expand Up @@ -648,6 +649,8 @@ def find(req, env=None):
if os.path.exists(dist.download_location):
return dist

return None

if force_scan:
self.prescan()
self.find_packages(requirement)
Expand All @@ -671,6 +674,7 @@ def find(req, env=None):
(source and "a source distribution of " or ""),
requirement,
)
return None
else:
self.info("Best match: %s", dist)
return dist.clone(location=dist.download_location)
Expand Down Expand Up @@ -1034,6 +1038,7 @@ def find_credential(self, url):
for repository, cred in self.creds_by_repository.items():
if url.startswith(repository):
return cred
return None


def open_with_auth(url, opener=urllib.request.urlopen):
Expand Down
4 changes: 2 additions & 2 deletions setuptools/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def dump(type, exc):

class ExceptionSaver:
"""
A Context Manager that will save an exception, serialized, and restore it
A Context Manager that will save an exception, serialize, and restore it
later.
"""

Expand All @@ -124,7 +124,7 @@ def __enter__(self):

def __exit__(self, type, exc, tb):
if not exc:
return
return False

# dump the exception
self._saved = UnpickleableException.dump(type, exc)
Expand Down
1 change: 0 additions & 1 deletion setuptools/tests/config/test_setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,6 @@ def _fake_distribution_init(self, dist, attrs):
'Link One': 'https://example.com/one/',
'Link Two': 'https://example.com/two/',
}
return None

@patch.object(_Distribution, '__init__', autospec=True)
def test_external_setters(self, mock_parent_init, tmpdir):
Expand Down
3 changes: 1 addition & 2 deletions setuptools/tests/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,4 @@ def path_to_url(path, authority=None):
base = 'file:'
if authority is not None:
base += '//' + authority
url = urllib.parse.urljoin(base, urllib.request.pathname2url(path))
return url
return urllib.parse.urljoin(base, urllib.request.pathname2url(path))
3 changes: 1 addition & 2 deletions setuptools/tests/test_build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,11 @@ def dist_with_example(self):
ext3 = Extension("ext3", ["c-extension/ext3.c"])

path.build(files)
dist = Distribution({
return Distribution({
"script_name": "%test%",
"ext_modules": [ext1, ext2, ext3],
"package_dir": {"": "src"},
})
return dist

def test_get_outputs(self, tmpdir_cwd, monkeypatch):
monkeypatch.setenv('SETUPTOOLS_EXT_SUFFIX', '.mp3') # make test OS-independent
Expand Down
8 changes: 2 additions & 6 deletions setuptools/tests/test_core_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __read_test_cases():

params = functools.partial(dict, base)

test_cases = [
return [
('Metadata version 1.0', params()),
(
'Metadata Version 1.0: Short long description',
Expand Down Expand Up @@ -156,8 +156,6 @@ def __read_test_cases():
),
]

return test_cases


@pytest.mark.parametrize('name,attrs', __read_test_cases())
def test_read_metadata(name, attrs):
Expand Down Expand Up @@ -209,7 +207,7 @@ def merge_dicts(d1, d2):

return d1

test_cases = [
return [
('No author, no maintainer', attrs.copy()),
(
'Author (no e-mail), no maintainer',
Expand Down Expand Up @@ -267,8 +265,6 @@ def merge_dicts(d1, d2):
('Maintainer unicode', merge_dicts(attrs, {'maintainer': 'Jan Łukasiewicz'})),
]

return test_cases


@pytest.mark.parametrize('name,attrs', __maintainer_test_cases())
def test_maintainer_author(name, attrs, tmpdir):
Expand Down
4 changes: 1 addition & 3 deletions setuptools/tests/test_distutils_adoption.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ def win_sr(env):
> Fatal Python error: _Py_HashRandomization_Init: failed to
> get random numbers to initialize Python
"""
if env is None:
return
if platform.system() == 'Windows':
if env and platform.system() == 'Windows':
env['SYSTEMROOT'] = os.environ['SYSTEMROOT']
return env

Expand Down
4 changes: 3 additions & 1 deletion setuptools/unicode_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def decompose(path):
def filesys_decode(path):
"""
Ensure that the given path is decoded,
NONE when no expected encoding works
``None`` when no expected encoding works
"""

if isinstance(path, str):
Expand All @@ -33,6 +33,8 @@ def filesys_decode(path):
except UnicodeDecodeError:
continue

return None


def try_encode(string, enc):
"turn unicode encoding into a functional routine"
Expand Down
Loading