8000 Even more cleanups. · matplotlib/matplotlib@cfd2cdb · GitHub
[go: up one dir, main page]

Skip to content

Commit cfd2cdb

Browse files
committed
Even more cleanups.
1 parent ab524d9 commit cfd2cdb

File tree

6 files changed

+20
-41
lines changed

6 files changed

+20
-41
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
18151815
"are in kwargs".format(keys=fail_keys))
18161816

18171817
if allowed is not None:
1818-
allowed_set = set(required) | set(allowed)
1818+
allowed_set = {*required, *allowed}
18191819
fail_keys = [k for k in ret if k not in allowed_set]
18201820
if fail_keys:
18211821
raise TypeError(

lib/matplotlib/mathtext.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ def get_unicode_index(symbol, math=True):
6565
# length, usually longer than a hyphen.
6666
if symbol == '-':
6767
return 0x2212
68-
try:# This will succeed if symbol is a single unicode char
68+
try: # This will succeed if symbol is a single unicode char
6969
return ord(symbol)
7070
except TypeError:
7171
pass
72-
try:# Is symbol a TeX symbol (i.e. \alpha)
72+
try: # Is symbol a TeX symbol (i.e. \alpha)
7373
return tex2uni[symbol.strip("\\")]
7474
except KeyError:
75-
message = """'%(symbol)s' is not a valid Unicode character or
76-
TeX/Type1 symbol"""%locals()
77-
raise ValueError(message)
75+
raise ValueError(
76+
"'{}' is not a valid Unicode character or TeX/Type1 symbol"
77+
.format(symbol))
7878

7979

8080
unichr_safe = cbook.deprecated("3.0")(chr)

lib/matplotlib/rcsetup.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __call__(self, s):
6363
s = s.lower()
6464
if s in self.valid:
6565
return self.valid[s]
66-
raise ValueError('Unrecognized %s string "%s": valid strings are %s'
66+
raise ValueError('Unrecognized %s string %r: valid strings are %s'
6767
% (self.key, s, list(six.itervalues(self.valid))))
6868

6969

@@ -935,25 +935,13 @@ def _validate_linestyle(ls):
935935
A validator for all possible line styles, the named ones *and*
936936
the on-off ink sequences.
937937
"""
938-
# Look first for a valid named line style, like '--' or 'solid'
939-
if isinstance(ls, six.string_types):
940-
try:
941-
return _validate_named_linestyle(ls)
942-
except (UnicodeDecodeError, KeyError):
943-
# On Python 2, string-like *ls*, like for example
944-
# 'solid'.encode('utf-16'), may raise a unicode error.
945-
raise ValueError("the linestyle string {!r} is not a valid "
946-
"string.".format(ls))
947-
948-
if isinstance(ls, (bytes, bytearray)):
949-
# On Python 2, a string-like *ls* should already have lead to a
950-
# successful return or to raising an exception. On Python 3, we have
951-
# to manually raise an exception in the case of a byte-like *ls*.
952-
# Otherwise, if *ls* is of even-length, it will be passed to the
953-
# instance of validate_nseq_float, which will return an absurd on-off
954-
# ink sequence...
955-
raise ValueError("linestyle {!r} neither looks like an on-off ink "
956-
"sequence nor a valid string.".format(ls))
938+
# Look first for a valid named line style, like '--' or 'solid' Also
939+
# includes bytes(-arrays) here (they all fail _validate_named_linestyle);
940+
# otherwise, if *ls* is of even-length, it will be passed to the instance
941+
# of validate_nseq_float, which will return an absurd on-off ink
942+
# sequence...
943+
if isinstance(ls, (str, bytes, bytearray)):
944+
return _validate_named_linestyle(ls)
957945

958946
# Look for an on-off ink sequence (in points) *of even length*.
959947
# Offset is set to None.

lib/matplotlib/widgets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ def on_text_change(self, func):
917917

918918
def on_submit(self, func):
919919
"""
920-
When the user hits enter or leaves the submision box, call this
920+
When the user hits enter or leaves the submission box, call this
921921
*func* with event.
922922
923923
A connection id is returned which can be used to disconnect.
@@ -928,8 +928,8 @@ def on_submit(self, func):
928928
return cid
929929

930930
def disconnect(self, cid):
931-
"""remove the observer with connection id *cid*"""
932-
for reg in (self.change_observers, self.submit_observers):
931+
"""Remove the observer with connection id *cid*."""
932+
for reg in [self.change_observers, self.submit_observers]:
933933
try:
934934
del reg[cid]
935935
except KeyError:

setupext.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,7 @@ def __init__(self):
284284
if sys.platform == 'win32':
285285
self.has_pkgconfig = False
286286
else:
287-
try:
288-
self.pkg_config = os.environ['PKG_CONFIG']
289-
except KeyError:
290-
self.pkg_config = 'pkg-config'
291-
287+
self.pkg_config = os.environ.get('PKG_CONFIG', 'pkg-config')
292288
self.set_pkgconfig_path()
293289
self.has_pkgconfig = shutil.which(self.pkg_config) is not None
294290
if not self.has_pkgconfig:

tools/gh_api.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
"""Functions for Github API requests."""
22

3-
try:
4-
input = raw_input
5-
except NameError:
6-
pass
7-
3+
import getpass
4+
import json
85
import os
96
import re
107
import sys
118

129
import requests
13-
import getpass
14-
import json
1510

1611
try:
1712
import requests_cache

0 commit comments

Comments
 (0)
0