Skip to content

Commit 0f86323

Browse files
authored
lint: ignore class self annotations (#8492)
## Description Ignore `self` annotations for class methods. Typing them require `typing-extensions` to use the `Self` type, which is redundant and does not provide new information. Otherwise, the class name is not available when defining methods since it hasn't finished defining, so it requires further hacks to annotate. Furthermore, [PEP 673](https://peps.python.org/pep-0673) has made self type annotations unnecessary, but is only available on Python 3.11+. ## Checklist - [ ] I have followed [Sample Guidelines from AUTHORING_GUIDE.MD](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md) - [ ] README is updated to include [all relevant information](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#readme-file) - [ ] **Tests** pass: `nox -s py-3.9` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] **Lint** pass: `nox -s lint` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] These samples need a new **API enabled** in testing projects to pass (let us know which ones) - [ ] These samples need a new/updated **env vars** in testing projects set to pass (let us know which ones) - [ ] Please **merge** this PR for me once it is approved. - [ ] This sample adds a new sample directory, and I updated the [CODEOWNERS file](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/.github/CODEOWNERS) with the codeowners for this sample
1 parent fe5fdb1 commit 0f86323

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

noxfile-template.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def _determine_local_import_names(start_dir: str) -> List[str]:
124124
# Linting with flake8.
125125
#
126126
# We ignore the following rules:
127+
# ANN101: missing type annotation for self in method
127128
# E203: whitespace before ‘:’
128129
# E266: too many leading ‘#’ for block comment
129130
# E501: line too long
@@ -137,7 +138,7 @@ def _determine_local_import_names(start_dir: str) -> List[str]:
137138
"--max-complexity=20",
138139
"--import-order-style=google",
139140
"--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py",
140-
"--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202",
141+
"--ignore=ANN101,E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202",
141142
"--max-line-length=88",
142143
]
143144

0 commit comments

Comments
 (0)