Skip to content

Conversation

@AlexWaygood
Copy link
Member

@AlexWaygoodAlexWaygood commented Apr 17, 2022

Description

A followup to python/typeshed#7634 (comment)

Stubtest currently declines to error if a stub defines a public type alias that doesn't exist at runtime. But it should!

These are the new error reported from running stubtest on the typeshed stdlib, with this patch applied:

error: _threading_local.localdict is not present at runtime Stub: at line 6 Type alias for: builtins.dict Runtime: MISSING error: audioop.AdpcmState is not present at runtime Stub: at line 3 Type alias for: Tuple[builtins.int, builtins.int] Runtime: MISSING error: audioop.RatecvState is not present at runtime Stub: at line 4 Type alias for: Tuple[builtins.int, builtins.tuple[Tuple[builtins.int, builtins.int], ...]] Runtime: MISSING error: itertools.Predicate is not present at runtime Stub: at line 14 Type alias for: def (_T?) -> builtins.object Runtime: MISSING error: sqlite3.dbapi2.OptimizedUnicode is not present at runtime Stub: at line 413 Type alias for: builtins.str Runtime: MISSING 

They all look like true positives to me (or at least should be allowlisted in typeshed, rather than being ignored by stubtest altogether).

Test Plan

Two test cases added

@AlexWaygoodAlexWaygood changed the title stubtest: emit error if a stub defines a public type alias that's missing at runtimestubtest: emit error if a stub defines a public type alias that doesn't exist at runtimeApr 17, 2022
Copy link
Collaborator

@hauntsaninjahauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think it can be easier to preserve line numbers... I took the liberty of pushing changes directly to the branch, let me know what you think!

@AlexWaygood
Copy link
MemberAuthor

I think it can be easier to preserve line numbers... I took the liberty of pushing changes directly to the branch, let me know what you think!

Nice, thank you!! That's... much simpler than my method 🤦‍♂️

Just one nit about error messages -- we currently have:

Stub: at line 4 Type alias for Tuple[builtins.int, builtins.tuple[Tuple[builtins.int, builtins.int], ...]] 

I'd much prefer either this, separating the English from the code using a colon:

Stub: at line 4 Type alias for: Tuple[builtins.int, builtins.tuple[Tuple[builtins.int, builtins.int], ...]] 

or this, separating the English from the code using quotation marks:

Stub: at line 4 Type alias for "Tuple[builtins.int, builtins.tuple[Tuple[builtins.int, builtins.int], ...]]" 

What do you think?

Copy link
MemberAuthor

@AlexWaygoodAlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve my own PR

@hauntsaninjahauntsaninja merged commit 9e9de71 into python:masterApr 18, 2022
@AlexWaygoodAlexWaygood deleted the stubtest-typealiases branch April 18, 2022 20:27
@AlexWaygood
Copy link
MemberAuthor

Thanks @hauntsaninja :)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@AlexWaygood@hauntsaninja