Skip to content
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
2 changes: 1 addition & 1 deletion cohesion/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def get_file_contents(filename):
"""
Return contents of a file
"""
with open(filename) as fd:
with open(filename, "rb") as fd:
return fd.read()


Expand Down
2 changes: 1 addition & 1 deletion cohesion/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def from_file(cls, filename):

@classmethod
def from_string(cls, python_string):
module_ast_node = parser.get_ast_node_from_string(python_string)
module_ast_node = parser.get_ast_node_from_str_or_bytes(python_string)

return cls(module_ast_node)

Expand Down
4 changes: 2 additions & 2 deletions cohesion/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def get_module_classes(node):
]


def get_ast_node_from_string(string):
def get_ast_node_from_str_or_bytes(source):
"""
Return an AST node from a string
"""
return ast.parse(string)
return ast.parse(source)
2 changes: 1 addition & 1 deletion tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_get_file_contents(self):
contents = textwrap.dedent("""
class Cls(object):
pass
""")
""").encode("utf-8")

self.fs.create_file(
filename,
Expand Down
10 changes: 5 additions & 5 deletions tests/test_flake8_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def assertEmpty(self, iterable):
def test_flake8_extension_empty(self):
python_string = textwrap.dedent("")

ast_node = parser.get_ast_node_from_string(python_string)
ast_node = parser.get_ast_node_from_str_or_bytes(python_string)
checker = flake8_extension.CohesionChecker(ast_node, "unused")
checker.cohesion_below = 0.0

Expand All @@ -29,7 +29,7 @@ class Cls(object):
pass
""")

ast_node = parser.get_ast_node_from_string(python_string)
ast_node = parser.get_ast_node_from_str_or_bytes(python_string)
checker = flake8_extension.CohesionChecker(ast_node, "unused")
checker.cohesion_below = 0.0

Expand All @@ -52,7 +52,7 @@ def func(self):
self.variable = 'foo'
""")

ast_node = parser.get_ast_node_from_string(python_string)
ast_node = parser.get_ast_node_from_str_or_bytes(python_string)
checker = flake8_extension.CohesionChecker(ast_node, "unused")
checker.cohesion_below = 50.0

Expand All @@ -69,7 +69,7 @@ def func(self):
self.variable2 = 'baz'
""")

ast_node = parser.get_ast_node_from_string(python_string)
ast_node = parser.get_ast_node_from_str_or_bytes(python_string)
checker = flake8_extension.CohesionChecker(ast_node, "unused")
checker.cohesion_below = 75.0

Expand All @@ -92,7 +92,7 @@ def func(self):
self.variable = 'foo'
""")

ast_node = parser.get_ast_node_from_string(python_string)
ast_node = parser.get_ast_node_from_str_or_bytes(python_string)
checker = flake8_extension.CohesionChecker(ast_node, "unused")
checker.cohesion_below = str(0.0)

Expand Down
Loading