Completed
Push — master ( de4cac...2aedef )
by Philip
02:05 queued 39s
created

rename_keys()   A

Complexity

Conditions 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
1
from typing import Mapping
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...
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
4
def rename_keys(record: Mapping, key_map: Mapping) -> dict:
5
    """New record with same keys or renamed keys if key found in key_map."""
6
7
    new_record = dict()
8
9
    for k, v in record.items():
10
        key = key_map[k] if k in key_map else k
11
        new_record[key] = v
12
13
    return new_record
14
15
16
def replace_keys(record: Mapping, key_map: Mapping) -> dict:
17
    """New record with renamed keys including keys only found in key_map."""
18
19
    return {key_map[k]: v for k, v in record.items() if k in key_map}
20