Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitefe5c5d

Browse files
Merge branch 'master' into output-json
2 parentsd27be7e +b5914b5 commitefe5c5d

File tree

87 files changed

+2452
-973
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+2452
-973
lines changed

‎.github/workflows/test.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ jobs:
9393
arch:x64
9494
os:windows-latest
9595
toxenv:type
96+
# We also run these checks with pre-commit in CI,
97+
# but it's useful to run them with tox too,
98+
# to ensure the tox env works as expected
9699
-name:Formatting with Black + isort and code style with flake8
97100
python:'3.7'
98101
arch:x64

‎.pre-commit-config.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ repos:
1414
additional_dependencies:
1515
-flake8-bugbear==22.12.6# must match test-requirements.txt
1616
-flake8-noqa==1.3.0# must match test-requirements.txt
17+
18+
ci:
19+
# We run flake8 as part of our GitHub Actions suite in CI
20+
skip:[flake8]

‎CONTRIBUTING.md‎

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,33 @@ issue tracker, pull requests, and chat, is expected to treat
1212
other people with respect and more generally to follow the guidelines
1313
articulated in the[Python Community Code of Conduct](https://www.python.org/psf/codeofconduct/).
1414

15-
1615
##Getting started with development
1716

1817
###Setup
1918

20-
####(1) Clone the mypy repository and enter into it
21-
```
22-
git clone https://github.com/python/mypy.git
19+
####(1) Fork the mypy repository
20+
21+
Within Github, navigate to<https://github.com/python/mypy> and fork the repository.
22+
23+
####(2) Clone the mypy repository and enter into it
24+
25+
```bash
26+
git clone git@github.com:<your_username>/mypy.git
2327
cd mypy
2428
```
2529

26-
####(2) Create then activate a virtual environment
27-
```
30+
####(3) Create then activate a virtual environment
31+
32+
```bash
2833
# On Windows, the commands may be slightly different. For more details, see
2934
# https://docs.python.org/3/library/venv.html#creating-virtual-environments
3035
python3 -m venv venv
3136
source venv/bin/activate
3237
```
3338

34-
####(3) Install the test requirements and the project
35-
```
39+
####(4) Install the test requirements and the project
40+
41+
```bash
3642
python3 -m pip install -r test-requirements.txt
3743
python3 -m pip install -e.
3844
hash -r# This resets shell PATH cache, not necessary on Windows
@@ -47,12 +53,14 @@ your PR.
4753

4854
However, if you wish to do so, you can run the full test suite
4955
like this:
50-
```
56+
57+
```bash
5158
python3 runtests.py
5259
```
5360

5461
You can also use`tox` to run tests (`tox` handles setting up the test environment for you):
55-
```
62+
63+
```bash
5664
tox run -e py
5765

5866
# Or some specific python version:
@@ -63,6 +71,7 @@ tox run -e lint
6371
```
6472

6573
Some useful commands for running specific tests include:
74+
6675
```bash
6776
# Use mypy to check mypy's own code
6877
python3 runtests.py self
@@ -90,6 +99,7 @@ see [the README in the test-data directory](test-data/unit/README.md).
9099
If you're looking for things to help with, browse our[issue tracker](https://github.com/python/mypy/issues)!
91100

92101
In particular, look for:
102+
93103
-[good first issues](https://github.com/python/mypy/labels/good-first-issue)
94104
-[good second issues](https://github.com/python/mypy/labels/good-second-issue)
95105
-[documentation issues](https://github.com/python/mypy/labels/documentation)
@@ -151,28 +161,27 @@ You may also find other pages in the
151161
[Mypy developer guide](https://github.com/python/mypy/wiki/Developer-Guides)
152162
helpful in developing your change.
153163

154-
155164
##Core developer guidelines
156165

157166
Core developers should follow these rules when processing pull requests:
158167

159-
* Always wait for tests to pass before merging PRs.
160-
* Use "[Squash and merge](https://github.com/blog/2141-squash-your-commits)"
168+
- Always wait for tests to pass before merging PRs.
169+
- Use "[Squash and merge](https://github.com/blog/2141-squash-your-commits)"
161170
to merge PRs.
162-
* Delete branches for merged PRs (by core devs pushing to the main repo).
163-
* Edit the final commit message before merging to conform to the following
171+
- Delete branches for merged PRs (by core devs pushing to the main repo).
172+
- Edit the final commit message before merging to conform to the following
164173
style (we wish to have a clean`git log` output):
165-
* When merging a multi-commit PR make sure that the commit message doesn't
174+
- When merging a multi-commit PR make sure that the commit message doesn't
166175
contain the local history from the committer and the review history from
167176
the PR. Edit the message to only describe the end state of the PR.
168-
* Make sure there is a*single* newline at the end of the commit message.
177+
- Make sure there is a*single* newline at the end of the commit message.
169178
This way there is a single empty line between commits in`git log`
170179
output.
171-
* Split lines as needed so that the maximum line length of the commit
180+
- Split lines as needed so that the maximum line length of the commit
172181
message is under 80 characters, including the subject line.
173-
* Capitalize the subject and each paragraph.
174-
* Make sure that the subject of the commit message has no trailing dot.
175-
* Use the imperative mood in the subject line (e.g. "Fix typo in README").
176-
* If the PR fixes an issue, make sure something like "Fixes #xxx." occurs
182+
- Capitalize the subject and each paragraph.
183+
- Make sure that the subject of the commit message has no trailing dot.
184+
- Use the imperative mood in the subject line (e.g. "Fix typo in README").
185+
- If the PR fixes an issue, make sure something like "Fixes #xxx." occurs
177186
in the body of the message (not in the subject).
178-
* Use Markdown for formatting.
187+
- Use Markdown for formatting.

‎README.md‎

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ To report a bug or request an enhancement:
4040
tracker for that library
4141

4242
To discuss a new type system feature:
43+
4344
- discuss at[typing-sig mailing list](https://mail.python.org/archives/list/typing-sig@python.org/)
4445
- there is also some historical discussion[here](https://github.com/python/typing/issues)
4546

46-
4747
What is mypy?
4848
-------------
4949

@@ -82,6 +82,7 @@ See [the documentation](https://mypy.readthedocs.io/en/stable/index.html) for
8282
more examples and information.
8383

8484
In particular, see:
85+
8586
-[type hints cheat sheet](https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html)
8687
-[getting started](https://mypy.readthedocs.io/en/stable/getting_started.html)
8788
-[list of error codes](https://mypy.readthedocs.io/en/stable/error_code_list.html)
@@ -91,67 +92,75 @@ Quick start
9192

9293
Mypy can be installed using pip:
9394

94-
python3 -m pip install -U mypy
95+
```bash
96+
python3 -m pip install -U mypy
97+
```
9598

9699
If you want to run the latest version of the code, you can install from the
97100
repo directly:
98101

99-
python3 -m pip install -U git+https://github.com/python/mypy.git
100-
# or if you don't have 'git' installed
101-
python3 -m pip install -U https://github.com/python/mypy/zipball/master
102+
```bash
103+
python3 -m pip install -U git+https://github.com/python/mypy.git
104+
# or if you don't have 'git' installed
105+
python3 -m pip install -U https://github.com/python/mypy/zipball/master
106+
```
102107

103108
Now you can type-check the[statically typed parts] of a program like this:
104109

105-
mypy PROGRAM
110+
```bash
111+
mypy PROGRAM
112+
```
106113

107114
You can always use the Python interpreter to run your statically typed
108115
programs, even if mypy reports type errors:
109116

110-
python3 PROGRAM
117+
```bash
118+
python3 PROGRAM
119+
```
111120

112121
You can also try mypy in an[online playground](https://mypy-play.net/) (developed by
113122
Yusuke Miyazaki). If you are working with large code bases, you can run mypy in
114123
[daemon mode], that will give much faster (often sub-second) incremental updates:
115124

116-
dmypy run -- PROGRAM
125+
```bash
126+
dmypy run -- PROGRAM
127+
```
117128

118129
[statically typed parts]:https://mypy.readthedocs.io/en/latest/getting_started.html#function-signatures-and-dynamic-vs-static-typing
119130
[daemon mode]:https://mypy.readthedocs.io/en/stable/mypy_daemon.html
120131

121-
122132
Integrations
123133
------------
124134

125135
Mypy can be integrated into popular IDEs:
126136

127-
* Vim:
128-
* Using[Syntastic](https://github.com/vim-syntastic/syntastic): in`~/.vimrc` add
137+
- Vim:
138+
- Using[Syntastic](https://github.com/vim-syntastic/syntastic): in`~/.vimrc` add
129139
`let g:syntastic_python_checkers=['mypy']`
130-
* Using[ALE](https://github.com/dense-analysis/ale): should be enabled by default when`mypy` is installed,
140+
- Using[ALE](https://github.com/dense-analysis/ale): should be enabled by default when`mypy` is installed,
131141
or can be explicitly enabled by adding`let b:ale_linters = ['mypy']` in`~/vim/ftplugin/python.vim`
132-
* Emacs: using[Flycheck](https://github.com/flycheck/)
133-
* Sublime Text:[SublimeLinter-contrib-mypy](https://github.com/fredcallaway/SublimeLinter-contrib-mypy)
134-
* Atom:[linter-mypy](https://atom.io/packages/linter-mypy)
135-
* PyCharm:[mypy plugin](https://github.com/dropbox/mypy-PyCharm-plugin) (PyCharm integrates
142+
- Emacs: using[Flycheck](https://github.com/flycheck/)
143+
- Sublime Text:[SublimeLinter-contrib-mypy](https://github.com/fredcallaway/SublimeLinter-contrib-mypy)
144+
- Atom:[linter-mypy](https://atom.io/packages/linter-mypy)
145+
- PyCharm:[mypy plugin](https://github.com/dropbox/mypy-PyCharm-plugin) (PyCharm integrates
136146
[its own implementation](https://www.jetbrains.com/help/pycharm/type-hinting-in-product.html) of[PEP 484](https://peps.python.org/pep-0484/))
137-
* VS Code: provides[basic integration](https://code.visualstudio.com/docs/python/linting#_mypy) with mypy.
138-
* pre-commit: use[pre-commit mirrors-mypy](https://github.com/pre-commit/mirrors-mypy).
147+
- VS Code: provides[basic integration](https://code.visualstudio.com/docs/python/linting#_mypy) with mypy.
148+
- pre-commit: use[pre-commit mirrors-mypy](https://github.com/pre-commit/mirrors-mypy).
139149

140150
Web site and documentation
141151
--------------------------
142152

143153
Additional information is available at the web site:
144154

145-
https://www.mypy-lang.org/
155+
<https://www.mypy-lang.org/>
146156

147157
Jump straight to the documentation:
148158

149-
https://mypy.readthedocs.io/
159+
<https://mypy.readthedocs.io/>
150160

151161
Follow along our changelog at:
152162

153-
https://mypy-lang.blogspot.com/
154-
163+
<https://mypy-lang.blogspot.com/>
155164

156165
Contributing
157166
------------
@@ -164,7 +173,6 @@ To get started with developing mypy, see [CONTRIBUTING.md](CONTRIBUTING.md).
164173

165174
If you need help getting started, don't hesitate to ask on[gitter](https://gitter.im/python/typing).
166175

167-
168176
Mypyc and compiled version of mypy
169177
----------------------------------
170178

@@ -174,10 +182,12 @@ mypy approximately 4 times faster than if interpreted!
174182

175183
To install an interpreted mypy instead, use:
176184

177-
python3 -m pip install --no-binary mypy -U mypy
185+
```bash
186+
python3 -m pip install --no-binary mypy -U mypy
187+
```
178188

179189
To use a compiled version of a development
180190
version of mypy, directly install a binary from
181-
https://github.com/mypyc/mypy_mypyc-wheels/releases/latest.
191+
<https://github.com/mypyc/mypy_mypyc-wheels/releases/latest>.
182192

183-
To contribute to the mypyc project, check outhttps://github.com/mypyc/mypyc
193+
To contribute to the mypyc project, check out<https://github.com/mypyc/mypyc>

‎mypy/applytype.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def apply_generic_arguments(
110110
nt=id_to_type.get(param_spec.id)
111111
ifntisnotNone:
112112
nt=get_proper_type(nt)
113-
ifisinstance(nt,CallableType)orisinstance(nt,Parameters):
113+
ifisinstance(nt,(CallableType,Parameters)):
114114
callable=callable.expand_param_spec(nt)
115115

116116
# Apply arguments to argument types.

‎mypy/build.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,8 @@ def parse_file(
840840
Raise CompileError if there is a parse error.
841841
"""
842842
t0=time.time()
843+
ifignore_errors:
844+
self.errors.ignored_files.add(path)
843845
tree=parse(source,path,id,self.errors,options=options)
844846
tree._fullname=id
845847
self.add_stats(
@@ -1916,7 +1918,7 @@ def __init__(
19161918
self.caller_state=caller_state
19171919
self.caller_line=caller_line
19181920
ifcaller_state:
1919-
self.import_context=caller_state.import_context[:]
1921+
self.import_context=caller_state.import_context.copy()
19201922
self.import_context.append((caller_state.xpath,caller_line))
19211923
else:
19221924
self.import_context= []

‎mypy/checker.py‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,7 +2724,7 @@ def check_assignment(
27242724
new_syntax:bool=False,
27252725
)->None:
27262726
"""Type check a single assignment: lvalue = rvalue."""
2727-
ifisinstance(lvalue,TupleExpr)orisinstance(lvalue,ListExpr):
2727+
ifisinstance(lvalue,(TupleExpr,ListExpr)):
27282728
self.check_assignment_to_multiple_lvalues(
27292729
lvalue.items,rvalue,rvalue,infer_lvalue_type
27302730
)
@@ -3301,7 +3301,7 @@ def check_assignment_to_multiple_lvalues(
33013301
context:Context,
33023302
infer_lvalue_type:bool=True,
33033303
)->None:
3304-
ifisinstance(rvalue,TupleExpr)orisinstance(rvalue,ListExpr):
3304+
ifisinstance(rvalue,(TupleExpr,ListExpr)):
33053305
# Recursively go into Tuple or List expression rhs instead of
33063306
# using the type of rhs, because this allowed more fine grained
33073307
# control in cases like: a, b = [int, str] where rhs would get
@@ -3689,7 +3689,7 @@ def check_lvalue(self, lvalue: Lvalue) -> tuple[Type | None, IndexExpr | None, V
36893689
elifisinstance(lvalue,NameExpr):
36903690
lvalue_type=self.expr_checker.analyze_ref_expr(lvalue,lvalue=True)
36913691
self.store_type(lvalue,lvalue_type)
3692-
elifisinstance(lvalue,TupleExpr)orisinstance(lvalue,ListExpr):
3692+
elifisinstance(lvalue,(TupleExpr,ListExpr)):
36933693
types= [
36943694
self.check_lvalue(sub_expr)[0]or
36953695
# This type will be used as a context for further inference of rvalue,
@@ -5063,7 +5063,7 @@ def partition_by_callable(
50635063
"""
50645064
typ=get_proper_type(typ)
50655065

5066-
ifisinstance(typ,FunctionLike)orisinstance(typ,TypeType):
5066+
ifisinstance(typ,(FunctionLike,TypeType)):
50675067
return [typ], []
50685068

50695069
ifisinstance(typ,AnyType):
@@ -5835,7 +5835,14 @@ def refine_identity_comparison_expression(
58355835
"""
58365836
should_coerce=True
58375837
ifcoerce_only_in_literal_context:
5838-
should_coerce=any(is_literal_type_like(operand_types[i])foriinchain_indices)
5838+
5839+
defshould_coerce_inner(typ:Type)->bool:
5840+
typ=get_proper_type(typ)
5841+
returnis_literal_type_like(typ)or (
5842+
isinstance(typ,Instance)andtyp.type.is_enum
5843+
)
5844+
5845+
should_coerce=any(should_coerce_inner(operand_types[i])foriinchain_indices)
58395846

58405847
target:Type|None=None
58415848
possible_target_indices= []
@@ -6988,7 +6995,7 @@ def convert_to_typetype(type_map: TypeMap) -> TypeMap:
69886995

69896996
defflatten(t:Expression)->list[Expression]:
69906997
"""Flatten a nested sequence of tuples/lists into one list of nodes."""
6991-
ifisinstance(t,TupleExpr)orisinstance(t,ListExpr):
6998+
ifisinstance(t,(TupleExpr,ListExpr)):
69926999
return [bforaint.itemsforbinflatten(a)]
69937000
elifisinstance(t,StarExpr):
69947001
returnflatten(t.expr)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp