8000 [PEP 747] Recognize TypeForm[T] type and values (#9773) by davidfstr · Pull Request #18690 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

[PEP 747] Recognize TypeForm[T] type and values (#9773) #18690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ca4c79f
[PEP 747] Recognize TypeForm[T] type and values (#9773)
davidfstr Sep 29, 2024
9dcfc23
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 16, 2025
5cb1da5
Eliminate use of Type Parameter Syntax, which only works on Python >=…
davidfstr Feb 19, 2025
3ece208
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 19, 2025
799bc48
Remove INPUTS directory
davidfstr Feb 19, 2025
6bda848
WIP: Don't declare attributes on Expression to avoid confusing mypyc
davidfstr Feb 20, 2025
9df0e6b
SQ -> WIP: Don't declare attributes on Expression to avoid confusing …
davidfstr Feb 21, 2025
a2c318b
SQ -> WIP: Don't declare attributes on Expression to avoid confusing …
davidfstr Feb 21, 2025
f398374
Recognize non-string type expressions everywhere lazily. Optimize eag…
davidfstr Feb 25, 2025
bd5911f
NOMERGE: Disable test that is already failing on master branch
davidfstr Mar 4, 2025
3801bcc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 4, 2025
c4db784
Fix mypyc errors: Replace EllipsisType with NotParsed type
davidfstr Mar 4, 2025
29fe65a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 4, 2025
4134250
mypy_primer: Enable TypeForm feature when checking effects on open so…
davidfstr Mar 5, 2025
5fb5bd8
Revert "mypy_primer: Enable TypeForm feature when checking effects on…
davidfstr Mar 8, 2025
54cd64d
NOMERGE: mypy_primer: Enable --enable-incomplete-feature=TypeForm whe…
davidfstr Mar 8, 2025
075980b
Ignore warnings like: <type_comment>:1: SyntaxWarning: invalid escape…
davidfstr Mar 14, 2025
6797cac
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 14, 2025
4162a35
Rerun CI
davidfstr Mar 17, 2025
d1aafcd
Improve warning message when string annotation used in TypeForm context
davidfstr Mar 18, 2025
1d9620d
Print error code for the MAYBE_UNRECOGNIZED_STR_TYPEFORM note
davidfstr Mar 26, 2025
76cae61
Document the [maybe-unrecognized-str-typeform] error code
davidfstr Mar 26, 2025
170a5e7
Fix doc generation warning
davidfstr Mar 26, 2025
84c06a6
Merge branch 'master' into f/typeform3
davidfstr Apr 28, 2025
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
Prev Previous commit
Next Next commit
Fix mypyc errors: Replace EllipsisType with NotParsed type
  • Loading branch information
davidfstr committed Mar 4, 2025
commit c4db784bb1895e9035368adc5a1ec0648be5bb30
3 changes: 2 additions & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
NamedTupleExpr,
NameExpr,
NewTypeExpr,
NotParsed,
OpExpr,
OverloadedFuncDef,
ParamSpecExpr,
Expand Down Expand Up @@ -6341,7 +6342,7 @@ def try_parse_as_type_expression(self, maybe_type_expr: Expression) -> Type | No
# perhaps containing a string annotation
if (
isinstance(maybe_type_expr, (StrExpr, IndexExpr, OpExpr))
and maybe_type_expr.as_type is not Ellipsis
and maybe_type_expr.as_type != NotParsed.VALUE
):
return maybe_type_expr.as_type

Expand Down
25 changes: 13 additions & 12 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
if TYPE_CHECKING:
from mypy.patterns import Pattern

EllipsisType = builtins.ellipsis
else:
EllipsisType = Any

@unique
class NotParsed(Enum):
VALUE = 'NotParsed'


class Context:
Expand Down Expand Up @@ -1728,13 +1729,13 @@ class StrExpr(Expression):
value: str # '' by default
# If this value expression can also be parsed as a valid type expression,
# represents the type denoted by the type expression.
# Ellipsis means "not parsed" and None means "is not a type expression".
as_type: EllipsisType | mypy.types.Type | None
# None means "is not a type expression".
as_type: NotParsed | mypy.types.Type | None

def __init__(self, value: str) -> None:
super().__init__()
self.value = value
self.as_type = Ellipsis
self.as_type = NotParsed.VALUE

def accept(self, visitor: ExpressionVisitor[T]) -> T:
return visitor.visit_str_expr(self)
Expand Down Expand Up @@ -2046,16 +2047,16 @@ class IndexExpr(Expression):
analyzed: TypeApplication | TypeAliasExpr | None
# If this value expression can also be parsed as a valid type expression,
# represents the type denoted by the type expression.
# Ellipsis means "not parsed" and None means "is not a type expression".
as_type: EllipsisType | mypy.types.Type | None
# None means "is not a type expression".
as_type: NotParsed | mypy.types.Type | None

def __init__(self, base: Expression, index: Expression) -> None:
super().__init__()
self.base = base
self.index = index
self.method_type = None
self.analyzed = None
self.as_type = Ellipsis
self.as_type = NotParsed.VALUE

def accept(self, visitor: ExpressionVisitor[T]) -> T:
return visitor.visit_index_expr(self)
Expand Down Expand Up @@ -2131,8 +2132,8 @@ class OpExpr(Expression):
analyzed: TypeAliasExpr | None
# If this value expression can also be parsed as a valid type expression,
# represents the type denoted by the type expression.
# Ellipsis means "not parsed" and None means "is not a type expression".
as_type: EllipsisType | mypy.types.Type | None
# None means "is not a type expression".
as_type: NotParsed | mypy.types.Type | None

def __init__(
self, op: str, left: Expression, right: Expression, analyzed: TypeAliasExpr | None = None
Expand All @@ -2145,7 +2146,7 @@ def __init__(
self.right_always = False
self.right_unreachable = False
self.analyzed = analyzed
self.as_type = Ellipsis
self.as_type = NotParsed.VALUE

def accept(self, visitor: ExpressionVisitor[T]) -> T:
return visitor.visit_op_expr(self)
Expand Down
Loading
0