Skip to content

Commit

Permalink
Create lint_python.yml
Browse files Browse the repository at this point in the history
As requested at robotframework#3313 (comment)  This is a exact replica of robotframework#3421
  • Loading branch information
cclauss committed Mar 31, 2020
1 parent 09c4088 commit a67c960
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 65 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/lint_python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: lint_python
on: [push, pull_request]
jobs:
lint_python:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
- run: pip install flake8
- run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
4 changes: 3 additions & 1 deletion atest/testdata/keywords/Annotations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# flake8: noqa

def annotations(arg1, arg2: str):
return ' '.join(['annotations:', arg1, arg2])

def annotations_with_defaults(arg1, arg2: 'has a default' = 'default'):
return ' '.join(['annotations:', arg1, arg2])
return ' '.join(['annotations:', arg1, arg2])
5 changes: 3 additions & 2 deletions atest/testdata/keywords/type_conversion/Annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,13 @@ def unknown(argument: Unknown, expected=None):
_validate_type(argument, expected)


def non_type(argument: 'this is string, not type', expected=None):
def non_type(argument: 'this is string, not type', # noqa: F821
expected=None):
_validate_type(argument, expected)


# Causes SyntaxError with `typing.get_type_hints`
def invalid(argument: 'import sys', expected=None):
def invalid(argument: 'import sys', expected=None): # noqa: F722
_validate_type(argument, expected)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# flake8: noqa

# Imports needed for evaluating expected result.
from datetime import datetime, date, timedelta
from decimal import Decimal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def typing_(a: List, b: List[int]):


# These cause exception with `typing.get_type_hints`
def invalid1(a: foo):
def invalid1(a: foo): # noqa: F821
assert a == 'xxx'


Expand Down
3 changes: 3 additions & 0 deletions atest/testdata/libdoc/Annotations.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# flake8: noqa


class UnknownType(object):
pass

Expand Down
2 changes: 2 additions & 0 deletions atest/testdata/test_libraries/module_lib_with_all.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# flake8: noqa

from os.path import join, abspath

__all__ = ['join_with_execdir', 'abspath', 'attr_is_not_kw',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

with open(join(CURDIR, 'src', 'robot', 'version.py')) as f:
exec(f.read())
VERSION = get_version()
VERSION = get_version() # noqa: F821
with open(join(CURDIR, 'README.rst')) as f:
LONG_DESCRIPTION = f.read()
base_url = 'https://github.com/robotframework/robotframework/blob/master'
Expand Down
6 changes: 3 additions & 3 deletions src/robot/htmldata/jsonwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from robot.utils import PY2
from robot.utils.robottypes import long, unicode


class JsonWriter(object):
Expand Down Expand Up @@ -75,7 +75,7 @@ def dump(self, data, mapping):


class StringDumper(_Dumper):
_handled_types = (str, unicode) if PY2 else str
_handled_types = (str, unicode)
_search_and_replace = [('\\', '\\\\'), ('"', '\\"'), ('\t', '\\t'),
('\n', '\\n'), ('\r', '\\r'), ('</', '\\x3c/')]

Expand All @@ -91,7 +91,7 @@ def _escape(self, string):

class IntegerDumper(_Dumper):
# Handles also bool
_handled_types = (int, long) if PY2 else int
_handled_types = (int, long)

def dump(self, data, mapping):
self._write(str(data).lower())
Expand Down
5 changes: 3 additions & 2 deletions src/robot/libraries/OperatingSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
get_env_var, get_env_vars, get_time, is_truthy,
is_unicode, normpath, parse_time, plural_or_not,
secs_to_timestamp, secs_to_timestr, seq2str,
set_env_var, timestr_to_secs, unic, CONSOLE_ENCODING,
IRONPYTHON, JYTHON, PY2, PY3, SYSTEM_ENCODING, WINDOWS)
set_env_var, timestr_to_secs, unic, unicode,
CONSOLE_ENCODING, IRONPYTHON, JYTHON, PY2, PY3,
SYSTEM_ENCODING, WINDOWS)

__version__ = get_version()
PROCESSES = ConnectionCache('No active processes.')
Expand Down
1 change: 1 addition & 0 deletions src/robot/reporting/jsexecutionresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from collections import OrderedDict

from robot.utils import IRONPYTHON, PY_VERSION
from robot.utils.robottypes import long

from .stringcache import StringIndex

