From 78ebc552bb3b17ec00caa1fe5c27cc4ff07d707d Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Wed, 14 Feb 2024 15:51:30 +0100 Subject: [PATCH] Minor cleanup, Typing and removal Add typing to help static checker, removed unused private variables. --- lib/python/pyflyby/_idents.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/python/pyflyby/_idents.py b/lib/python/pyflyby/_idents.py index f1485b0f..7c1ca72f 100644 --- a/lib/python/pyflyby/_idents.py +++ b/lib/python/pyflyby/_idents.py @@ -10,6 +10,8 @@ from pyflyby._util import cached_attribute, cmp +from typing import Optional, Tuple, Dict + # Don't consider "print" a keyword, in order to be compatible with user code # that uses "from __future__ import print_function". @@ -45,12 +47,7 @@ def dotted_prefixes(dotted_name, reverse=False): return result -_name_re = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*$") -_dotted_name_re = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*([.][a-zA-Z_][a-zA-Z0-9_]*)*$") -_dotted_name_prefix_re = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*([.][a-zA-Z_][a-zA-Z0-9_]*)*[.]?$") - - -def is_identifier(s, dotted=False, prefix=False): +def is_identifier(s: str, dotted: bool = False, prefix: bool = False): """ Return whether ``s`` is a valid Python identifier name. @@ -139,7 +136,11 @@ class BadDottedIdentifierError(ValueError): # TODO: Use in various places, esp where e.g. dotted_prefixes is used. @total_ordering -class DottedIdentifier(object): +class DottedIdentifier: + name: str + parts: Tuple[str, ...] + scope_info: Optional[Dict] + def __new__(cls, arg, scope_info=None): if isinstance(arg, cls): return arg