Skip to content

Commit adbcbd4

Browse files
authored
Update contribution guidelines for type hints and imports
1 parent a248ba9 commit adbcbd4

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

.github/copilot-instructions.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
<https://github.com/PyThaiNLP/pythainlp/blob/dev/tests/README.md>.
77
The document list test categories, their dependency sets,
88
and test naming conventions.
9+
- [ ] Use reStructuredText for docstring (PEP 287), targetting Sphinx.
10+
- [ ] When possible, follow NLTK established convention of submodule
11+
name (tend to be a verb or a generic noun), function name, and
12+
configuration. Communicate this to the users during code review.
13+
See <https://www.nltk.org/py-modindex.html>.
914

1015
## Project contribution guidelines
1116

@@ -185,6 +190,21 @@
185190
file I/O, network I/O, etc.
186191
- [ ] Use type hints for function/method signatures
187192
and variable declarations as much as possible.
193+
- [ ] Follow best practices and standard Python type hint patterns.
194+
- [ ] Use mypy as an assistant.
195+
- [ ] mypy is in "dev" optional dependency.
196+
- [ ] Sometimes mypy may report errors wrongly due to cache issues.
197+
Try to reset the cache if unexpected errors occured.
198+
- [ ] Use pyright, pyrefly, and pytype for second opinions.
199+
- [ ] When insert typing imports, put it in appropriate location and order.
200+
Use "if TYPE_CHECKING import" block when possible.
201+
- [ ] Try to find type information for external libraries:
202+
- [ ] Check if type stub is available and install it.
203+
- [ ] Check if source code is available and analyze it for correct types.
204+
- [ ] Recheck necessity of casting.
205+
- [ ] Recheck necessity of `# noqa:` and `# type: ignore`.
206+
- [ ] Recheck docstring and documentation consistency with the code;
207+
They should match the updated type hints.
188208
- [ ] requires-python in pyproject.toml should reflect the minimum
189209
Python version supported by the project.
190210
- [ ] Do not introduce syntax or features that are not supported
@@ -196,8 +216,13 @@
196216
runtime type inspection tools, documentation generators, and static
197217
analysis tools.
198218
For example, typing.get_type_hints() should work properly.
219+
- [ ] Do not allow the use of assert in production code
220+
(it is only allowed for testing and debugging).
199221
- [ ] Do not use mutable default arguments in function/method definitions.
200222
- [ ] Do not use wildcard imports (from module import *).
223+
- [ ] When reordering the imports, be careful not to (re-)introduce circular
224+
import. Read comments near imports to get more information.
225+
- [ ] Remove unused imports.
201226
- [ ] Remove any trailing whitespace in the Python file.
202227
- [ ] Make the package zip-safe if possible.
203228
- [ ] Be mindful about choice of data structures.
@@ -208,6 +233,7 @@
208233
`collections.abc` modules.
209234
Use the most appropriate data structure for the specific use case
210235
to optimize performance and memory usage.
236+
- [ ] Recheck formatting with Ruff.
211237

212238
## JSON
213239

0 commit comments

Comments
 (0)