Skip to main content
added 1 character in body
Source Link
Reinderien
  • 71.1k
  • 5
  • 76
  • 256

filter_fn should probably be moved to a global because it does not need closure.

Combine state_names and exclude_path_snippets to one set via |, and then reduce to a single not in.

all is not called-for; use a single boolean expression. Once you have only one set comparison, you will only need one orand.

Don't raise a bare Exception. Raise a ValueError, or an application-specific exception.

Consider a tuple-unpack, potentially with a rethrow; and don't cast to a list:

try:
    filtered, = filter(filter_fn, path_snippets)
except ValueError as e:
    raise ValueError(f'Failed to extract URI from {path}') from e
return filtered

filter_fn deserves a better name like is_snippet_valid.

filter_fn should probably be moved to a global because it does not need closure.

Combine state_names and exclude_path_snippets to one set via |, and then reduce to a single not in.

all is not called-for; use a single boolean expression. Once you have only one set comparison, you will only need one or.

Don't raise a bare Exception. Raise a ValueError, or an application-specific exception.

Consider a tuple-unpack, potentially with a rethrow; and don't cast to a list:

try:
    filtered, = filter(filter_fn, path_snippets)
except ValueError as e:
    raise ValueError(f'Failed to extract URI from {path}') from e
return filtered

filter_fn deserves a better name like is_snippet_valid.

filter_fn should probably be moved to a global because it does not need closure.

Combine state_names and exclude_path_snippets to one set via |, and then reduce to a single not in.

all is not called-for; use a single boolean expression. Once you have only one set comparison, you will only need one and.

Don't raise a bare Exception. Raise a ValueError, or an application-specific exception.

Consider a tuple-unpack, potentially with a rethrow; and don't cast to a list:

try:
    filtered, = filter(filter_fn, path_snippets)
except ValueError as e:
    raise ValueError(f'Failed to extract URI from {path}') from e
return filtered

filter_fn deserves a better name like is_snippet_valid.

Source Link
Reinderien
  • 71.1k
  • 5
  • 76
  • 256

filter_fn should probably be moved to a global because it does not need closure.

Combine state_names and exclude_path_snippets to one set via |, and then reduce to a single not in.

all is not called-for; use a single boolean expression. Once you have only one set comparison, you will only need one or.

Don't raise a bare Exception. Raise a ValueError, or an application-specific exception.

Consider a tuple-unpack, potentially with a rethrow; and don't cast to a list:

try:
    filtered, = filter(filter_fn, path_snippets)
except ValueError as e:
    raise ValueError(f'Failed to extract URI from {path}') from e
return filtered

filter_fn deserves a better name like is_snippet_valid.