Expand Down
2 changes: 1 addition & 1 deletion src/robot/testdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
html_escape, html_format, IRONPYTHON, is_string,
PY_VERSION, secs_to_timestr, seq2str2,
timestr_to_secs, unescape)

from robot.utils.robottypes import long

# http://ironpython.codeplex.com/workitem/31549
if IRONPYTHON and PY_VERSION < (2, 7, 2):
Expand Down
1 change: 1 addition & 0 deletions src/robot/utils/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import sys

from .platform import IRONPYTHON, PY2
from .robottypes import unicode


if PY2:
Expand Down
2 changes: 1 addition & 1 deletion src/robot/utils/robotio.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from .error import get_error_message
from .platform import PY3
from .robottypes import is_pathlike
from .robottypes import is_pathlike, unicode


def file_writer(path=None, encoding='UTF-8', newline=None, usage=None):
Expand Down
42 changes: 34 additions & 8 deletions src/robot/utils/robottypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,44 @@

from .platform import PY2

try:
long = long
unicode = unicode
except NameError:
long = int
unicode = str


def is_integer(item):
return isinstance(item, (int, long))


def is_number(item):
return isinstance(item, (int, long, float))


def is_bytes(item):
return isinstance(item, (bytes, bytearray))


def is_string(item):
# Returns False with `b'bytes'` on IronPython on purpose. Results of
# `isinstance(item, basestring)` would depend on IronPython 2.7.x version.
return isinstance(item, (str, unicode))


def is_unicode(item):
return isinstance(item, unicode)



if PY2:
from .robottypes2 import (is_bytes, is_dict_like, is_integer, is_list_like,
is_number, is_pathlike, is_string,
is_unicode, type_name, Mapping, MutableMapping)
unicode = unicode
from .robottypes2 import (is_dict_like, is_list_like, is_pathlike,
type_name, Mapping, MutableMapping)

else:
from .robottypes3 import (is_bytes, is_dict_like, is_integer, is_list_like,
is_number, is_pathlike, is_string,
is_unicode, type_name, Mapping, MutableMapping)
unicode = str
from .robottypes3 import (is_dict_like, is_list_like, is_pathlike,
type_name, Mapping, MutableMapping)


TRUE_STRINGS = {'TRUE', 'YES', 'ON', '1'}
Expand Down
24 changes: 2 additions & 22 deletions src/robot/utils/robottypes2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# flake8: noqa

from collections import Mapping, MutableMapping, Sequence
from UserDict import UserDict
from UserString import UserString
Expand All @@ -26,28 +28,6 @@
from .platform import RERAISED_EXCEPTIONS


def is_integer(item):
return isinstance(item, (int, long))


def is_number(item):
return isinstance(item, (int, long, float))


def is_bytes(item):
return isinstance(item, (bytes, bytearray))


def is_string(item):
# Returns False with `b'bytes'` on IronPython on purpose. Results of
# `isinstance(item, basestring)` would depend on IronPython 2.7.x version.
return isinstance(item, (str, unicode))


def is_unicode(item):
return isinstance(item, unicode)


def is_pathlike(item):
return False

Expand Down
20 changes: 0 additions & 20 deletions src/robot/utils/robottypes3.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,6 @@
from os import PathLike


def is_integer(item):
return isinstance(item, int)


def is_number(item):
return isinstance(item, (int, float))


def is_bytes(item):
return isinstance(item, (bytes, bytearray))


def is_string(item):
return isinstance(item, str)


def is_unicode(item):
return isinstance(item, str)


def is_pathlike(item):
return isinstance(item, PathLike)

Expand Down
2 changes: 1 addition & 1 deletion utest/utils/test_encoding.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from robot.utils import IRONPYTHON, PY3
from robot.utils import unicode, IRONPYTHON
from robot.utils.asserts import assert_equal
from robot.utils.encoding import console_decode, CONSOLE_ENCODING

Expand Down
4 changes: 2 additions & 2 deletions utest/utils/test_normalizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ def test_str(self):

def test_unicode(self):
nd = NormalizedDict({'a': u'\xe4', u'\xe4': 'a'})
if PY2:
try:
assert_equal(unicode(nd), "{'a': u'\\xe4', u'\\xe4': 'a'}")
else:
except NameError:
assert_equal(str(nd), u"{'a': '\xe4', '\xe4': 'a'}")

def test_update(self):
Expand Down

0 comments on commit a67c960

Please sign in to comment.