From 90b7f824f2e760e6363b0d10c52b1940346a0fa6 Mon Sep 17 00:00:00 2001 From: David Bieber Date: Sun, 22 Sep 2024 09:14:50 -0700 Subject: [PATCH] Replace Python 2 type hints with real type annotations (#559) * Replace Python 2 type hints with real type annotations --- CONTRIBUTING.md | 3 --- fire/decorators.py | 7 +++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index baae1a6e..b5d67c96 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,12 +40,9 @@ In addition, the project follows a convention of: - Maximum line length: 80 characters - Indentation: 2 spaces (4 for line continuation) - PascalCase for function and method names. -- No type hints, as described in [PEP 484], to maintain compatibility with -Python versions < 3.5. - Single quotes around strings, three double quotes around docstrings. [Google Python Style Guide]: http://google.github.io/styleguide/pyguide.html -[PEP 484]: https://www.python.org/dev/peps/pep-0484 ## Testing diff --git a/fire/decorators.py b/fire/decorators.py index 2758b0aa..914b1de6 100644 --- a/fire/decorators.py +++ b/fire/decorators.py @@ -18,6 +18,7 @@ command line arguments to client code. """ +from typing import Any, Dict import inspect FIRE_METADATA = 'FIRE_METADATA' @@ -80,8 +81,7 @@ def _SetMetadata(fn, attribute, value): setattr(fn, FIRE_METADATA, metadata) -def GetMetadata(fn): - # type: (...) -> dict +def GetMetadata(fn) -> Dict[str, Any]: """Gets metadata attached to the function `fn` as an attribute. Args: @@ -104,8 +104,7 @@ def GetMetadata(fn): return default -def GetParseFns(fn): - # type: (...) -> dict +def GetParseFns(fn) -> Dict[str, Any]: metadata = GetMetadata(fn) default = {'default': None, 'positional': [], 'named': {}} return metadata.get(FIRE_PARSE_FNS, default)