Skip to content

Commit 388fafe

Browse files
committed
Merge remote-tracking branch 'upstream/master' into bugfix/gh-19186-typevarlikes-defaults
2 parents dd867a4 + 1698432 commit 388fafe

File tree

7 files changed

+494
-22
lines changed

7 files changed

+494
-22
lines changed

mypy/checker.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,9 +3299,19 @@ def check_assignment(
32993299
del partial_types[var]
33003300
lvalue_type = var.type
33013301
else:
3302-
# Try to infer a partial type. No need to check the return value, as
3303-
# an error will be reported elsewhere.
3304-
self.infer_partial_type(lvalue_type.var, lvalue, rvalue_type)
3302+
# Try to infer a partial type.
3303+
if not self.infer_partial_type(var, lvalue, rvalue_type):
3304+
# If that also failed, give up and let the caller know that we
3305+
# cannot read their mind. The definition site will be reported later.
3306+
# Calling .put() directly because the newly inferred type is
3307+
# not a subtype of None - we are not looking for narrowing
3308+
fallback = self.inference_error_fallback_type(rvalue_type)
3309+
self.binder.put(lvalue, fallback)
3310+
# Same as self.set_inference_error_fallback_type but inlined
3311+
# to avoid computing fallback twice.
3312+
# We are replacing partial<None> now, so the variable type
3313+
# should remain optional.
3314+
self.set_inferred_type(var, lvalue, make_optional_type(fallback))
33053315
elif (
33063316
is_literal_none(rvalue)
33073317
and isinstance(lvalue, NameExpr)

mypyc/lib-rt/exc_ops.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "pythoncapi_compat.h"
2+
13
// Exception related primitive operations
24
//
35
// These are registered in mypyc.primitives.exc_ops.
@@ -24,7 +26,7 @@ void CPy_Reraise(void) {
2426
}
2527

2628
void CPyErr_SetObjectAndTraceback(PyObject *type, PyObject *value, PyObject *traceback) {
27-
if (!PyType_Check(type) && value == Py_None) {
29+
if (!PyType_Check(type) && Py_IsNone(value)) {
2830
// The first argument must be an exception instance
2931
value = type;
3032
type = (PyObject *)Py_TYPE(value);

mypyc/lib-rt/librt_internal.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "pythoncapi_compat.h"
2+
13
#define PY_SSIZE_T_CLEAN
24
#include <Python.h>
35
#include <stdint.h>
@@ -245,7 +247,7 @@ write_bool(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwname
245247
PyErr_SetString(PyExc_TypeError, "value must be a bool");
246248
return NULL;
247249
}
248-
if (unlikely(write_bool_internal(data, value == Py_True) == CPY_NONE_ERROR)) {
250+
if (unlikely(write_bool_internal(data, Py_IsTrue(value)) == CPY_NONE_ERROR)) {
249251
return NULL;
250252
}
251253
Py_INCREF(Py_None);

mypyc/lib-rt/misc_ops.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "pythoncapi_compat.h"
2+
13
// Misc primitive operations + C helpers
24
//
35
// These are registered in mypyc.primitives.misc_ops.
@@ -750,7 +752,7 @@ CPy_Super(PyObject *builtins, PyObject *self) {
750752

751753
static bool import_single(PyObject *mod_id, PyObject **mod_static,
752754
PyObject *globals_id, PyObject *globals_name, PyObject *globals) {
753-
if (*mod_static == Py_None) {
755+
if (Py_IsNone(*mod_static)) {
754756
CPyModule *mod = PyImport_Import(mod_id);
755757
if (mod == NULL) {
756758
return false;

0 commit comments

Comments
 (0)