Skip to content

Commit 9b2ad15

Browse files
Use direct references to std. library configparser objects
1 parent 069b58a commit 9b2ad15

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

theano/configparser.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
import configparser as ConfigParser
21
import hashlib
32
import logging
43
import os
54
import shlex
65
import sys
76
import typing
87
import warnings
8+
from configparser import (
9+
ConfigParser,
10+
InterpolationError,
11+
NoOptionError,
12+
NoSectionError,
13+
RawConfigParser,
14+
)
915
from functools import wraps
1016
from io import StringIO
1117

@@ -195,9 +201,9 @@ def fetch_val_for_key(self, key, delete_key=False):
195201
try:
196202
try:
197203
return self._theano_cfg.get(section, option)
198-
except ConfigParser.InterpolationError:
204+
except InterpolationError:
199205
return self._theano_raw_cfg.get(section, option)
200-
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
206+
except (NoOptionError, NoSectionError):
201207
raise KeyError(key)
202208

203209
def change_flags(self, *args, **kwargs) -> _ChangeFlagsDecorator:
@@ -494,7 +500,7 @@ def _create_default_config():
494500
THEANO_FLAGS_DICT = parse_config_string(THEANO_FLAGS, issue_warnings=True)
495501

496502
config_files = config_files_from_theanorc()
497-
theano_cfg = ConfigParser.ConfigParser(
503+
theano_cfg = ConfigParser(
498504
{
499505
"USER": os.getenv("USER", os.path.split(os.path.expanduser("~"))[-1]),
500506
"LSCRATCH": os.getenv("LSCRATCH", ""),
@@ -508,7 +514,7 @@ def _create_default_config():
508514
# Having a raw version of the config around as well enables us to pass
509515
# through config values that contain format strings.
510516
# The time required to parse the config twice is negligible.
511-
theano_raw_cfg = ConfigParser.RawConfigParser()
517+
theano_raw_cfg = RawConfigParser()
512518
theano_raw_cfg.read(config_files)
513519

514520
# Instances of TheanoConfigParser can have independent current values!

0 commit comments

Comments
 (0)