For below program, How could I detect the variable TypeError previously other than truly running it? Does Pylint or pyflake8 has this feature?
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
A = 1
B = 'b'
print(A+B)
For below program, How could I detect the variable TypeError previously other than truly running it? Does Pylint or pyflake8 has this feature?
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
A = 1
B = 'b'
print(A+B)
You can use either type or isinstance method
>>> type(1)
<type 'int'>
>>>
>>> isinstance(1, int)
True
>>>
TypeError
is an exception that occurs at runtime. To avoid the exception, you can use type()
or isinstance()
. Although, if you find yourself doing this frequently, then you should rethink your code design.