The Wayback Machine - https://web.archive.org/web/20220807050809/https://github.com/google/python-fire/commit/1c1f6dd1107034b9693c9a6e5ed417331e69bc31
Skip to content
Permalink
Browse files
Add type-checking to Python Fire via pytype.
PiperOrigin-RevId: 236693773
Change-Id: I8eb393b69283445b952780c288704e4b8e262628
  • Loading branch information
rchen152 authored and Copybara-Service committed Mar 4, 2019
1 parent 2363b5f commit 1c1f6dd1107034b9693c9a6e5ed417331e69bc31
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
@@ -98,3 +98,6 @@ ENV/

# PyCharm IDE
.idea/

# Type-checking
.pytype/
@@ -15,10 +15,19 @@ before_install:
- pip install --upgrade setuptools pip
- pip install --upgrade pylint pytest pytest-pylint pytest-runner
install:
- pip install hypothesis
- pip install hypothesis python-Levenshtein
- python setup.py develop
script:
- python -m pytest # Run the tests without IPython.
- pip install ipython
- python -m pytest # Now run the tests with IPython.
- pylint fire --ignore=test_components_py3.py,parser_fuzz_test.py,console
- pip install pytype
# Run type-checking, excluding files that define or use py3 features in py2.
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then
pytype -x
fire/fire_test.py
fire/inspectutils_test.py
fire/test_components_py3.py;
else
pytype; fi
@@ -487,7 +487,7 @@ def _Fire(component, args, context, name=None):
# If the component is a namedtuple, we need to convert it to dict to
# be able to use the .items() method.
if inspectutils.IsNamedTuple(component):
component = component._asdict()
component = component._asdict() # pytype: disable=attribute-error
for key, value in component.items():
if target == str(key):
component = value
@@ -82,7 +82,7 @@ class Namespace(dict):
def __getattr__(self, key):
if key not in self:
self[key] = Namespace()
return self.get(key)
return self[key]

def __setattr__(self, key, value):
self[key] = value
@@ -398,7 +398,7 @@ def _consume_line(line_info, state):
if state.section.new and state.section.format == Formats.RST:
# The current line starts with an RST directive, e.g. ":param arg:".
directive = _get_directive(line_info)
directive_tokens = directive.split()
directive_tokens = directive.split() # pytype: disable=attribute-error
if state.section.title == Sections.ARGS:
name = directive_tokens[-1]
arg = _get_or_create_arg_by_name(state, name)
@@ -65,7 +65,9 @@ def __init__(self, initial_component, name=None, separator='-', verbose=False,

def GetResult(self):
"""Returns the component from the last element of the trace."""
# pytype: disable=attribute-error
return self.GetLastHealthyElement().component
# pytype: enable=attribute-error

def GetLastHealthyElement(self):
"""Returns the last element of the trace that is not an error.
@@ -9,3 +9,7 @@ test = pytest

[tool:pytest]
addopts = --ignore=fire/test_components_py3.py --ignore=fire/parser_fuzz_test.py

[pytype]
inputs = .
output = .pytype

0 comments on commit 1c1f6dd

Please sign in to comment.