Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Type checkers that we test our stubs against. These should always
# be pinned to a specific version to make failure reproducible.
mypy==1.15.0
mypy==1.16.0
pyright==1.1.400
# pytype can be installed on Windows, but requires building wheels, let's not do that on the CI
pytype==2024.10.11; platform_system != "Windows" and python_version >= "3.10" and python_version < "3.13"
Expand Down
8 changes: 8 additions & 0 deletions stdlib/@tests/stubtest_allowlists/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ _?ast.stmt.__init__

_ast.ImportFrom.level # None on the class, but never None on instances

argparse.Namespace.__setattr__ # should allow setting any attribute

ast.ImportFrom.level # None on the class, but never None on instances
ast.NodeVisitor.visit_\w+ # Methods are discovered dynamically, see #3796
_?asyncio.Future.__init__ # Usually initialized from c object
Expand Down Expand Up @@ -272,7 +274,9 @@ _?ctypes.Array._length_ # _length_ is abstract, https://github.com/python/types
_?ctypes.Array.raw # exists but stubtest can't see it; only available if _CT == c_char
ctypes.CDLL._FuncPtr # None at class level but initialized in __init__ to this value
_?ctypes.Structure.__getattr__ # doesn't exist, but makes things easy if we pretend it does
_?ctypes.Structure.__setattr__ # doesn't exist, but makes things easy if we pretend it does
_?ctypes.Union.__getattr__ # doesn't exist, but makes things easy if we pretend it does
_?ctypes.Union.__setattr__ # doesn't exist, but makes things easy if we pretend it does

# Iterable classes that don't define __iter__ at runtime (usually iterable via __getitem__)
# These would ideally be special-cased by type checkers; see https://github.com/python/mypy/issues/2220
Expand Down Expand Up @@ -323,6 +327,8 @@ inspect.Signature.__init__
inspect.Parameter.empty # set as private marker _empty
inspect.Signature.empty # set as private marker _empty

logging.LogRecord.__setattr__ # doesn't exist, but makes things easy if we pretend it does

# Iterable classes that don't define __iter__ at runtime (usually iterable via __getitem__)
# These would ideally be special-cased by type checkers; see https://github.com/python/mypy/issues/2220
mmap.mmap.__iter__
Expand Down Expand Up @@ -380,7 +386,9 @@ multiprocessing.synchronize.SemLock.acquire
multiprocessing.synchronize.SemLock.release

numbers.Number.__hash__ # typeshed marks this as abstract but code just sets this as None

optparse.Values.__getattr__ # Some attributes are set in __init__ using setattr
optparse.Values.__setattr__ # doesn't exist, but makes things easy if we pretend it does

os._wrap_close.read # Methods that come from __getattr__() at runtime
os._wrap_close.readable # Methods that come from __getattr__() at runtime
Expand Down
4 changes: 4 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py312.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ zoneinfo.ZoneInfo.from_file # Pos-only parameters had different "names" in diff
typing_extensions.TypeAliasType.__parameters__
typing_extensions.TypeAliasType.__value__

# Types that require `__setattr__` and `__delattr__` for typing purposes:
types.SimpleNamespace.__setattr__
types.SimpleNamespace.__delattr__


# ====================================
# Pre-existing errors from Python 3.11
Expand Down
4 changes: 4 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py313.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ zoneinfo.ZoneInfo.from_file # Pos-only parameters had different "names" in diff
typing_extensions.TypeAliasType.__parameters__
typing_extensions.TypeAliasType.__value__

# Types that require `__setattr__` and `__delattr__` for typing purposes:
types.SimpleNamespace.__setattr__
types.SimpleNamespace.__delattr__


# =======
# >= 3.11
Expand Down
8 changes: 4 additions & 4 deletions stdlib/@tests/stubtest_allowlists/py314.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ functools.partialmethod.__new__

zoneinfo.ZoneInfo.from_file # Pos-only parameters had different "names" in different Python versions

# Types that require `__setattr__` and `__delattr__` for typing purposes:
types.SimpleNamespace.__setattr__
types.SimpleNamespace.__delattr__


# =======
# >= 3.11
Expand Down Expand Up @@ -101,10 +105,6 @@ typing(_extensions)?\.IO\.writelines
# Allowlist entries that cannot or should not be fixed; >= 3.14
# =============================================================

# Internal annotations machinery
.*\.__annotate_func__
.*\.__annotations_cache__

