Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix incorrect type hints + refactor for impoved consistency #2304

Closed
wants to merge 10 commits into from

Commits on Feb 16, 2024

  1. fix(wip): incorrect type hints for optional params/attributes

    Commit was automated using this powerful one-liner:
    
    `find . -type f -name "*.py" -print0 | xargs -0 perl -i -pe \
    	's/([a-zA-Z_]+): (?!(Optional\[|Any\]))([a-zA-Z_]+) = None/\1: Optional[\3] = None/g'`
    
    Which modifies variable annotations initialized with None to use Optional[Type],
    except when the type is already annotated as Optional[Type] or Any
    
    After executing the command, I manually updated modules that didn't
    already import Optional.
    
    issue: 2303
    danphenderson committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    42afbd7 View commit details
    Browse the repository at this point in the history
  2. chore(wip): update Union[Type, None] to Optional[Type]

    Changes where automated with this perl one-liner:
    
    `perl -pi -e 's/Union\[\s*(\w+)\s*,\s*None\s*\]/Optional[$1]/g' \
     $(find . -type f -name '*.py')`
    
    WIP, still need to address the case where the union specifies more
    than two different types.
    
    issue: 2303
    danphenderson committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    4af9951 View commit details
    Browse the repository at this point in the history
  3. chore: accessing typing module consistently

    Changes with created with this perl command:
    
    `perl -pi -e 's/typing\.//g' $(find . -type f -name '*.py')`
    
    Which removes all instances of '.typing'. I manually had to update
    the imports.
    
    WIP: care should be taken to test that 'generate_api.py' and
    'documentation_provider.py' scripts are working properly.
    
    issue: 2303
    danphenderson committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    dcc5d7e View commit details
    Browse the repository at this point in the history
  4. fix(wip): incorrect optional type hints

    Changes made with perl command:
    
    `perl -pi -e 's/: Dict\[(.*?)\] = None/: Optional[Dict[$1]] = None/g'
    $(find . -type f -name '*.py')`
    
    Which replaces ': Dict[..., ...] = None' with ': Optional[Dict[..., ...]] = None', where '...' can be any type.
    
    issue: 2303
    danphenderson committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    728d3ea View commit details
    Browse the repository at this point in the history
  5. fix(wip): incorrect optional type hints

    Changes made with perl command:
    
    `perl -pi -e 's/: Literal\[(.*?)\] = None/: Optional[Literal[$1]] = None/g'
        $(find . -type f -name '*.py')`
    
    Which replaces ': Literal[..., ...] = None' with ': Optional[Literal[..., ...]] = None', where '...' can be any type.
    
    issue: 2303
    danphenderson committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    09f138e View commit details
    Browse the repository at this point in the history
  6. fix(wip): incorrect optional type hints

    Changes made with a perl command (see 09f138e, 728d3ea)
    with manual intervention to fix unintended modifications.
    
    ': Sequence[...] = None' has been corrected to ':
    Optional[Sequence[...]] = None'.
    
    issue: 2303
    danphenderson committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    b642750 View commit details
    Browse the repository at this point in the history
  7. fix: incorrect type hints

    Changes made with the perl command:
    
    find . -type f -name '*.py' -exec perl -i -pe \
    	's/(\s*)(\w+): Union\[(.*?)\] = None,/$1$2: Optional[Union[$3]] = None,/g' {} +
    
    Which replaces instances of '<param>: Union[...] = None,' with '<param>: Optional[Union[...]] = None,'
    Note, this does not modify incorrect class attributes of this form (they
    don't end with a ',').
    
    issue: 2303
    danphenderson committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    f790c80 View commit details
    Browse the repository at this point in the history
  8. chore: consistent decleration of optional params

    Changes made with the perl command:
    
    find . -type f -name '*.py' -exec perl -i -pe \
    	's/Union\[((?:(?![,]).)*), None\]/Optional[$1]/g' {} +
    
    Which replaces Union type hints with a single 'TYPE' followed by 'None'
    are replaced with 'Optional[<TYPE>]'.
    
    issue: 2303
    danphenderson committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    99dcd81 View commit details
    Browse the repository at this point in the history
  9. fix: incorrect optional type hints

    Changes made with shell command:
    
    `perl -pi -e 's/: Callable\[(.*?)\] = None/: Optional[Callable[$1]] = None/g' $(find . -type f -name '*.py')`
    
    Which replaces ': Callable[...] = None' with ': Optional[Callable[...]] = None', where '...' can be any type.
    
    issue: 2303
    danphenderson committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    52bc2fa View commit details
    Browse the repository at this point in the history
  10. Merge branch 'main' into 2303-fix-type-hints

    danphenderson committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    db25da2 View commit details
    Browse the repository at this point in the history