Passed
Push — master ( 3b28a5...96ddc7 )
by Swen
02:25
created

resolve_object_property()   A

Complexity

Conditions 2

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
ccs 5
cts 5
cp 1
rs 9.3142
cc 2
crap 2
1 1
from typing import List
0 ignored issues
show
Configuration introduced by
The import typing could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
2
3 1
from django.conf import settings
0 ignored issues
show
Configuration introduced by
The import django.conf could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
4
5
6 1
def get_language_codes() -> List[str]:
7
    """Gets a list of all available language codes.
8
9
    This looks at your project's settings.LANGUAGES
10
    and returns a flat list of the configured
11
    language codes.
12
13
    Arguments:
14
        A flat list of all availble language codes
15
        in your project.
16
    """
17
18 1
    return [
19
        lang_code
20
        for lang_code, _ in settings.LANGUAGES
21
    ]
22
23
24 1
def resolve_object_property(obj, path: str):
25
    """Resolves the value of a property on an object.
26
27
    Is able to resolve nested properties. For example,
28
    a path can be specified:
29
30
        'other.beer.name'
31
32
    Raises:
33
        AttributeError:
34
            In case the property could not be resolved.
35
36
    Returns:
37
        The value of the specified property.
38
    """
39
40 1
    value = obj
41 1
    for path_part in path.split('.'):
42 1
        value = getattr(value, path_part)
43
44
    return value
45