# Undocumented private attributes
.*\.ForwardRef\.__arg__
.*\.ForwardRef\.__ast_node__
Expand Down
8 changes: 8 additions & 0 deletions stubs/WTForms/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ wtforms.fields.core.Field.__get__
# to let mypy know that arbitrary attribute access is possible
wtforms.meta.DefaultMeta.__getattr__

# Should allow setting and deleting any attribute
wtforms.Flags.__delattr__
wtforms.Flags.__setattr__
wtforms.fields.Flags.__delattr__
wtforms.fields.Flags.__setattr__
wtforms.fields.core.Flags.__delattr__
wtforms.fields.core.Flags.__setattr__

# Error: variable differs from runtime
# ======================
# _unbound_fields has some weird semantics: due to the metaclass it
Expand Down
34 changes: 17 additions & 17 deletions stubs/openpyxl/@tests/test_cases/check_base_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,27 +177,27 @@ class WithDescriptorsStrict(Strict):
assert_type(with_descriptors.match_pattern_bytes, ReadableBuffer)
assert_type(with_descriptors.match_pattern_bytes_none, Union[ReadableBuffer, None])

assert_type(with_descriptors.convertible_not_none, int) # type: ignore[assert-type] # False-positive in mypy
assert_type(with_descriptors.convertible_not_none, int)
assert_type(with_descriptors.convertible_none, Union[int, None])

assert_type(with_descriptors.minmax_float, float) # type: ignore[assert-type] # False-positive in mypy
assert_type(with_descriptors.minmax_float, float)
assert_type(with_descriptors.minmax_float_none, Union[float, None])
assert_type(with_descriptors.minmax_int, int) # type: ignore[assert-type] # False-positive in mypy
assert_type(with_descriptors.minmax_int, int)
assert_type(with_descriptors.minmax_int_none, Union[int, None])

assert_type(with_descriptors.bool_not_none, bool) # type: ignore[assert-type] # False-positive in mypy
assert_type(with_descriptors.bool_not_none, bool)
assert_type(with_descriptors.bool_none, Union[bool, None])

assert_type(with_descriptors.datetime_not_none, datetime) # type: ignore[assert-type] # False-positive in mypy
assert_type(with_descriptors.datetime_not_none, datetime)
assert_type(with_descriptors.datetime_none, Union[datetime, None])

assert_type(with_descriptors.string_not_none, str) # type: ignore[assert-type] # False-positive in mypy
assert_type(with_descriptors.string_not_none, str)
assert_type(with_descriptors.string_none, Union[str, None])

assert_type(with_descriptors.float_not_none, float) # type: ignore[assert-type] # False-positive in mypy
assert_type(with_descriptors.float_not_none, float)
assert_type(with_descriptors.float_none, Union[float, None])

assert_type(with_descriptors.integer_not_none, int) # type: ignore[assert-type] # False-positive in mypy
assert_type(with_descriptors.integer_not_none, int)
assert_type(with_descriptors.integer_none, Union[int, None])


Expand Down Expand Up @@ -289,8 +289,8 @@ class WithDescriptorsStrict(Strict):

with_descriptors.convertible_not_none = 0
with_descriptors.convertible_not_none = "0"
with_descriptors.convertible_not_none = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
with_descriptors.convertible_not_none = object() # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
with_descriptors.convertible_not_none = None # type: ignore
with_descriptors.convertible_not_none = object() # type: ignore

with_descriptors.convertible_none = 0
with_descriptors.convertible_none = "0"
Expand All @@ -301,7 +301,7 @@ class WithDescriptorsStrict(Strict):
with_descriptors.minmax_float = 0
with_descriptors.minmax_float = "0"
with_descriptors.minmax_float = 0.0
with_descriptors.minmax_float = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
with_descriptors.minmax_float = None # type: ignore
with_descriptors.minmax_float = object() # type: ignore

with_descriptors.minmax_float_none = 0
Expand All @@ -313,7 +313,7 @@ class WithDescriptorsStrict(Strict):
with_descriptors.minmax_int = 0
with_descriptors.minmax_int = "0"
with_descriptors.minmax_int = 0.0
with_descriptors.minmax_int = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
with_descriptors.minmax_int = None # type: ignore
with_descriptors.minmax_int = object() # type: ignore

with_descriptors.minmax_int_none = 0
Expand Down Expand Up @@ -354,7 +354,7 @@ class WithDescriptorsStrict(Strict):


with_descriptors.string_not_none = ""
with_descriptors.string_not_none = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
with_descriptors.string_not_none = None # type: ignore
with_descriptors.string_not_none = 0 # type: ignore

