Passed
Push — master ( b94d48...186be2 )
by
unknown
02:40
created

tracim.lib.utils.utils.cmp_to_key()   B

Complexity

Conditions 1

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
cc 1
nop 1
1
# -*- coding: utf-8 -*-
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
import datetime
3
4
5
def cmp_to_key(mycmp):
6
    """
7
    List sort related function
8
9
    Convert a cmp= function into a key= function
10
    """
11
    class K(object):
0 ignored issues
show
Coding Style Naming introduced by
The name K does not conform to the class naming conventions ([A-Z_][a-zA-Z0-9]+$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
12
        def __init__(self, obj, *args):
0 ignored issues
show
Unused Code introduced by
The argument args seems to be unused.
Loading history...
13
            self.obj = obj
14
15
        def __lt__(self, other):
16
            return mycmp(self.obj, other.obj) < 0
17
18
        def __gt__(self, other):
19
            return mycmp(self.obj, other.obj) > 0
20
21
        def __eq__(self, other):
22
            return mycmp(self.obj, other.obj) == 0
23
24
        def __le__(self, other):
25
            return mycmp(self.obj, other.obj) <= 0
26
27
        def __ge__(self, other):
28
            return mycmp(self.obj, other.obj) >= 0
29
30
        def __ne__(self, other):
31
            return mycmp(self.obj, other.obj) != 0
32
33
    return K
34
35
36
def current_date_for_filename() -> str:
37
    """
38
    ISO8601 current date, adapted to be used in filename (for
39
    webdav feature for example), with trouble-free characters.
40
    :return: current date as string like "2018-03-19T15.49.27.246592"
41
    """
42
    # INFO - G.M - 19-03-2018 - As ':' is in transform_to_bdd method in
43
    # webdav utils, it may cause trouble. So, it should be replaced to
44
    # a character which will not change in bdd.
45
    return datetime.datetime.now().isoformat().replace(':', '.')
46