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

Revise type annotations slightly #1860

Merged
merged 3 commits into from
Mar 5, 2024

Commits on Mar 5, 2024

  1. Remove unneeded annotation on __slots__ variable

    The correct type is inferred, and no other __slots__ variable in
    the codebase has an annotation.
    EliahKagan committed Mar 5, 2024
    Configuration menu
    Copy the full SHA
    9f226fc View commit details
    Browse the repository at this point in the history
  2. Fix some underindented portions of docstrings

    A few docstrings had parts that were meant to be indented the
    usual four spaces beyond the surrounding indentation, but were
    indented only three spaces beyond it instead.
    EliahKagan committed Mar 5, 2024
    Configuration menu
    Copy the full SHA
    e984bfe View commit details
    Browse the repository at this point in the history
  3. Add return-type annotation on __init__ methods

    Although sometimes found unintuitive, the reutrn type of a class's
    __init__ method is best annotated as None, as in other functions
    that return implicitly or by operand-less return statements.
    
    Note that this is only a minor improvement, effectively just a
    style fix, because mypy treats __init__ specially and, *when at
    least one parameter is annotated*, its return type is implicitly
    None rather than implicitly Any like other functions. All the
    __init__ methods modified here did already have one or more
    annotated parameters.
    
    However, having __init__ methods without the return type makes it
    easier to introduce a bug where an __init__ method with no
    parameters besides self -- which itself should almost always be
    unannotated and is properly inferred -- is written and the return
    annotation needed to get mypy to regard it as statically typed,
    so it checks it at all, is omitted. (It is also inelegant when
    one considers the meaning of __init__ and the distinction between
    it and __new__.)
    
    This commit does not add any return type annotations to functions
    in the test suite, since the test suite doesn't currently use
    static typing.
    
    Further reading:
    
    - https://peps.python.org/pep-0484/#the-meaning-of-annotations
    - python/mypy#604
    - gitpython-developers#1755 (comment)
    EliahKagan committed Mar 5, 2024
    Configuration menu
    Copy the full SHA
    5d7e55b View commit details
    Browse the repository at this point in the history