with_descriptors.string_none = ""
Expand All @@ -366,8 +366,8 @@ class WithDescriptorsStrict(Strict):
with_descriptors.float_not_none = 0.0
with_descriptors.float_not_none = "0"
with_descriptors.float_not_none = b"0"
with_descriptors.float_not_none = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
with_descriptors.float_not_none = object() # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
with_descriptors.float_not_none = None # type: ignore
with_descriptors.float_not_none = object() # type: ignore

with_descriptors.float_none = 0
with_descriptors.float_none = 0.0
Expand All @@ -381,8 +381,8 @@ class WithDescriptorsStrict(Strict):
with_descriptors.integer_not_none = 0.0
with_descriptors.integer_not_none = "0"
with_descriptors.integer_not_none = b"0"
with_descriptors.integer_not_none = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
with_descriptors.integer_not_none = object() # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
with_descriptors.integer_not_none = None # type: ignore
with_descriptors.integer_not_none = object() # type: ignore

with_descriptors.integer_none = 0
with_descriptors.integer_none = 0.0
Expand Down
44 changes: 16 additions & 28 deletions stubs/openpyxl/@tests/test_cases/check_nested_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,19 @@ class WithDescriptorsStrict(Strict):
assert_type(with_descriptors.minmax_int, int)
assert_type(with_descriptors.minmax_int_none, Union[int, None])

assert_type(with_descriptors.bool_not_none, bool) # type: ignore[assert-type] # False-positive in mypy
assert_type(with_descriptors.bool_not_none, bool)
assert_type(with_descriptors.bool_none, Union[bool, None])

assert_type(with_descriptors.emptytag_not_none, bool)
assert_type(with_descriptors.emptytag_none, Union[bool, None])

assert_type(with_descriptors.string_not_none, str) # type: ignore[assert-type] # False-positive in mypy
assert_type(with_descriptors.string_not_none, str)
assert_type(with_descriptors.string_none, Union[str, None])

assert_type(with_descriptors.float_not_none, float) # type: ignore[assert-type] # False-positive in mypy
assert_type(with_descriptors.float_not_none, float)
assert_type(with_descriptors.float_none, Union[float, None])

assert_type(with_descriptors.integer_not_none, int) # type: ignore[assert-type] # False-positive in mypy
assert_type(with_descriptors.integer_not_none, int)
assert_type(with_descriptors.integer_none, Union[int, None])


Expand Down Expand Up @@ -264,15 +264,11 @@ class WithDescriptorsStrict(Strict):

with_descriptors.convertible_not_none = 0
with_descriptors.convertible_not_none = "0"
with_descriptors.convertible_not_none = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
with_descriptors.convertible_not_none = object() # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
with_descriptors.convertible_not_none = None # type: ignore
with_descriptors.convertible_not_none = object() # type: ignore
with_descriptors.convertible_not_none = cast(_HasTagAndGet[str], _)
with_descriptors.convertible_not_none = cast( # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
_HasTagAndGet[None], _
)
with_descriptors.convertible_not_none = cast( # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
_HasTagAndGet[object], _
)
with_descriptors.convertible_not_none = cast(_HasTagAndGet[None], _) # type: ignore
with_descriptors.convertible_not_none = cast(_HasTagAndGet[object], _) # type: ignore

with_descriptors.convertible_none = 0
with_descriptors.convertible_none = "0"
Expand Down Expand Up @@ -426,15 +422,11 @@ class WithDescriptorsStrict(Strict):
with_descriptors.float_not_none = 0.0
with_descriptors.float_not_none = "0"
with_descriptors.float_not_none = b"0"
with_descriptors.float_not_none = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
with_descriptors.float_not_none = object() # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
with_descriptors.float_not_none = None # type: ignore
with_descriptors.float_not_none = object() # type: ignore
with_descriptors.float_not_none = cast(_HasTagAndGet[float], _)
with_descriptors.float_not_none = cast( # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
_HasTagAndGet[None], _
)
with_descriptors.float_not_none = cast( # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
_HasTagAndGet[object], _
)
with_descriptors.float_not_none = cast(_HasTagAndGet[None], _) # type: ignore
with_descriptors.float_not_none = cast(_HasTagAndGet[object], _) # type: ignore

