diff --git a/.pylintrc b/.pylintrc index 817c301..de77cc5 100644 --- a/.pylintrc +++ b/.pylintrc @@ -7,13 +7,14 @@ # pygtk.require(). #init-hook= -# Profiled execution. -profile=no - # Add files or directories to the blacklist. They should be base names, not # paths. ignore=.git,doc, +# Add files or directories matching the regex patterns to the blacklist. The +# regex matches against base names, not paths. +ignore-patterns= + # Pickle collected data for later comparisons. persistent=yes @@ -21,12 +22,38 @@ persistent=yes # usually to register additional checkers. load-plugins= +# Use multiple processes to speed up Pylint. +jobs=1 + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code +extension-pkg-whitelist= + +# Allow optimization of some AST trees. This will activate a peephole AST +# optimizer, which will apply various small optimizations. For instance, it can +# be used to obtain the result of joining multiple strings with the addition +# operator. Joining a lot of strings can lead to a maximum recursion error in +# Pylint and this flag can prevent that. It has one side effect, the resulting +# AST will be different than the one from reality. This option is deprecated +# and it will be removed in Pylint 2.0. +optimize-ast=no + [MESSAGES CONTROL] +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED +confidence= + # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option -# multiple time. See also the "--disable" option for examples. +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. #enable= # Disable the message, report, category or checker with the given id(s). You @@ -38,39 +65,7 @@ load-plugins= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -#disable= - -disable=C0111,W0611,R0201,W0613,R0903,E1101,I0011,W0232 - -# C0111 missing-docstring Our priority is to make the code document -# itself. Docstring is required only when -# the signature is not enough to tell -# everything important. -# -# W0611 unused-import Pylint does not count our type-hinting -# annotations as a use of a class name, thus, -# this rule results in many false-positives. -# -# R0201 no-self-use Extracting private methods inside a class -# to increase readability often results in -# some methods that don't use the `self`. -# -# W0613 unused-argument Methods of test doubles, for example stubs, -# often return canned values, not using any -# of their arguments. -# -# R0903 too-few-public-methods Node classes often have no methods at all. -# -# E1101 no-member Used when a variable is accessed for a -# nonexistent member. -# Reason: Too many false positives -# -# I0011 locally-disabled Disabling a Pylint warning is always the -# result of a decision, no additional notification -# is required to tell us what we did. -# -# W0232 no-init New-style classes (see above) do not require __init__ methods, -# the object class has a perfectly fine default constructor. +disable=import-star-module-level,old-octal-literal,oct-method,print-statement,unpacking-in-except,parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,execfile-builtin,coerce-builtin,cmp-builtin,buffer-builtin,basestring-builtin,apply-builtin,filter-builtin-not-iterating,using-cmp-argument,useless-suppression,range-builtin-not-iterating,suppressed-message,no-absolute-import,old-division,cmp-method,reload-builtin,zip-builtin-not-iterating,intern-builtin,unichr-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,input-builtin,round-builtin,hex-method,nonzero-method,map-builtin-not-iterating,missing-docstring,unused-import,no-self-use,unused-argument,too-few-public-methods,no-member,locally-disabled,locally-disabled,no-init [REPORTS] @@ -78,11 +73,12 @@ disable=C0111,W0611,R0201,W0613,R0903,E1101,I0011,W0232 # Set the output format. Available formats are text, parseable, colorized, msvs # (visual studio) and html. You can also give a reporter class, eg # mypackage.mymodule.MyReporterClass. -#output-format=parseable +output-format=text # Put messages in a separate file for each module / package specified on the # command line instead of printing them on stdout. Reports (if any) will be -# written in a file name "pylint_global.[txt|html]". +# written in a file name "pylint_global.[txt|html]". This option is deprecated +# and it will be removed in Pylint 2.0. files-output=no # Tells whether to display a full report or only the messages @@ -95,108 +91,146 @@ reports=yes # (RP0004). evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) -# Add a comment according to your evaluation note. This is used by the global -# evaluation report (RP0004). -comment=no - # Template used to display messages. This is a python new-style format string # used to format the message information. See doc for all details msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} +[BASIC] -[SIMILARITIES] +# Good variable names which should always be accepted, separated by a comma +good-names=i,j,k,ex,Run,_ -# Minimum lines number of a similarity. -min-similarity-lines=3 +# Bad variable names which should always be refused, separated by a comma +bad-names=foo,bar,baz,toto,tutu,tata -# Ignore comments when computing similarities. -ignore-comments=yes +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= -# Ignore docstrings when computing similarities. -ignore-docstrings=yes +# Include a hint for the correct naming format with invalid-name +include-naming-hint=no -# Ignore imports when computing similarities. -ignore-imports=no +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +property-classes=abc.abstractproperty +# Regular expression matching correct function names +function-rgx=(test_[a-z0-9_]+|[a-z_][a-z0-9_]{2,40})$ -[VARIABLES] +# Naming hint for function names +function-name-hint=[a-z_][a-z0-9_]{2,40}$ -# Tells whether we should check for unused import in __init__ files. -init-import=no +# Regular expression matching correct variable names +variable-rgx=[a-z_][a-z0-9_]{2,40}$ -# A regular expression matching the beginning of the name of dummy variables -# (i.e. not used). -dummy-variables-rgx=_$|dummy +# Naming hint for variable names +variable-name-hint=[a-z_][a-z0-9_]{2,40}$ -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. -additional-builtins= +# Regular expression matching correct constant names +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ +# Naming hint for constant names +const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ -[BASIC] +# Regular expression matching correct attribute names +attr-rgx=[a-z_][a-z0-9_]{2,40}$ -# Required attributes for module, separated by a comma -required-attributes= +# Naming hint for attribute names +attr-name-hint=[a-z_][a-z0-9_]{2,40}$ -# List of builtins function names that should not be used, separated by a comma -bad-functions=map,filter,apply,input +# Regular expression matching correct argument names +argument-rgx=[a-z_][a-z0-9_]{2,40}$ -# Regular expression which should only match correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ +# Naming hint for argument names +argument-name-hint=[a-z_][a-z0-9_]{2,40}$ -# Regular expression which should only match correct module level names -const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ +# Regular expression matching correct class attribute names +class-attribute-rgx=(test_[a-z0-9_]+|[A-Za-z_][A-Za-z0-9_]{2,40}|(__.*__))$ -# Regular expression which should only match correct class names -class-rgx=[A-Z_][a-zA-Z0-9]+$ +# Naming hint for class attribute names +class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,40}|(__.*__))$ -# Regular expression which should only match correct function names -# Private functions are allowed to have nice explanatory names -function-rgx=(([a-z][a-z0-9_]{2,40})|(__[a-z_0-9]{2,70}))$ +# Regular expression matching correct inline iteration names +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ -# Regular expression which should only match correct method names -# Private methods and BDD-style xUnit test functions are allowed to have nice -# explanatory names -method-rgx=((_?[a-z][a-z0-9_]{2,40})|(__[a-z_0-9]{2,70})|(test[a-z0-9_]{2,100}))$ +# Naming hint for inline iteration names +inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ -# Regular expression which should only match correct instance attribute names -# Private instance attribute names are allowed to have nice explanatory names -attr-rgx=((_?[a-z][a-z0-9_]{2,30})|(__[a-z_0-9]{2,70}))$ +# Regular expression matching correct class names +class-rgx=[A-Z_][a-zA-Z0-9]+$ -# Regular expression which should only match correct argument names -# Type annotated short argument names are okay -argument-rgx=[a-z_][a-z0-9_]{0,30}$ +# Naming hint for class names +class-name-hint=[A-Z_][a-zA-Z0-9]+$ -# Regular expression which should only match correct variable names -variable-rgx=[a-z_][a-z0-9_]{1,30}$ +# Regular expression matching correct module names +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ -# Regular expression which should only match correct attribute names in class -# bodies -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ +# Naming hint for module names +module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ -# Regular expression which should only match correct list comprehension / -# generator expression variable names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ +# Regular expression matching correct method names +method-rgx=(test_[a-z0-9_]+|[a-z_][a-z0-9_]{2,40})$ -# Good variable names which should always be accepted, separated by a comma -good-names=i,j,k,ex,Run,_,f - -# Bad variable names which should always be refused, separated by a comma -bad-names=foo,bar,baz,toto,tutu,tata,tmp,tmp2 +# Naming hint for method names +method-name-hint=([xyz]|test_[a-z_][a-z0-9_]*|[a-z_][a-z0-9_]{2,40})$ # Regular expression which should only match function or class names that do # not require a docstring. -no-docstring-rgx=__.*__ +no-docstring-rgx=^_ # Minimum line length for functions/classes that require docstrings, shorter # ones are exempt. docstring-min-length=-1 -[MISCELLANEOUS] +[ELIF] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 -# List of note tags to take in consideration, separated by a comma. -notes=FIXME,XXX,TODO + +[SIMILARITIES] + +# Minimum lines number of a similarity. +min-similarity-lines=4 + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=no + + +[LOGGING] + +# Logging modules to check that the string format arguments are in logging +# function parameter format +logging-modules=logging + + +[VARIABLES] + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# A regular expression matching the name of dummy variables (i.e. expectedly +# not used). +dummy-variables-rgx=(_+[a-zA-Z0-9]*?$)|dummy + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_,_cb + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,future.builtins [FORMAT] @@ -207,13 +241,29 @@ max-line-length=120 # Regexp for a line that is allowed to be longer than the limit. ignore-long-lines=^\s*(# )??$ +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + +# List of optional constructs for which whitespace checking is disabled. `dict- +# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. +# `trailing-comma` allows a space between comma and closing bracket: (a, ). +# `empty-line` allows space-only lines. +no-space-check=trailing-comma,dict-separator + # Maximum number of lines in a module max-module-lines=1000 -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 # tab). indent-string=' ' +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +expected-line-ending-format= + [TYPECHECK] @@ -221,18 +271,49 @@ indent-string=' ' # mixin class is detected if its name ends with "mixin" (case insensitive). ignore-mixin-members=yes -# List of classes names for which member attributes should not be checked -# (useful for classes with attributes dynamically set). -ignored-classes=SQLObject +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis. It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules= -# When zope mode is activated, add a predefined set of Zope acquired attributes -# to generated-members. -zope=no +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=optparse.Values,thread._local,_thread._local # List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E0201 when accessed. Python regular +# system, and so shouldn't trigger E1101 when accessed. Python regular # expressions are accepted. -generated-members=REQUEST,acl_users,aq_parent +generated-members= + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + + +[SPELLING] + +# Spelling dictionary name. Available dictionaries: none. To make it working +# install python-enchant package. +spelling-dict= + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to indicated private dictionary in +# --spelling-private-dict-file option instead of raising a message. +spelling-store-unknown-words=no + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME,XXX,TODO [DESIGN] @@ -263,11 +344,13 @@ max-parents=7 max-attributes=7 # Minimum number of public methods for a class (see R0903). -min-public-methods=0 +min-public-methods=2 # Maximum number of public methods for a class (see R0904). -# Classes inheriting from unittest.TestCase may have more than 50 methods -max-public-methods=100 +max-public-methods=20 + +# Maximum number of boolean expressions in a if statement +max-bool-expr=5 [IMPORTS] @@ -277,22 +360,30 @@ deprecated-modules=regsub,TERMIOS,Bastion,rexec # Create a graph of every (i.e. internal and external) dependencies in the # given file (report RP0402 must not be disabled) -import-graph=pylint_import_graph.dot +import-graph= # Create a graph of external dependencies in the given file (report RP0402 must # not be disabled) -ext-import-graph=pylint_ext_import-graph.dot +ext-import-graph= # Create a graph of internal dependencies in the given file (report RP0402 must # not be disabled) -int-import-graph=pylint_int_import-graph.dot +int-import-graph= +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= -[CLASSES] +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no -# List of interface methods to ignore, separated by a comma. This is used for -# instance to not check methods defines in Zope's Interface base class. -ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by + +[CLASSES] # List of method names used to declare (i.e. assign) instance attributes. defining-attr-methods=__init__,__new__,setUp @@ -303,6 +394,10 @@ valid-classmethod-first-arg=cls # List of valid names for the first argument in a metaclass class method. valid-metaclass-classmethod-first-arg=mcs +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict,_fields,_replace,_source,_make + [EXCEPTIONS] diff --git a/.travis.yml b/.travis.yml index fe4280e..430aa1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,20 @@ language: python -python: 3.4 sudo: false -env: - - TOX_ENV=py32 - - TOX_ENV=py33 - - TOX_ENV=py34 +matrix: + include: + - python: 3.4 + env: + - TOX_ENV=py34 + - python: 3.5 + env: + - TOX_ENV=py35 + - python: 3.6 + env: + - TOX_ENV=py36 install: - - case ${TOX_ENV} in - py32) pip install virtualenv\<14 --upgrade;; - *) pip install virtualenv --upgrade;; - esac + - pip install virtualenv --upgrade - pip install tox script: diff --git a/features/environment.py b/features/environment.py index 2372020..37990df 100644 --- a/features/environment.py +++ b/features/environment.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either diff --git a/features/steps/steps.py b/features/steps/steps.py index ed4ce5a..9472978 100644 --- a/features/steps/steps.py +++ b/features/steps/steps.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either diff --git a/scripts/copyright.py b/scripts/copyright.py index dc3c0c5..6c2077a 100755 --- a/scripts/copyright.py +++ b/scripts/copyright.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either @@ -49,10 +49,10 @@ def match_patterns(text, patterns): with open(os.path.join(BASE_PATH, 'copyright.txt')) as f: COPYRIGHT_TEXT = f.read() FILTER_EXTENSION = {'.py', '.sh'} -BEGIN_PATTERN = re.compile(r"^Copyright \(c\) 2013-(20[0-9]{2}) BalaBit$") +BEGIN_PATTERN = re.compile(r"^Copyright \(c\) 2013-(20[0-9]{2}) Balabit$") UPDATE_COPYRIGHT_HEADER = ''' -Copyright (c) 2013-{year} BalaBit +Copyright (c) 2013-{year} Balabit {copyright}\ '''.format(year=THIS_YEAR, copyright=COPYRIGHT_TEXT) diff --git a/setup.py b/setup.py index 9fe8174..3fef3a7 100755 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either @@ -38,7 +38,7 @@ are valid. """, license="LGPLv2+", - version="1.0.3", + version="2.0.0", author="Viktor Hercinger", author_email="viktor.hercinger@balabit.com", maintainer="Viktor Hercinger", diff --git a/tox.ini b/tox.ini index 4c08d8e..1ca3b25 100644 --- a/tox.ini +++ b/tox.ini @@ -1,26 +1,20 @@ [tox] -envlist=py34,py33,py32 +envlist=py36,py35,py34 [testenv] deps= nose pytest mock - pep8 + pycodestyle - py34,py33: pylint - py32: logilab-common==0.62.1 - py32: astroid==1.2.1 - py32: pylint==1.3.1 + pylint + behave - py33,py34: behave - py32: behave==1.2.4 - py33,py32: enum34 + coverage - py34,py33: coverage - py32: coverage<4.0.0 commands= - pep8 --repeat typesafety + pycodestyle --max-line-length 120 --repeat typesafety pylint -f parseable --rcfile=.pylintrc typesafety nosetests --with-coverage --with-doctest typesafety behave diff --git a/typesafety/__init__.py b/typesafety/__init__.py index 140fe06..1be1706 100644 --- a/typesafety/__init__.py +++ b/typesafety/__init__.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either diff --git a/typesafety/autodecorator.py b/typesafety/autodecorator.py index 07b2b5f..98b03ca 100644 --- a/typesafety/autodecorator.py +++ b/typesafety/autodecorator.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either @@ -135,7 +135,7 @@ def __set_attribute(self, module, key, value): # We want to catch all errors here since any problems with setting # a module attribute to the decorated function is non-fatal. # pylint: disable=W0702 - except: + except: # noqa if hasattr(module, '__module__'): name = '{}.{}'.format(module.__module__, module.__name__) diff --git a/typesafety/finder.py b/typesafety/finder.py index d388e73..4c83403 100644 --- a/typesafety/finder.py +++ b/typesafety/finder.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either @@ -141,8 +141,11 @@ def find_module(self, fullname, path=None): This will do nothing, since we use the system to locate a module. ''' + loader = None if self.__filter is None or self.__filter(fullname): - return ModuleLoader(self, fullname, path) + loader = ModuleLoader(self, fullname, path) + + return loader def load_module(self, loader): ''' diff --git a/typesafety/noseplugin.py b/typesafety/noseplugin.py index 908e2be..b66be71 100644 --- a/typesafety/noseplugin.py +++ b/typesafety/noseplugin.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either @@ -80,7 +80,7 @@ def options(self, parser, env): '(useful when debugging typesafety)' ) - def configure(self, options, config): + def configure(self, options, conf): if options.enable_typesafety: self.enabled = True self.__enabled_for = tuple( diff --git a/typesafety/pytest_typesafety.py b/typesafety/pytest_typesafety.py index b2ca1d6..4a20c9e 100644 --- a/typesafety/pytest_typesafety.py +++ b/typesafety/pytest_typesafety.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either diff --git a/typesafety/pytests/check_pytest_plugin.py b/typesafety/pytests/check_pytest_plugin.py index 4f27ee0..8a2b8fe 100644 --- a/typesafety/pytests/check_pytest_plugin.py +++ b/typesafety/pytests/check_pytest_plugin.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either diff --git a/typesafety/sphinxautodoc.py b/typesafety/sphinxautodoc.py index 94136b5..1f576d1 100644 --- a/typesafety/sphinxautodoc.py +++ b/typesafety/sphinxautodoc.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either diff --git a/typesafety/tests/externalmodule.py b/typesafety/tests/externalmodule.py index 78cb4c8..16118b7 100644 --- a/typesafety/tests/externalmodule.py +++ b/typesafety/tests/externalmodule.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either diff --git a/typesafety/tests/mockmodule.py b/typesafety/tests/mockmodule.py index b086600..ea753b4 100644 --- a/typesafety/tests/mockmodule.py +++ b/typesafety/tests/mockmodule.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either @@ -19,33 +19,16 @@ import collections from . import mockmodule2 -from .version import is_above_version # External objects not native to this module from .externalmodule import UndecoratedClass, undecorated_function -if not is_above_version('3.2'): - class ClassWithSlots: - __slots__ = ['mutable'] - - @property - def immutable(self): - return 1 - - @property - def mutable(self): - return 2 - - def function(): pass class ModuleClass(object): - def __init__(self): - super(ModuleClass, self).__init__() - def method(self): pass diff --git a/typesafety/tests/mockmodule2.py b/typesafety/tests/mockmodule2.py index 63a000c..32e875a 100644 --- a/typesafety/tests/mockmodule2.py +++ b/typesafety/tests/mockmodule2.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either diff --git a/typesafety/tests/test_autodecorator.py b/typesafety/tests/test_autodecorator.py index f7b657a..58dbd59 100644 --- a/typesafety/tests/test_autodecorator.py +++ b/typesafety/tests/test_autodecorator.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either @@ -18,8 +18,6 @@ import sys import unittest -from .version import skip_above_version - from ..autodecorator import decorate_module @@ -67,17 +65,6 @@ def __unload_test_module(self, name): if fullname in sys.modules: del sys.modules[fullname] - @skip_above_version( - "3.2", - "Defining slots this way causes a ValueError, so they become " + - "unreachable for the autodecorator. Every other fix like this " + - "in other software simply removes slot entries " + - "like ClassWithSlots.mutable." - ) - def test_immutable_class_attributes_are_not_decorated(self): - self.assertEqual(1, self._module.ClassWithSlots().immutable) - self.assertEqual(1234, self._module.ClassWithSlots().mutable) - def test_dont_decorate_objects_not_native_to_the_module(self): self.assertEqual(2, self._module.UndecoratedClass().method(1)) self.assertEqual(3, self._module.undecorated_function(1)) diff --git a/typesafety/tests/test_finder.py b/typesafety/tests/test_finder.py index a33f79b..69e08a6 100644 --- a/typesafety/tests/test_finder.py +++ b/typesafety/tests/test_finder.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either diff --git a/typesafety/tests/test_plugin.py b/typesafety/tests/test_plugin.py index 78893f5..c334a8c 100644 --- a/typesafety/tests/test_plugin.py +++ b/typesafety/tests/test_plugin.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either diff --git a/typesafety/tests/test_sphinxautodoc.py b/typesafety/tests/test_sphinxautodoc.py index 20c52dd..7892861 100644 --- a/typesafety/tests/test_sphinxautodoc.py +++ b/typesafety/tests/test_sphinxautodoc.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either @@ -19,12 +19,12 @@ import collections from functools import wraps -from .version import skip_above_version, skip_below_or_at_version -from typesafety.sphinxautodoc import add_annotations_to_signature +from ..sphinxautodoc import add_annotations_to_signature -class TestAnnotatedDocsForMethodSignatures(unittest.TestCase): +# Is a test suite, can have as many public methods as needed. +class TestAnnotatedDocsForMethodSignatures(unittest.TestCase): # pylint: disable=too-many-public-methods def test_only_functions_classes_and_and_methods_are_considered(self): self.__assert_signature_docs_override( None, @@ -196,20 +196,6 @@ def test_decorated_methods_are_resolved_when_decor_func_attr_is_set(self): ExampleClass.method_with_decorators ) - @skip_above_version( - "3.3", - "For some reason, version(s) 3.3+ handle annotations of decorated " - "functions differently. In 3.4 this seems to be fixed." - ) - def test_decorated_methods_should_not_trigger_inifinite_loop(self): - self.__assert_signature_docs_override( - ("(*args, **kwargs)", ""), - "method", - "ExampleClass.method_with_recursive_decorator", - ExampleClass.method_with_recursive_decorator - ) - - @skip_below_or_at_version("3.3", "See the exact explanation above") def test_decorated_methods_dont_trigger_inf_loop_but_return_none(self): self.__assert_signature_docs_override( None, @@ -218,20 +204,6 @@ def test_decorated_methods_dont_trigger_inf_loop_but_return_none(self): ExampleClass.method_with_recursive_decorator ) - @skip_above_version( - "3.3", - "For some reason, version(s) 3.3+ handle annotations of decorated " + - "functions differently. In 3.4 this seems to be fixed." - ) - def test_decorated_methods_should_not_trigger_errors(self): - self.__assert_signature_docs_override( - ("(*args, **kwargs)", ""), - "method", - "ExampleClass.method_with_messed_up_decorator", - ExampleClass.method_with_messed_up_decorator - ) - - @skip_below_or_at_version("3.3", "See the exact explanation above") def test_decorated_methods_should_not_trigger_errors_but_return_none(self): self.__assert_signature_docs_override( None, @@ -286,7 +258,7 @@ def function_with_annotated_varargs(an_int, *varargs: list, **varkwargs: dict): pass -def function_with_complex_default_value(a_tuple: tuple=(1, 2, 3)): +def function_with_complex_default_value(a_tuple: tuple = (1, 2, 3)): pass @@ -329,8 +301,8 @@ def __init__(self, an_int: int): def method_with_default_value( self, a_float: float, - an_int: int=42, - an_str: str="" + an_int: int = 42, + an_str: str = "" ): pass @@ -340,7 +312,7 @@ def method_with_varargs(self, an_int: int, *varargs, **varkwargs): def method_with_kwonly_arg(self, a_float: float, *, an_int: int): pass - def method_with_default_value_for_self(self=None, an_int: int=42): + def method_with_default_value_for_self(self=None, an_int: int = 42): pass def method_with_class_names(self, an_object: SomeClass) -> SomeClass: diff --git a/typesafety/tests/test_validator.py b/typesafety/tests/test_validator.py index 934786a..f215f19 100644 --- a/typesafety/tests/test_validator.py +++ b/typesafety/tests/test_validator.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either @@ -28,12 +28,13 @@ def func_arg_validate( return 1 -class TestValidator(unittest.TestCase): +# Is a test suite, can have as many public methods as needed. +class TestValidator(unittest.TestCase): # pylint: disable=too-many-public-methods def setUp(self): self._validator = Validator(func_arg_validate) def test_function_has_no_annotation(self): - def func_no_annotation(x, y, z): + def func_no_annotation(arg0, arg1, arg2): pass validator = Validator(func_no_annotation) @@ -41,7 +42,7 @@ def func_no_annotation(x, y, z): self.assertFalse(validator.need_validate_return_value) def test_function_has_arg_annotation(self): - def func_arg_annotated(x: type): + def func_arg_annotated(arg: type): pass validator = Validator(func_arg_annotated) @@ -49,7 +50,7 @@ def func_arg_annotated(x: type): self.assertFalse(validator.need_validate_return_value) def test_function_has_ret_annotation(self): - def func_ret_annotated(x) -> type: + def func_ret_annotated(arg) -> type: pass validator = Validator(func_ret_annotated) @@ -57,7 +58,7 @@ def func_ret_annotated(x) -> type: self.assertTrue(validator.need_validate_return_value) def test_invalid_annotations_are_ignored(self): - def func_ignore_annotation(x: 1) -> (2,): + def func_ignore_annotation(arg: 1) -> (2,): pass validator = Validator(func_ignore_annotation) @@ -91,7 +92,7 @@ def test_invalid_return_value(self): ) def test_validate_arguments_without_annotations(self): - def func_no_annotation(x): + def func_no_annotation(arg): pass Validator(func_no_annotation).validate_arguments(1) @@ -103,7 +104,7 @@ def func_no_annotation(): Validator(func_no_annotation).validate_return_value(1) def test_validate_with_ignored_annotations(self): - def func_ignore_annotation(x: 1): + def func_ignore_annotation(arg: 1): pass Validator(func_ignore_annotation).validate_arguments(dict(x=1)) @@ -167,7 +168,7 @@ def func_has_required_arg(intarg: int): self.assertRaises(TypesafetyError, Validator(func_has_required_arg)) def test_skip_typesafety_check_for_function(self): - def skip_typesafety_check(x: int) -> int: + def skip_typesafety_check(arg: int) -> int: return "string" skip_typesafety_check.typesafety_skip = True @@ -178,7 +179,7 @@ def skip_typesafety_check(x: int) -> int: ) def test_validating_multiple_types(self): - def func(x: (str, int)): + def func(arg: (str, int)): pass validator = Validator(func) @@ -191,7 +192,7 @@ def func(x: (str, int)): self.assertIn("expected: (str, int)", str(error.exception)) def test_validating_multiple_types_or_none(self): - def func(x: (str, int, None)): + def func(arg: (str, int, None)): pass validator = Validator(func) diff --git a/typesafety/tests/version.py b/typesafety/tests/version.py index b847a76..5e47589 100644 --- a/typesafety/tests/version.py +++ b/typesafety/tests/version.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either diff --git a/typesafety/validator.py b/typesafety/validator.py index 389dddc..24e70cc 100644 --- a/typesafety/validator.py +++ b/typesafety/validator.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2016 BalaBit +# Copyright (c) 2013-2018 Balabit # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either