Skip to content

Commit 8449619

Browse files
authored
Use ty in place of pytype (#617)
* Use ty in place of pytype
1 parent d33056c commit 8449619

17 files changed

+51
-58
lines changed

.github/scripts/build.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ python -m pytest # Run the tests without IPython.
2424
pip install ipython
2525
python -m pytest # Now run the tests with IPython.
2626
pylint fire --ignore=test_components_py3.py,parser_fuzz_test.py,console
27-
if [[ ${PYTHON_VERSION} == 3.7 ]]; then
28-
# Run type-checking.
29-
pip install pytype;
30-
pytype -x fire/test_components_py3.py;
27+
if [[ ${PYTHON_VERSION} == 3.12 ]]; then
28+
# Run type-checking
29+
pip install ty
30+
python -m ty check --python $(which python) --exclude fire/test_components_py3.py --exclude fire/console/ --exclude fire/formatting_windows.py
3131
fi

fire/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ def import_from_file_path(path):
6060

6161
spec = util.spec_from_file_location(module_name, path)
6262

63-
if spec is None:
63+
if spec is None or spec.loader is None:
6464
raise OSError('Unable to load module from specified path.')
6565

6666
module = util.module_from_spec(spec) # pylint: disable=no-member
67-
spec.loader.exec_module(module) # pytype: disable=attribute-error
67+
spec.loader.exec_module(module)
6868

6969
return module, module_name
7070

fire/console/console_attr_os.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
# limitations under the License.
1515

1616
"""OS specific console_attr helper functions."""
17-
# This file contains platform specific code which is not currently handled
18-
# by pytype.
19-
# pytype: skip-file
2017

2118
from __future__ import absolute_import
2219
from __future__ import division
@@ -73,7 +70,7 @@ def _GetXY(fd):
7370
try:
7471
# This magic incantation converts a struct from ioctl(2) containing two
7572
# binary shorts to a (rows, columns) int tuple.
76-
rc = struct.unpack(b'hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, 'junk'))
73+
rc = struct.unpack(b'hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, b'junk'))
7774
return (rc[1], rc[0]) if rc else None
7875
except: # pylint: disable=bare-except
7976
return None

fire/console/encoding.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ def Decode(data, encoding=None):
6767

6868
try:
6969
# Just return the string if its pure ASCII.
70-
return string.decode('ascii') # pytype: disable=attribute-error
70+
return string.decode('ascii')
7171
except UnicodeError:
7272
# The string is not ASCII encoded.
7373
pass
7474

7575
# Try the suggested encoding if specified.
7676
if encoding:
7777
try:
78-
return string.decode(encoding) # pytype: disable=attribute-error
78+
return string.decode(encoding)
7979
except UnicodeError:
8080
# Bad suggestion.
8181
pass
@@ -84,21 +84,21 @@ def Decode(data, encoding=None):
8484
# be exceptional if a valid extended ascii encoding with extended chars
8585
# were also a valid UITF-8 encoding.
8686
try:
87-
return string.decode('utf8') # pytype: disable=attribute-error
87+
return string.decode('utf8')
8888
except UnicodeError:
8989
# Not a UTF-8 encoding.
9090
pass
9191

9292
# Try the filesystem encoding.
9393
try:
94-
return string.decode(sys.getfilesystemencoding()) # pytype: disable=attribute-error
94+
return string.decode(sys.getfilesystemencoding())
9595
except UnicodeError:
9696
# string is not encoded for filesystem paths.
9797
pass
9898

9999
# Try the system default encoding.
100100
try:
101-
return string.decode(sys.getdefaultencoding()) # pytype: disable=attribute-error
101+
return string.decode(sys.getdefaultencoding())
102102
except UnicodeError:
103103
# string is not encoded using the default encoding.
104104
pass
@@ -118,7 +118,7 @@ def Decode(data, encoding=None):
118118
# string = '\xdc'
119119
# string = string.decode('iso-8859-1')
120120
# string = string.encode('ascii', 'backslashreplace')
121-
return string.decode('iso-8859-1') # pytype: disable=attribute-error
121+
return string.decode('iso-8859-1')
122122

123123

124124
def GetEncodedValue(env, name, default=None):

fire/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ def _Fire(component, args, parsed_flag_args, context, name=None):
504504

505505
# Treat namedtuples as dicts when handling them as a map.
506506
if inspectutils.IsNamedTuple(component):
507-
component_dict = component._asdict() # pytype: disable=attribute-error
507+
component_dict = component._asdict()
508508
else:
509509
component_dict = component
510510

@@ -519,7 +519,7 @@ def _Fire(component, args, parsed_flag_args, context, name=None):
519519
# a key as another type.
520520
# TODO(dbieber): Consider alternatives for accessing non-string keys.
521521
for key, value in (
522-
component_dict.items()): # pytype: disable=attribute-error
522+
component_dict.items()):
523523
if target == str(key):
524524
component = value
525525
handled = True

fire/core_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,12 @@ def serialize(x):
215215

216216
def testLruCacheDecoratorBoundArg(self):
217217
self.assertEqual(
218-
core.Fire(tc.py3.LruCacheDecoratedMethod, # pytype: disable=module-attr
218+
core.Fire(tc.py3.LruCacheDecoratedMethod,
219219
command=['lru_cache_in_class', 'foo']), 'foo')
220220

221221
def testLruCacheDecorator(self):
222222
self.assertEqual(
223-
core.Fire(tc.py3.lru_cache_decorated, # pytype: disable=module-attr
223+
core.Fire(tc.py3.lru_cache_decorated,
224224
command=['foo']), 'foo')
225225

226226

fire/custom_descriptions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ def GetStringTypeDescription(obj, available_space, line_length):
131131
def GetSummary(obj, available_space, line_length):
132132
obj_type_name = type(obj).__name__
133133
if obj_type_name in CUSTOM_DESC_SUM_FN_DICT:
134-
return CUSTOM_DESC_SUM_FN_DICT.get(obj_type_name)[0](obj, available_space,
135-
line_length)
134+
return CUSTOM_DESC_SUM_FN_DICT[obj_type_name][0](obj, available_space,
135+
line_length)
136136
return None
137137

138138

139139
def GetDescription(obj, available_space, line_length):
140140
obj_type_name = type(obj).__name__
141141
if obj_type_name in CUSTOM_DESC_SUM_FN_DICT:
142-
return CUSTOM_DESC_SUM_FN_DICT.get(obj_type_name)[1](obj, available_space,
143-
line_length)
142+
return CUSTOM_DESC_SUM_FN_DICT[obj_type_name][1](obj, available_space,
143+
line_length)
144144
return None

fire/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def SetParseFns(*positional, **named):
6868
def _Decorator(fn):
6969
parse_fns = GetParseFns(fn)
7070
parse_fns['positional'] = positional
71-
parse_fns['named'].update(named) # pytype: disable=attribute-error
71+
parse_fns['named'].update(named)
7272
_SetMetadata(fn, FIRE_PARSE_FNS, parse_fns)
7373
return fn
7474

fire/docstrings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def _consume_line(line_info, state):
436436
if state.section.new and state.section.format == Formats.RST:
437437
# The current line starts with an RST directive, e.g. ":param arg:".
438438
directive = _get_directive(line_info)
439-
directive_tokens = directive.split() # pytype: disable=attribute-error
439+
directive_tokens = directive.split()
440440
if state.section.title == Sections.ARGS:
441441
name = directive_tokens[-1]
442442
arg = _get_or_create_arg_by_name(

fire/formatting_windows.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import sys
2222

2323
try:
24-
import colorama # pylint: disable=g-import-not-at-top, # pytype: disable=import-error
24+
import colorama # pylint: disable=g-import-not-at-top
2525
HAS_COLORAMA = True
2626
except ImportError:
2727
HAS_COLORAMA = False
@@ -38,9 +38,9 @@ def initialize_or_disable():
3838
# Windows 10, 2016, and 2019 only.
3939

4040
wrap = False
41-
kernel32 = ctypes.windll.kernel32 # pytype: disable=module-attr
41+
kernel32 = ctypes.windll.kernel32
4242
enable_virtual_terminal_processing = 0x04
43-
out_handle = kernel32.GetStdHandle(subprocess.STD_OUTPUT_HANDLE) # pylint: disable=line-too-long, # pytype: disable=module-attr
43+
out_handle = kernel32.GetStdHandle(subprocess.STD_OUTPUT_HANDLE) # pylint: disable=line-too-long,
4444
# GetConsoleMode fails if the terminal isn't native.
4545
mode = ctypes.wintypes.DWORD()
4646
if kernel32.GetConsoleMode(out_handle, ctypes.byref(mode)) == 0:

0 commit comments

Comments
 (0)