Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_kwargs_same_name_different_kwarg(self):
python_node = self.get_ast_node(
"""
import foo
foo.bar(kwarg2="test")
"""
)
linter = get_bad_kwarg_use_implementation(
[
{
"module_path": "foo.bar",
"kwarg_name": "kwarg1",
"predicate": dlint.tree.kwarg_present,
},
]
)
linter.visit(python_node)
result = linter.get_results()
expected = []
assert result == expected
def test_decorator_name_unknown_type(self):
unknown_type = None
with pytest.raises(TypeError):
dlint.tree.decorator_name(unknown_type)
def visit_ImportFrom(self, node):
if not node.module:
# Relative imports, e.g. 'from .' or 'from ..'
return
from_import_names = [
node.module + "." + alias.name
for alias in node.names
if node.module + "." + alias.name not in self.whitelisted_modules
]
bad_from_import = any(
tree.same_modules(illegal_module, name)
for illegal_module in self.illegal_modules
for name in from_import_names
)
if bad_from_import:
self.results.append(
base.Flake8Result(
lineno=node.lineno,
col_offset=node.col_offset,
message=self._error_tmpl
)
"predicate": tree.kwarg_not_present,
},
{
"module_path": "defusedxml.lxml.iterparse",
"kwarg_name": "forbid_dtd",
"predicate": tree.kwarg_not_present,
},
{
"module_path": "defusedxml.lxml.parse",
"kwarg_name": "forbid_dtd",
"predicate": tree.kwarg_not_present,
},
{
"module_path": "defusedxml.lxml.fromstring",
"kwarg_name": "forbid_entities",
"predicate": tree.kwarg_false,
},
{
"module_path": "defusedxml.lxml.iterparse",
"kwarg_name": "forbid_entities",
"predicate": tree.kwarg_false,
},
{
"module_path": "defusedxml.lxml.parse",
"kwarg_name": "forbid_entities",
"predicate": tree.kwarg_false,
},
{
"module_path": "defusedxml.lxml.fromstring",
"kwarg_name": "forbid_external",
"predicate": tree.kwarg_false,
},
def missing_or_string(s, call, kwarg_name):
return (
tree.kwarg_not_present(call, kwarg_name)
or tree.kwarg_str(call, kwarg_name, s)
)
def unverified_cert_reqs(call, kwarg_name):
return tree.kwarg_any([
functools.partial(
tree.kwarg_str,
call,
kwarg_name,
"CERT_NONE"
),
functools.partial(
tree.kwarg_str,
call,
kwarg_name,
"NONE"
),
functools.partial(
tree.kwarg_module_path,
call,
kwarg_name,
def kwargs(self):
return [
{
"module_path": "SimpleXMLRPCServer.register_instance",
"kwarg_name": "allow_dotted_names",
"predicate": tree.kwarg_true,
},