Skip to content

Commit 6fc820a

Browse files
committed
Merge remote-tracking branch 'upstream/master' into bugfix/gh-19839-paramspec-reveal-crash
2 parents be13a0e + 9250c1b commit 6fc820a

File tree

144 files changed

+9390
-624
lines changed

Some content is hidden

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

144 files changed

+9390
-624
lines changed

LICENSE

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,38 @@ FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
227227
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
228228
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
229229
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
230+
231+
= = = = =
232+
233+
Files under lib-rt/base64 are licensed under the following license.
234+
235+
= = = = =
236+
237+
Copyright (c) 2005-2007, Nick Galbreath
238+
Copyright (c) 2015-2018, Wojciech Muła
239+
Copyright (c) 2016-2017, Matthieu Darbois
240+
Copyright (c) 2013-2022, Alfred Klomp
241+
All rights reserved.
242+
243+
Redistribution and use in source and binary forms, with or without
244+
modification, are permitted provided that the following conditions are
245+
met:
246+
247+
- Redistributions of source code must retain the above copyright notice,
248+
this list of conditions and the following disclaimer.
249+
250+
- Redistributions in binary form must reproduce the above copyright
251+
notice, this list of conditions and the following disclaimer in the
252+
documentation and/or other materials provided with the distribution.
253+
254+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
255+
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
256+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
257+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
258+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
259+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
260+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
261+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
262+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
263+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
264+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

docs/source/command_line.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ format into the specified directory.
11591159
Enabling incomplete/experimental features
11601160
*****************************************
11611161

1162-
.. option:: --enable-incomplete-feature {PreciseTupleTypes,InlineTypedDict}
1162+
.. option:: --enable-incomplete-feature {PreciseTupleTypes,InlineTypedDict,TypeForm}
11631163

11641164
Some features may require several mypy releases to implement, for example
11651165
due to their complexity, potential for backwards incompatibility, or
@@ -1214,6 +1214,9 @@ List of currently incomplete/experimental features:
12141214
def test_values() -> {"width": int, "description": str}:
12151215
return {"width": 42, "description": "test"}
12161216
1217+
* ``TypeForm``: this feature enables ``TypeForm``, as described in
1218+
`PEP 747 – Annotating Type Forms <https://peps.python.org/pep-0747/>_`.
1219+
12171220

12181221
Miscellaneous
12191222
*************

docs/source/duck_type_compatibility.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ supported for a small set of built-in types:
99
* ``int`` is duck type compatible with ``float`` and ``complex``.
1010
* ``float`` is duck type compatible with ``complex``.
1111
* ``bytearray`` and ``memoryview`` are duck type compatible with ``bytes``.
12+
(this will be disabled by default in **mypy 2.0**, and currently can be
13+
disabled with :option:`--strict-bytes <mypy --strict-bytes>`.)
1214

1315
For example, mypy considers an ``int`` object to be valid whenever a
1416
``float`` object is expected. Thus code like this is nice and clean

mypy-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ typing_extensions>=4.6.0
44
mypy_extensions>=1.0.0
55
pathspec>=0.9.0
66
tomli>=1.1.0; python_version<'3.11'
7-
librt>=0.4.0
7+
librt>=0.6.2

mypy/build.py

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from librt.internal import cache_version
3232

