Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix how HEAD annotates inherited commit property
HEAD inherits its commit attribute from SymbolicReference, which defines it as a property using an explicit function call to `property`, rather than using it as a decorator. Due at least to python/mypy#16827, mypy has trouble with this. Currently that assignment in SymbolicReference is marked as type[ignore], which suppresses a type error (or something mypy regards as one) in the call itself. Even without that type comment, the type of the SymboilicReference instance attribute produced by the property is inferred as Any. This commit does not change that. This commit replaces the HEAD class's partially successful attempt to annotate `commit` as `self.commit` in `__init__` with a fully recognized annotation for `commit` in the class scope (which is interpreted as an instance attribute). Merely removing the annotation in `__init__` is sufficient to make the mypy error for it go away, but this causes the inferred type of `x.commit` when `x` is a `HEAD` instance to be inferred as Any rather than the desired specific type Commit. That is why this also adds an annotation to the class to achieve that without causing its own mypy error as the old one did. Once the SymbolicReference.commit property has a more specific static type, however that is to be achieved, there will be no need for the annotation added in the HEAD class body here. (This differs from the situation in 3aeef46 before this, where Diffable does not inherit any `repo` attribute--and is intended not to--and therefore had to introduce an annotation for it, for mypy to accept it.)
- Loading branch information