with_descriptors.float_none = 0
with_descriptors.float_none = 0.0
Expand All @@ -451,15 +443,11 @@ class WithDescriptorsStrict(Strict):
with_descriptors.integer_not_none = 0.0
with_descriptors.integer_not_none = "0"
with_descriptors.integer_not_none = b"0"
with_descriptors.integer_not_none = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
with_descriptors.integer_not_none = object() # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
with_descriptors.integer_not_none = None # type: ignore
with_descriptors.integer_not_none = object() # type: ignore
with_descriptors.integer_not_none = cast(_HasTagAndGet[int], _)
with_descriptors.integer_not_none = cast( # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
_HasTagAndGet[None], _
)
with_descriptors.integer_not_none = cast( # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
_HasTagAndGet[object], _
)
with_descriptors.integer_not_none = cast(_HasTagAndGet[None], _) # type: ignore
with_descriptors.integer_not_none = cast(_HasTagAndGet[object], _) # type: ignore

with_descriptors.integer_none = 0
with_descriptors.integer_none = 0.0
Expand Down
3 changes: 0 additions & 3 deletions stubs/passlib/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ passlib.utils.handlers.HasRounds.rounds
# Errors in `__all__` at runtime:
# TODO: change after https://github.com/python/mypy/pull/14217 is released
passlib.handlers.oracle.__all__
passlib.handlers.oracle.oracle11g
passlib.handlers.oracle.oracle10g
passlib.handlers.mysql.__all__
passlib.handlers.mysql.mysq41

# Compat tools are ignored:
passlib.utils.compat.*
Expand Down
3 changes: 3 additions & 0 deletions stubs/python-xlib/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Xlib.protocol.rq.DictWrapper.__lt__
Xlib.protocol.rq.Event.__gt__
Xlib.protocol.rq.Event.__lt__

# should allow setting any attribute
Xlib.protocol.rq.GetAttrData.__setattr__

# Can be None or str once instantiated
Xlib.protocol.rq.*.structcode
# Should only ever be str once instantiated
Expand Down
28 changes: 4 additions & 24 deletions stubs/reportlab/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ reportlab.lib.utils.CIDict.get
reportlab.lib.utils.CIDict.pop
reportlab.lib.utils.CIDict.setdefault

# these have a __module__ argument which confuses stubtest
reportlab.lib.testutils.rlSkip
reportlab.lib.testutils.rlSkipIf
reportlab.lib.testutils.rlSkipUnless

# __map__ argument confuses stubtest
reportlab.lib.styles.str2alignment

# __new__ just forwards the arguments to the super class
# it doesn't actually accept arbitrary arguments
reportlab.platypus.doctemplate.PTCycle.__new__
Expand All @@ -83,6 +75,10 @@ reportlab.graphics.barcode.qrencoder.i
reportlab.lib.fonts.k
reportlab.lib.pdfencrypt.i

# should allow setting any attribute
reportlab.lib.abag.ABag.__setattr__
reportlab.lib.styles.PropertySet.__setattr__

# *-imports that cause a mess we don't want to propagate
reportlab.graphics.charts.lineplots.pi
reportlab\.graphics\.render(base|PDF|PM|PS|SVG)\.EVEN_ODD
Expand All @@ -96,23 +92,7 @@ reportlab\.graphics\.render(base|PDF|PM|PS|SVG)\.shapeChecking
reportlab\.graphics\.render(base|PDF|PM|PS|SVG)\.verbose

# messed up __all__ which contains just a string
reportlab.graphics.barcode.qr.C
reportlab.graphics.barcode.qr.Q
reportlab.graphics.barcode.qr.W
reportlab.graphics.barcode.qr.__all__
reportlab.graphics.barcode.qr.d
reportlab.graphics.barcode.qr.e
reportlab.graphics.barcode.qr.g
reportlab.graphics.barcode.qr.i
reportlab.graphics.barcode.qr.o
reportlab.graphics.barcode.qr.r
reportlab.graphics.barcode.qr.t

# spelling mistake in __all__
reportlab.graphics.barcode.ecc200datamatrix.ECC200datamatrix

# wasn't removed from __all__ by accident
reportlab.graphics.barcode.eanbc.isEanString


# Error: is not present at runtime
Expand Down
3 changes: 3 additions & 0 deletions stubs/requests/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
requests.packages.mod
requests.packages.package
requests.packages.target

# Should allow setting any attribute:
requests.structures.LookupDict.__setattr__
1 change: 0 additions & 1 deletion stubs/workalendar/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# VictoriaDayTuesdayAfterFirstMondayMay is not defined but used in __all__ runtime:
workalendar.europe.scotland.mixins.__all__
workalendar.europe.scotland.mixins.VictoriaDayTuesdayAfterFirstMondayMay

workalendar.core.CoreCalendar.name
workalendar.skyfield_astronomy
Expand Down