3333
import mypy.semanal_main
34-
from mypy.cache import CACHE_VERSION, Buffer, CacheMeta
34+
from mypy.cache import CACHE_VERSION, CacheMeta, ReadBuffer, WriteBuffer
3535
from mypy.checker import TypeChecker
3636
from mypy.error_formatter import OUTPUT_CHOICES, ErrorFormatter
3737
from mypy.errors import CompileError, ErrorInfo, Errors, report_internal_error
@@ -603,6 +603,7 @@ def __init__(
603603
self.options = options
604604
self.version_id = version_id
605605
self.modules: dict[str, MypyFile] = {}
606+
self.import_map: dict[str, set[str]] = {}
606607
self.missing_modules: set[str] = set()
607608
self.fg_deps_meta: dict[str, FgDepMeta] = {}
608609
# fg_deps holds the dependencies of every module that has been
@@ -623,6 +624,7 @@ def __init__(
623624
self.incomplete_namespaces,
624625
self.errors,
625626
self.plugin,
627+
self.import_map,
626628
)
627629
self.all_types: dict[Expression, Type] = {} # Enabled by export_types
628630
self.indirection_detector = TypeIndirectionVisitor()
@@ -742,6 +744,26 @@ def getmtime(self, path: str) -> int:
742744
else:
743745
return int(self.metastore.getmtime(path))
744746

747+
def correct_rel_imp(self, file: MypyFile, imp: ImportFrom | ImportAll) -> str:
748+
"""Function to correct for relative imports."""
749+
file_id = file.fullname
750+
rel = imp.relative
751+
if rel == 0:
752+
return imp.id
753+
if os.path.basename(file.path).startswith("__init__."):
754+
rel -= 1
755+
if rel != 0:
756+
file_id = ".".join(file_id.split(".")[:-rel])
757+
new_id = file_id + "." + imp.id if imp.id else file_id
758+
759+
if not new_id:
760+
self.errors.set_file(file.path, file.name, self.options)
761+
self.errors.report(
762+
imp.line, 0, "No parent module -- cannot perform relative import", blocker=True
763+
)
764+
765+
return new_id
766+
745767
def all_imported_modules_in_file(self, file: MypyFile) -> list[tuple[int, str, int]]:
746768
"""Find all reachable import statements in a file.
747769
@@ -750,27 +772,6 @@ def all_imported_modules_in_file(self, file: MypyFile) -> list[tuple[int, str, i
750772
751773
Can generate blocking errors on bogus relative imports.
752774
"""
753-
754-
def correct_rel_imp(imp: ImportFrom | ImportAll) -> str:
755-
"""Function to correct for relative imports."""
756-
file_id = file.fullname
757-
rel = imp.relative
758-
if rel == 0:
759-
return imp.id
760-
if os.path.basename(file.path).startswith("__init__."):
761-
rel -= 1
762-
if rel != 0:
763-
file_id = ".".join(file_id.split(".")[:-rel])
764-
new_id = file_id + "." + imp.id if imp.id else file_id
765-
766-
if not new_id:
767-
self.errors.set_file(file.path, file.name, self.options)
768-
self.errors.report(
769-
imp.line, 0, "No parent module -- cannot perform relative import", blocker=True
770-
)
771-
772-
return new_id
773-
774775
res: list[tuple[int, str, int]] = []
775776
for imp in file.imports:
776777
if not imp.is_unreachable:
@@ -785,7 +786,7 @@ def correct_rel_imp(imp: ImportFrom | ImportAll) -> str:
785786
ancestors.append(part)
786787
res.append((ancestor_pri, ".".join(ancestors), imp.line))
787788
elif isinstance(imp, ImportFrom):
788-
cur_id = correct_rel_imp(imp)
789+
cur_id = self.correct_rel_imp(file, imp)
789790
all_are_submodules = True
790791
# Also add any imported names that are submodules.
791792
pri = import_priority(imp, PRI_MED)
@@ -805,7 +806,7 @@ def correct_rel_imp(imp: ImportFrom | ImportAll) -> str:
805806
res.append((pri, cur_id, imp.line))
806807
elif isinstance(imp, ImportAll):
807808
pri = import_priority(imp, PRI_HIGH)
808-
res.append((pri, correct_rel_imp(imp), imp.line))
809+
res.append((pri, self.correct_rel_imp(file, imp), imp.line))
809810

810811
# Sort such that module (e.g. foo.bar.baz) comes before its ancestors (e.g. foo
811812
# and foo.bar) so that, if FindModuleCache finds the target module in a
@@ -1342,7 +1343,7 @@ def find_cache_meta(id: str, path: str, manager: BuildManager) -> CacheMeta | No
13421343
if meta[0] != cache_version() or meta[1] != CACHE_VERSION:
13431344
manager.log(f"Metadata abandoned for {id}: incompatible cache format")
13441345
return None
1345-
data_io = Buffer(meta[2:])
1346+
data_io = ReadBuffer(meta[2:])
13461347
m = CacheMeta.read(data_io, data_file)
13471348
else:
13481349
m = CacheMeta.deserialize(meta, data_file)
@@ -1593,7 +1594,7 @@ def write_cache(
15931594

15941595
# Serialize data and analyze interface
15951596
if manager.options.fixed_format_cache:
1596-
data_io = Buffer()
1597+
data_io = WriteBuffer()
15971598
tree.write(data_io)
15981599
data_bytes = data_io.getvalue()
15991600
else:
@@ -1677,7 +1678,7 @@ def write_cache_meta(meta: CacheMeta, manager: BuildManager, meta_file: str) ->
16771678
# Write meta cache file
16781679
metastore = manager.metastore
16791680
if manager.options.fixed_format_cache:
1680-
data_io = Buffer()
1681+
data_io = WriteBuffer()
16811682
meta.write(data_io)
16821683
# Prefix with both low- and high-level cache format versions for future validation.
16831684
# TODO: switch to something like librt.internal.write_byte() if this is slow.
@@ -2110,7 +2111,7 @@ def load_tree(self, temporary: bool = False) -> None:
21102111
t0 = time.time()
21112112
# TODO: Assert data file wasn't changed.
21122113
if isinstance(data, bytes):
2113-
data_io = Buffer(data)
2114+
data_io = ReadBuffer(data)
21142115
self.tree = MypyFile.read(data_io)
21152116
else:
21162117
self.tree = MypyFile.deserialize(data)
@@ -2483,7 +2484,7 @@ def write_cache(self) -> tuple[CacheMeta, str] | None:
24832484
if self.options.debug_serialize:
24842485
try:
24852486
if self.manager.options.fixed_format_cache:
2486-
data = Buffer()
2487+
data = WriteBuffer()
24872488
self.tree.write(data)
24882489
else:
24892490
self.tree.serialize()
@@ -2898,6 +2899,9 @@ def dispatch(sources: list[BuildSource], manager: BuildManager, stdout: TextIO)
28982899
manager.cache_enabled = False
28992900
graph = load_graph(sources, manager)
29002901

2902+
for id in graph:
2903+
manager.import_map[id] = set(graph[id].dependencies + graph[id].suppressed)
2904+
29012905
t1 = time.time()
29022906
manager.add_stats(
29032907
graph_size=len(graph),

0 commit comments

Comments
 (0)